How would a PCAP filter look like to capture all DHCP related traffic

dhcppcaptcpdumpwireshark

As I understand it, for IPv4 I would need to capture

  • UDP port 67 and 68,
  • ARP,
  • ICMP echo request and reply,

and for IPv6 I would need

  • UDP port 546 and 547,
  • all DHCP-related multicast addresses,
  • ICMPv6 neighbor discovery.

I want to capture DHCP related traffic with tcpdump or wireshark for later analysis.

Although I want to make the filter as specific as possible to get a small capture file, I don't want to miss out on some important packets like those used to verify that an IP address is not yet taken.

Am I missing something?

Best Answer

I settled with the following PCAP filter:

( udp and ( port 67 or port 68 ) )
or arp
or ( icmp and (icmp[icmptype] == 8 or icmp[icmptype] == 0 ) )
or ( udp and ( port 546 or port 547 ) )
or ( icmp6 and ( ip6[40] == 135 or ip6[40] == 136 ) )
or dst net ff02:0:0:0:0:1:ff00::/104
or dst host ff01::1
or dst host ff02::1
or dst host ff02::1:2
or ( icmp6 and ( ip6[40] == 128 or ip6[40] == 129 ) )

The first three lines catch DHCPv4, ARP (duplicate address detection) and PING.

The fourth line catches DHCPv6, lines five to eight catch duplicate address detection for IPv6. Line nine catches multicast for DHCPv6 agents and the last line is for PING6.

Of course this will catch many packets not related to the DHCP traffic. These have to be sorted out afterwards.

Maybe the PING and PING6 traffic isn't needed at all.

Related Topic