SPAN ports can drop packets under heavy load. The SPAN port’s ASIC may not be able to mirror Line-rate traffic, especially on 10Gbps+ links. If you see missing packets in a SPAN capture, Consider using a TAP or capturing on the endpoint.
Tcpdump uses the Berkeley Packet Filter (BPF) language to select which packets to capture. BPF Filters are compiled into a bytecode program that runs in the kernel, so filtering happens before Packets are copied to userspace. This is critical for performance — capturing all traffic on a 10Gbps link without a filter would overwhelm the capture buffer.
# By host (source or destination)
tcpdump -i eth0 host 192.168.1.100
tcpdump -i eth0 src 192.168.1.100
tcpdump -i eth0 dst 192.168.1.100
tcpdump -i eth0 net 10.0.0.0/8
tcpdump -i eth0 src port 443
tcpdump -i eth0 dst port 443
tcpdump -i eth0 host 192.168.1.100 and port 443
tcpdump -i eth0 port 80 or port 443
tcpdump -i eth0 not port 22
tcpdump -i eth0 ' (host 192.168.1.100 or host 192.168.1.200) and port 443 '
tcpdump -i eth0 ' net 10.0.0.0/8 and not host 10.0.0.1 '
tcpdump -i eth0 ' tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 ' # SYN or FIN
tcpdump -i eth0 ' tcp[tcpflags] & tcp-syn != 0 ' # SYN only
tcpdump -i eth0 ' tcp[tcpflags] & tcp-rst != 0 ' # RST only
tcpdump -i eth0 ' tcp[tcpflags] & (tcp-syn|tcp-ack) != 0 ' # SYN-ACK
BPF allows matching arbitrary bytes in the packet. The syntax is proto[offset:size].
# Match TCP payload containing "GET"
tcpdump -i eth0 ' tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) ' \
# Match specific ICMP type (type 3 = destination unreachable)
tcpdump -i eth0 ' icmp[0] == 3 '
# Match specific ICMP code (code 4 = fragmentation needed)
tcpdump -i eth0 ' icmp[0] == 3 and icmp[1] == 4 '
# Match GRE protocol (IP protocol 47)
tcpdump -i eth0 ' ip[9] == 47 '
# Match packets larger than 1000 bytes
tcpdump -i eth0 ' greater 1000 '
# Match packets smaller than 100 bytes
tcpdump -i eth0 ' less 100 '
# Save capture to pcap file
tcpdump -i eth0 -w /tmp/capture.pcap -c 10000
# Save with ring buffer (rotate files, keep last N)
tcpdump -i eth0 -w /tmp/capture.pcap -C 100 -W 5
# -C 100: max 100MB per file
tcpdump -r /tmp/capture.pcap
# Read with display filter
tcpdump -r /tmp/capture.pcap ' host 192.168.1.100 and port 443 '
# Capture with verbose output
tcpdump -i eth0 -vv -nn -X ' host 192.168.1.100 '
# -nn: no DNS resolution (faster)
# -X: hex + ASCII payload
# Increase capture buffer size (default is 2MB, may be too small for 10Gbps)
tcpdump -i eth0 -B 524288000 # 500MB buffer
# Disable promiscuous mode (only capture traffic to/from this host)
# Limit snapshot length (default 262144 bytes)
tcpdump -i eth0 -s 96 # capture first 96 bytes (headers only, no payload)
# Use zero-copy capture (if supported)
Wireshark display filters are applied after capture and use a different (and more powerful) syntax Than BPF capture filters.
tcp.analysis.retransmission
tcp.analysis.duplicate_ack
dns.qry.name contains "example.com"
dns.qry.type == 1 # A record
dns.qry.type == 28 # AAAA record
dns.flags.response == 0 # query
dns.flags.response == 1 # response
tls.handshake.type == 1 # ClientHello
tls.handshake.type == 2 # ServerHello
tls.handshake.extensions.server_name contains "example.com"
http.request.method == "GET"
http.response.code == 200
http.host contains "example.com"
http.request.uri contains "/api/"
ip.addr == 192.168.1.100 and tcp.port == 443 and tls.handshake.type == 1
!(arp or dns) # exclude ARP and DNS
Customize the packet list columns to show the information you need most:
No. | Time | Source | Destination | Protocol | Length | Info
Add custom columns: Frame Time (relative to first packet), Delta Time (inter-packet interval), TCP Stream, TCP Segment Length, Cumulative Bytes.
Wireshark ships with default coloring rules, but you can add custom rules:
# Highlight all TCP retransmissions in bright red
tcp.analysis.retransmission
# Highlight all RST packets
# Highlight all DNS queries
# Highlight all HTTP errors (4xx, 5xx)
http.response.code >= 400
Right-click a TCP packet and select “Follow TCP Stream” to see the full conversation. This Reassembles all TCP segments in order, removing headers and showing the application data.
Wireshark’s Expert Info (Analyze menu) automatically annotates packets with potential issues:
Notes: Informational (e.g., “TCP window update”)Warnings: Potential problems (e.g., “Previous segment not captured”, “Duplicate ACK”)Errors: Definite problems (e.g., “Retransmission”, “Out of order”, “RST sent”)Wireshark allows per-protocol configuration:
TLS: Decrypt using a pre-master secret (SSLKEYLOGFILE), RSA private key, or session keysHTTP: Set TCP port for HTTP (if using non-standard ports)DNS: Enable/disable DNS query/response matching# Set SSLKEYLOGFILE for Chrome/Firefox
export SSLKEYLOGFILE = / tmp / sslkeys . log
# In Wireshark: Edit > Preferences > Protocols > TLS
# (Pre)-Master-Secret log filename: /tmp/sslkeys.log
Tshark is the command-line version of Wireshark. It uses the same capture and display filter syntax But outputs to the terminal.
# Capture with display filter
tshark -i eth0 -f ' port 443 ' -Y ' tls.handshake.type == 1 '
tshark -i eth0 -w /tmp/capture.pcap -c 10000
# Extract HTTP host headers
tshark -r /tmp/capture.pcap -Y http -T fields \
-e frame.number -e ip.src -e ip.dst -e http.host -e http.request.uri
# Extract DNS query names
tshark -r /tmp/capture.pcap -Y ' dns.flags.response == 0 ' -T fields \
-e frame.number -e dns.qry.name -e dns.qry.type
tshark -r /tmp/capture.pcap -Y ' tls.handshake.type == 1 ' -T fields \
-e frame.number -e ip.src -e ip.dst \
-e tls.handshake.extensions_server_name
# Extract TCP retransmissions
tshark -r /tmp/capture.pcap -Y ' tcp.analysis.retransmission ' -T fields \
-e frame.number -e ip.src -e ip.dst -e tcp.srcport -e tcp.dstport
tshark -r /tmp/capture.pcap -q -z io,phs
tshark -r /tmp/capture.pcap -q -z conv,ip
# Conversations (by TCP port)
tshark -r /tmp/capture.pcap -q -z conv,tcp
tshark -r /tmp/capture.pcap -q -z dns,tree
tshark -r /tmp/capture.pcap -q -z http,tree
# IO statistics (bytes per second)
tshark -r /tmp/capture.pcap -q -z io,stat,0
# Output as JSON for parsing with jq
tshark -r /tmp/capture.pcap -Y ' http.response ' -T json \
| jq ' .[] | select(._source.layers.http) | {time: ._source.layers.frame."frame.time_relative", code: ._source.layers.http."http.response.code"} '
NetFlow is a network protocol developed by Cisco that exports aggregated flow records from routers And switches. A “flow” is a unidirectional sequence of packets sharing the same 5-tuple (source IP, Destination IP, source port, destination port, protocol).
What NetFlow records:
Field Description src_addr Source IP address dst_addr Destination IP address src_port Source port dst_port Destination port protocol IP protocol (TCP, UDP, ICMP, etc.) packets Number of packets in the flow bytes Total bytes in the flow start_time Time of first packet end_time Time of last packet tcp_flags OR of TCP flags seen in all packets tos Type of Service / DSCP value as_src Source AS number (if BGP is enabled) as_dst Destination AS number input_interface SNMP index of ingress interface output_interface SNMP index of egress interface nexthop Next-hop IP address
NetFlow versions:
Version Description v5 Original format, fixed fields v9 Template-based, extensible (RFC 3954) IPFIX IETF standard based on NetFlow v9 (RFC 7011)
SFlow (Sampled Flow) uses statistical sampling rather than tracking every packet. The router samples 1 in N packets (configurable, 1:1000) and exports the sample to a collector.
Advantages over NetFlow: lower CPU overhead on the router, works at line rate, can export interface Counters and packet headers.
Disadvantages: sampling means some flows are missed, less accurate for low-volume traffic.
# Cisco IOS NetFlow configuration
interface GigabitEthernet0/1
export-protocol netflow-v9
record netflow ipv4 original-input
interface GigabitEthernet0/1
ip flow monitor MONITOR-1 input
# nfdump (NetFlow collector and analyzer)
nfdump -r /data/netflow/nfcapd.202401150000 -n 20 # top 20 flows by bytes
nfdump -r /data/netflow/nfcapd.202401150000 -s srcip/bytes # top talkers (source)
nfdump -r /data/netflow/nfcapd.202401150000 -s dstport/bytes # top ports
nfdump -r /data/netflow/nfcapd.202401150000 ' dst port 443 ' # filter flows
# SiLK (Suite for IP network analysis)
rwfilter --proto=6 --dport=443 --pass=stdout \
| rwcount --bin-size=300 # count connections per 5-minute bin
rwfilter --proto=17 --pass=stdout \
| rwstats --fields=sport,dport --top=20 # top UDP port pairs
Real-time bandwidth usage per connection:
iftop -i eth0 -n # -n: no DNS resolution
Simple real-time bandwidth monitor per interface:
Bandwidth monitor with graphical output:
Long-term bandwidth monitoring (stores historical data):
Bandwidth monitoring per process:
Linux’s netfilter connection tracking system maintains a table of all active connections. This is The backbone of NAT, stateful firewalls, and conntrack-based tools.
# View all tracked connections
# View connections for a specific IP
conntrack -L -s 192.168.1.100
# View connection tracking statistics
# Maximum tracked connections
cat /proc/sys/net/nf_conntrack_max
# Current tracked connections
cat /proc/sys/net/netfilter/nf_conntrack_count
# Increase connection tracking table size
sysctl -w net.netfilter.nf_conntrack_max= 262144
# Reduce connection tracking timeout
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_established= 600
cat /proc/sys/net/netfilter/nf_conntrack_tcp_timeout_established