Capturing Traffic with OPNsense to See What Is Really Happening
What a capture is and when to use it, responsible use, comparing LAN and WAN captures, the OPNsense Packet Capture function, unanswered SYNs, dropping sessions, silent DNS, NAT that does not translate, one-way VoIP audio, tcpdump, port mirroring and common mistakes.
“Is the firewall blocking something?”, “Is the server answering or not?”, “The VoIP call connects, but nobody can hear anything.” These are questions the logs do not always settle: a log entry says that a rule fired, not what happened next. In these cases it pays to look at the real traffic, packet by packet. OPNsense has a built-in capture function that lets you do this in a few minutes, without installing anything. Let us see how to use it well, where to capture and how to read the most common cases.
What a packet capture is
A packet capture records in a file a copy of the packets crossing a network interface, with the exact moment each one went through. The most widespread format is pcap, born with tcpdump's libpcap library; the newer pcapng format adds comments and several interfaces in the same file. Both open in Wireshark, which breaks every packet down into its layers: Ethernet, IP, TCP or UDP and the application protocol.
A capture is useful when you need to answer a precise question: does the packet arrive? does it leave? does a reply come back? what does the reply contain? It does not replace the firewall log or basic commands such as ping and traceroute, described in the article on ping and traceroute: it complements them when they are not enough.
One point needs to be clear from the start. A capture is a diagnostic tool, not a surveillance tool. Use it only on your own network, or on a network you are authorised to manage, with the permission of whoever is responsible for it. Packets contain personal data: addresses, the names of visited sites in DNS queries and, in unencrypted traffic, the content as well. For this reason you capture the bare minimum, with tight filters and for a short time, and you delete the files as soon as the problem is solved. In Europe the GDPR asks for exactly this: data that is adequate, relevant and limited to the purpose. In a business, the rules on monitoring employees also apply, so it is wise to agree the procedure with the data controller or the person responsible for data protection.
Where to capture: LAN, WAN and comparison
The value of a capture depends on where you take it. The firewall is a privileged observation point, because it sees the traffic on both sides. The most useful technique is to capture on the LAN and the WAN at the same time and compare: a packet that appears on the LAN but not on the WAN stopped inside the firewall; one that leaves the WAN without getting a reply was lost beyond the firewall.
A technical detail makes the comparison possible. On FreeBSD, the system OPNsense is based on, the capture reads incoming packets on the interface before the pf filter decides. A SYN blocked by a rule therefore appears in the LAN capture, even though it will never leave through the WAN. On the WAN, by contrast, outgoing packets appear already translated by NAT, with the firewall's public address.
A capture on the firewall has one limit: it only sees the traffic that crosses it. Two PCs on the same network talking to each other go through the switch and never touch OPNsense. In that case you need another observation point, as we will see with port mirroring.
The OPNsense capture function
The page is under Interfaces › Diagnostics › Packet Capture; menus may vary with the version. The main settings are these:
- Interface: LAN, WAN, a VLAN or a VPN interface. In recent versions you can select several interfaces in the same capture, which is handy for comparing LAN and WAN.
- Filters: host address, port, protocol (TCP, UDP, ICMP, ARP and others) and address family, IPv4 or IPv6. The tighter the filter, the smaller and more readable the file.
- Number of packets: the capture stops by itself after the given number. A few hundred packets are almost always enough.
- Packet length: you can save only the beginning of each packet, that is the headers. It is the simplest way to avoid recording the content.
- Promiscuous mode: makes the card read frames addressed to other MAC addresses too. On the firewall it is rarely needed.
- Level of detail: decides how much information the page shows when you view the capture in the browser, from one line per packet up to the full content.
Once the capture is running, reproduce the problem: open the page that does not work, place the call, try the connection. Then stop the capture and choose between two routes. For a quick check it is enough to view it on the page. For a full analysis, download the file in pcap format and open it with Wireshark. When the analysis is over, remove the capture from the firewall.
The first example: the SYN that never leaves
A PC on the LAN, 192.168.1.10, cannot open a web service on 198.51.100.80, port 443. The browser waits and then reports a timeout. We start a capture with the filter host 198.51.100.80, protocol TCP and port 443, selecting both the LAN and the WAN. The LAN capture shows this (tcpdump format, shortened):
10:15:02.341256 IP 192.168.1.10.51514 > 198.51.100.80.443: Flags [S], seq 2401152311, win 64240, length 0
10:15:03.352870 IP 192.168.1.10.51514 > 198.51.100.80.443: Flags [S], seq 2401152311, win 64240, length 0
10:15:05.366102 IP 192.168.1.10.51514 > 198.51.100.80.443: Flags [S], seq 2401152311, win 64240, length 0Flags [S] marks the SYN, the first packet of the TCP handshake (RFC 9293). The same SYN, with the same sequence number, is repeated after about 1 and then 2 seconds: these are the client's retransmissions, because it received no reply. The intervals double at each attempt; the exact values depend on the operating system. The WAN capture, over the same interval, is empty.
The conclusion is clear-cut: the packet enters the firewall and does not leave it. The possible causes are few: a Block rule on the LAN, a Pass rule that does not match, for example because of a wrong alias, or a routing problem on the firewall itself. The log under Firewall › Log Files › Live View, filtered by the PC's address, usually points to the responsible rule, if that rule logs packets. How rules work is explained in the article on how a firewall rule works.
With the rule fixed, we repeat the capture. Now the SYN appears on both interfaces, and on the WAN the source address is the public one, translated by NAT:
LAN 10:21:40.118342 IP 192.168.1.10.51530 > 198.51.100.80.443: Flags [S], seq 917735120, length 0
WAN 10:21:40.118501 IP 203.0.113.25.30117 > 198.51.100.80.443: Flags [S], seq 917735120, length 0
WAN 10:21:40.139877 IP 198.51.100.80.443 > 203.0.113.25.30117: Flags [S.], seq 3150244101, ack 917735121, length 0
LAN 10:21:40.140010 IP 198.51.100.80.443 > 192.168.1.10.51530: Flags [S.], seq 3150244101, ack 917735121, length 0
LAN 10:21:40.140410 IP 192.168.1.10.51530 > 198.51.100.80.443: Flags [.], ack 3150244102, length 0Flags [S.] is the server's SYN-ACK, Flags [.] the ACK that completes the handshake. The LAN and WAN labels at the start of each line have been added for clarity. The time difference between the SYN and the SYN-ACK on the WAN, about 21 milliseconds, is the round-trip time to the server. The fact that the SYN-ACK comes back in without a rule on the WAN is down to the state table, described in the article on the stateful firewall.
Reading the most common cases
With a little practice, a few lines of capture are enough to see where the problem lies. Here are the cases you meet most often.
SYN with no reply, on the WAN too. The SYN leaves through the WAN and nothing comes back. The firewall has done its job: the packet is lost further along. Either the service is unreachable, because the server is off or a filter along the path silently drops the packets, or the address is wrong. If instead a packet with Flags [R.] comes back, that is a reset, the server is on but no service is listening on that port. An ICMP destination unreachable message means that a router or firewall along the path rejects the packet and says so.
SYN-ACK present, but the session drops. The handshake completes, so the path and the rules work. The problem comes later. If the server closes with a reset, the cause lies in the application: certificate, authentication, connection limit. If instead the client keeps retransmitting the same large packet, for example the first TLS message of 1,400 bytes or more, while small packets get through, the suspect is the maximum packet size (MTU). This is typical of PPPoE connections, with an MTU of 1,492 bytes, when the ICMP messages reporting the problem are blocked. In OPNsense you can limit the size of TCP segments with the MSS field in the WAN interface settings.
DNS that does not answer. With a filter on UDP port 53 you watch the query leave and check whether the answer comes back:
10:30:11.502114 IP 192.168.1.10.53122 > 192.168.1.1.53: 41871+ A? www.example.com. (33)
10:30:11.502890 IP 203.0.113.25.24871 > 198.51.100.53.53: 5520+ A? www.example.com. (33)
10:30:16.503551 IP 192.168.1.10.53122 > 192.168.1.1.53: 41871+ A? www.example.com. (33)The first line is the PC's query to the firewall's resolver, on the LAN; the second is the firewall's query to the external DNS server, on the WAN. After five seconds the PC repeats the query: no answer has arrived. The local resolver works and forwards; the problem is upstream, in the external DNS server or on the path to it. If the second line were missing, the problem would be in the firewall's resolver. A correct answer would look like 41871 1/0/0 A 198.51.100.80. How queries and answers work is explained in the article on DNS.
NAT that does not translate. An internal server, 192.168.1.20, must be reachable from the Internet on port 443 through port forwarding. From outside it does not answer. Capture on the WAN with the filter port 443 and, at the same time, on the LAN with the filter host 192.168.1.20.
The second case deserves attention. If the internal server uses another router as its gateway, its reply does not return to the firewall: the LAN capture shows the SYN going out to the server, but the SYN-ACK never comes back in. The correct port forwarding configuration is explained in the article on NAT and port forwarding.
VoIP: the call connects but there is no audio. SIP signalling, usually on UDP port 5060, works, because the phone rings. The voice, however, travels in RTP streams, on variable UDP ports. Capture on the WAN with a host filter for the PBX or the phone and protocol UDP. If RTP packets go out but none come in, or the other way round, the audio is one-way: often a NAT problem with the addresses written inside the SIP messages. Wireshark, through the Telephony › VoIP Calls menu, rebuilds the calls and the two audio streams.
tcpdump from the console
The web page uses the same engine as tcpdump, which you can run directly from the firewall's shell, at the console or over SSH. It is useful when the web interface cannot be reached or when you want to watch the traffic in real time. Interface names are the physical ones, such as igb0 or vtnet1, shown under Interfaces › Assignments. Some examples:
# 20 TCP packets between the LAN and the server, without resolving names (-n)
tcpdump -ni igb1 -c 20 host 198.51.100.80 and tcp port 443
# only SYNs and resets on the WAN
tcpdump -ni igb0 'tcp[tcpflags] & (tcp-syn|tcp-rst) != 0'
# DNS from the PC, saving only the headers (-s 128) to a file for Wireshark
tcpdump -ni igb1 -s 128 -c 200 -w /tmp/dns.pcap host 192.168.1.10 and udp port 53Filters follow the pcap-filter syntax: host, net, port, tcp, udp, icmp, combined with and, or and not. The -c option limits the number of packets, -w writes the file instead of showing it. Copy the file to the PC with an SCP client and delete it from the firewall straight away with rm /tmp/dns.pcap.
In Wireshark it helps to tell two kinds of filter apart. The capture filter, the tcpdump one, decides what gets recorded. The display filter sifts a file that has already been recorded. Some useful display filters: tcp.flags.syn == 1 && tcp.flags.ack == 0 for SYNs only, tcp.analysis.retransmission for retransmissions, dns for queries, ip.addr == 192.168.1.10 for one host.
An alternative: port mirroring on the switch
When the traffic you want to observe does not cross the firewall, for example between a PC and a server on the same network or between a VoIP phone and the internal PBX, use port mirroring, also called SPAN. A managed switch copies the traffic of one or more ports to a monitoring port, where you connect a PC running Wireshark. The original traffic is not touched.
Two warnings. The mirror port must receive the sum of the copied traffic: a 1 Gbit/s port in full duplex can generate up to 2 Gbit/s, and if the monitoring port runs at 1 Gbit/s some packets are lost in the copy, not on the network. And mirroring must be switched off at the end of the analysis: left on, it is a permanent copy of someone else's traffic.
Common mistakes
- Capturing without filters. On a 1 Gbit/s WAN an unfiltered capture collects thousands of packets per second: it fills the firewall's memory or disk and produces an unreadable file. Always start from host, port and protocol, with a maximum number of packets.
- Capturing on the wrong interface. A VLAN's traffic goes through the VLAN interface, a VPN's through the tunnel interface. An empty capture on the wrong interface suggests a lost packet, when the packet is simply somewhere else.
- Forgetting the files. A capture left on the firewall, in a download folder or in an attachment contains addresses, names and sometimes content. Delete it at the end of the analysis; if it has to be shared, for example with a supplier, first trim it down to the packets that are needed.
- Looking for content in encrypted traffic. HTTPS, encrypted DNS and VPNs show addresses, ports, timing and sizes, not the content. For network diagnostics this is almost always enough: the handshake, resets and retransmissions remain visible.
- Mistaking a capture for a security system. A capture is a snapshot taken to answer a question. To recognise attacks continuously you need dedicated tools, such as those described in the article on IDS and IPS.
Conclusions
When the logs are not enough, a packet capture shows what is really happening and where. In practice:
- define the question first: which host, which port, which symptom;
- capture on the LAN and the WAN together, with tight filters and a maximum number of packets;
- reproduce the problem during the capture and compare the two interfaces: where the packet disappears, that is where the fault is;
- read the TCP flags: SYN with no reply, resets, retransmissions;
- for internal traffic, use the switch's port mirroring;
- capture only on your own network, with authorisation, and delete the files at the end of the analysis.
If the problem is more general, in other words “the Internet is not working”, it is better to start from the step-by-step diagnosis and reach for a capture only when needed. To go deeper into the OPNsense firewall, its rules and NAT, the books and the course listed below are a useful next step.
The video
Further reading
- Book: OPNsense® in Practice — Volume 1: The Foundations of a Professional Journey (English edition)
- Book: LOCAL AREA NETWORKS (LAN) — Volume 5: LAN Security and Integration (English edition)
- Book: LOCAL AREA NETWORKS (LAN) — Volume 4: Routing, NAT, and Internet Access (English edition)
- Video course: Capire i Firewall con OPNsense (video course in Italian)
- Related article: How a Firewall Rule Works
- Related article: NAT and Port Forwarding: How a Private Network Talks to the Internet
- Related article: DNS: How a Name Becomes an IP Address
- Related article: IDS and IPS: Detecting and Blocking Suspicious Traffic with OPNsense
- Related article: Ping and Traceroute: How to Really Read the Results
- Related article: Stateful Firewalls: Why Replies Get Through Without a Rule
- Related article: The Internet Isn't Working: Step-by-Step Troubleshooting, from Cable to DNS
- Related article: Managed or Unmanaged Switch: Which One to Choose
- Specialization: Firewalls & Network Security
Technical sources
- Documentazione ufficiale di OPNsense — Interfaces › Diagnostics › Packet Capture e Firewall › Log Files — Choice of interfaces, filters by address, port, protocol and address family, number and length of packets, promiscuous mode, level of detail, viewing and downloading the capture; the firewall's live log. Menus and options depend on the version.
- Pagine di manuale tcpdump(1) e pcap-filter(7) — The Tcpdump Group — The -n, -i, -c, -s and -w options, the format of the lines and of the TCP flags ([S], [S.], [.], [R.]), capture filter syntax with host, net, port, protocols and the and, or, not operators.
- Wireshark User's Guide — Capture Filters, Display Filters, Telephony › VoIP Calls — The pcap and pcapng formats, the difference between capture filters and display filters (tcp.flags.syn, tcp.analysis.retransmission, dns, ip.addr), reconstruction of VoIP calls and RTP streams.
- RFC 9293 e RFC 6298 — Transmission Control Protocol (TCP); Computing TCP's Retransmission Timer — The SYN, SYN-ACK, ACK three-way handshake, reset with RST; retransmission of unanswered segments with an initial one-second timer that doubles at each attempt. Actual timings depend on the operating system.
- RFC 1035 e RFC 3261 — Domain Names; SIP: Session Initiation Protocol — DNS queries and answers over UDP port 53 with a message identifier; SIP signalling on port 5060 and description of media streams with the addresses written inside the messages.
- Regolamento (UE) 2016/679 (GDPR), articolo 5 — The principles of purpose limitation, data minimisation and storage limitation, applied to captures that contain addresses, names and content.
- RFC 1918 e RFC 5737 — Addresses used in the examples: private network 192.168.1.0/24, documentation addresses 198.51.100.0/24 and 203.0.113.0/24.
Standards and official documentation available from the respective organisations.