1 In order to capture packets (with Wireshark/TShark, tcpdump, or any
2 other libpcap-based packet capture program) on a Linux system, the
3 "packet" protocol must be supported by your kernel. If it is not, you
4 may get error messages such as
6 modprobe: can't locate module net-pf-17
8 in "/var/adm/messages", or may get messages such as
10 socket: Address family not supported by protocol
12 from applications using libpcap.
14 Most recent Linux distributions will have this configured in by default.
15 If it is not configured in with the default kernel, and if it is not a
16 module loaded by default, you must configure the kernel with the
17 CONFIG_PACKET option for this protocol; the following note is from the
18 Linux "Configure.help" file for the 2.0[.x] kernel:
22 The Packet protocol is used by applications which communicate
23 directly with network devices without an intermediate network
24 protocol implemented in the kernel, e.g. tcpdump. If you want them
27 This driver is also available as a module called af_packet.o ( =
28 code which can be inserted in and removed from the running kernel
29 whenever you want). If you want to compile it as a module, say M
30 here and read Documentation/modules.txt; if you use modprobe or
31 kmod, you may also want to add "alias net-pf-17 af_packet" to
34 and the note for the 2.2[.x] kernel says:
38 The Packet protocol is used by applications which communicate
39 directly with network devices without an intermediate network
40 protocol implemented in the kernel, e.g. tcpdump. If you want them
41 to work, choose Y. This driver is also available as a module called
42 af_packet.o ( = code which can be inserted in and removed from the
43 running kernel whenever you want). If you want to compile it as a
44 module, say M here and read Documentation/modules.txt. You will
45 need to add 'alias net-pf-17 af_packet' to your /etc/conf.modules
46 file for the module version to function automatically. If unsure,
49 In addition, there is an option that, in 2.2 and later kernels, will
50 allow packet capture filters specified to programs such as tcpdump to be
51 executed in the kernel, so that packets that don't pass the filter won't
52 be copied from the kernel to the program, rather than having all packets
53 copied to the program and libpcap doing the filtering in user mode.
55 Copying packets from the kernel to the program consumes a significant
56 amount of CPU, so filtering in the kernel can reduce the overhead of
57 capturing packets if a filter has been specified that discards a
58 significant number of packets. (If no filter is specified, it makes no
59 difference whether the filtering isn't performed in the kernel or isn't
60 performed in user mode. :-))
62 Most recent Linux distributions will have this configured in by default.
63 If it is not configured in with the default kernel, you must configure
64 the kernel with the CONFIG_FILTER option; the "Configure.help" file
69 The Linux Socket Filter is derived from the Berkeley Packet Filter.
70 If you say Y here, user-space programs can attach a filter to any
71 socket and thereby tell the kernel that it should allow or disallow
72 certain types of data to get through the socket. Linux Socket
73 Filtering works on all socket types except TCP for now. See the text
74 file linux/Documentation/networking/filter.txt for more information.
77 An additional problem, on Linux, with older versions of libpcap, is that
78 capture filters do not work when snooping loopback devices; if you're
79 capturing on a Linux loopback device, do not use a capture filter, as it
80 will probably reject most if not all packets, including the packets it's
81 intended to accept - instead, capture all packets and use a display
82 filter to select the packets you want to see. Most recent Linux
83 distribution releases will not have this problem.
85 In addition, older versions of libpcap will, on Linux systems with a
86 2.0[.x] kernel, or if built for systems with a 2.0[.x] kernel, not turn
87 promiscuous mode off on a network device until the program using
88 promiscuous mode exits, so if you start a capture with Wireshark on some
89 Linux distributions, the network interface will be put in promiscuous
90 mode and will remain in promiscuous mode until Wireshark exits. There
91 might be additional libpcap bugs that cause it not to be turned off even
92 when Wireshark exits; if your network is busy, this could cause the Linux
93 networking stack to do a lot more work discarding packets not intended
94 for the machine, so you may want to check, after running Wireshark,
95 whether any network interfaces are in promiscuous mode (the output of
96 "ifconfig -a" will say something such as
98 eth0 Link encap:Ethernet HWaddr 00:00:66:66:66:66
99 inet addr:66.66.66.66 Bcast:66.66.66.255 Mask:255.255.255.0
100 UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
101 RX packets:6493 errors:0 dropped:0 overruns:0 frame:0
102 TX packets:3380 errors:0 dropped:0 overruns:0 carrier:0
103 collisions:0 txqueuelen:100
104 Interrupt:18 Base address:0xfc80
106 with "PROMISC" indicating that the interface is in promiscuous mode),
107 and, if any interfaces are in promiscuous mode and no capture is being
108 done on that interface, turn promiscuous mode off by hand with
110 ifconfig <ifname> -promisc
112 where "<ifname>" is the name of the interface.
114 Newer versions of libpcap shouldn't have this problem, even on 2.0[.x]
115 kernels; no version of libpcap should have that problem on systems with
116 2.2 or later kernels.