Configuring host and network filters

When talking about host and network filters, we refer to Layer 3 filters that are IP address-based filters. In this recipe we will refer to these filters and what we can do with them.

Getting ready

The basic Layer 3 filters are:

  • ip or ip6: To capture IP or IPv6 packets.
  • host <host>: To get host name or address.
  • dst host <host>: To get destination host name or address.
  • src host <host>: To get source host name or address.

    Tip

    Host can be an IP address or a host name related with this number. You can type, for example, a filter host www.packtpub.com that will show you all packets to/from the IP address related to the Packt website.

  • gateway <Host name or address>: It captures traffic to or from the hardware address but not to the IP address of the host. This filter captures traffic going through the specified router. This filter requires a host name that is used and can be found by the local system's name resolution process (for example, DNS).
  • net <net>: All packets to or from the specified IPv4/IPv6 network.
  • dst net <net>: All packets to the specified IPv4/IPv6 destination network.
  • src net <net>: All packets to the specified IPv4/IPv6 destination network.
  • net <net> mask <netmask>: All packets to/from the specific network and mask. This syntax is not valid for the IPv6 network.
  • dst net <net> mask <netmask>: All packets to/from the specific network and mask. This syntax is not valid for the IPv6 network.
  • src net <net> mask <netmask>: All packets to/from the specific network and mask. This syntax is not valid for the IPv6 network.
  • net <net>/<len>: All packets to/from the <net> network with <len> length in bits.
  • dst net <net>/<len>: All packets to/from the <net> network with <len> length in bits.
  • dst net <net>/<len>: All packets to/from the <net> network with <len> length in bits.
  • broadcast: All broadcast packets.
  • multicast: All multicast packets.
  • ip proto <protocol code>: It captures packets while the IP protocol field equals to the <protocol> identifier. There can be various protocols, such as, TCP (Code 6), UDP (Code 17), ICMP (Code 1), and so on.
  • ip6 proto <protocol>: It captures IPv6 packets with protocol as indicated in the type field. Note that this primitive does not follow the IPv6 extension headers chain.

    Tip

    In IPv6 header, there is a field in the header that can point to an optional extension header, which points to the next extension header, and so on. In the current version, Wireshark capture filter does not follow this structure.

  • icmp[icmptype]==<identifier>: It captures ICMP packets, while the identifier is ICMP codes, such as icmp-echo and icmp-request.

How to do it...

Follow the instructions mentioned in the Configure capture filters recipe, and configure filters as follows:

  1. For capturing packets to/from host 10.10.10.1, configure host 10.10.10.1.
  2. For capturing packets to/from host at www.cnn.com, configure host www.cnn.com.
  3. For capturing packets to host 10.10.10.1, configure dst host 10.10.10.1.
  4. For capturing packets from host 10.10.10.1, configure src host 10.10.10.1.
  5. For capturing packets to/from network 192.168.1.0/24, configure net 192.168.1 or net 192.168.1.0 mask 255.255.255.0 or net 192.168.1.0/24.
  6. For capturing all data without broadcasts or without multicasts, configure not broadcast or not multicast.
  7. For capturing packets to/from the IPv6 network 2001::/16, configure net 2001::/16.
  8. For capturing packets to IPv6 host 2001::1, configure host 2001::1.
  9. For capturing only ICMP packets, configure ip proto 1.
  10. For filtering only ICMP Echo's pings, you can use ICMP messages or message codes. configure icmp[icmptype]==icmp-echo or icmp[icmptype]==8.

How it works…

For host filtering, when you type a host name, Wireshark will translate the name to an IP address, and capture packets that refer to this address. For example, if you configure a filter host www.cnn.com, it will be translated by a name resolution service (mostly DNS) to an IP address, and will show you all packets going to and from this address. Note that in this case, if CNN website will forward you to other websites on other addresses, only packets to the first address will be captured.

There's more...

Some more useful filters:

  • ip multicast: IP multicast packets
  • ip broadcast: IP broadcast packets
  • ip[2:2] == <number>: IP packet size
  • ip[8] == <number>: TTL (Time To Live) value
  • ip[9] == <number>: Protocol value
  • (ip[12:4] = ip[16:4]): IP source equal to IP destination address
  • ip[2:2]==<number>: Total length or IP packet
  • ip[9] == <number>: Protocol identifier

These filters are further explained in the Configuring byte offset and payload matching filters recipe at the end of this chapter. The principle, as illustrated in the following diagram, is that the first number in the brackets defines how many bytes are from the beginning of the protocol header, and the second number indicates how many bytes to watch.

There's more...

See also

For more filters, refer to the tcpdump manual pages at http://www.tcpdump.org/tcpdump_man.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.89.238