man: netsniff-ng: finish usage examples and add filter examples
[netsniff-ng.git] / man / netsniff-ng.8
blob0b4eeadc042b828f46a2022519a2ee182762cb5b
1 .\" netsniff-ng - the packet sniffing beast
2 .\" Copyright 2013 Daniel Borkmann.
3 .\" Subject to the GPL, version 2.
5 .TH NETSNIFF-NG 8 "03 March 2013" "Linux" "netsniff-ng toolkit"
6 .SH NAME
7 netsniff-ng \- the packet sniffing beast
9 .SH SYNOPSIS
11 \fB netsniff-ng\fR { [\fIoptions\fR] [\fIfilter-expression\fR] }
13 .SH DESCRIPTION
15 Blubber.
17 .SH OPTIONS
19 .SS -d <netdev>, --dev <netdev>
20 Networking device to fetch statistics from, e.g. eth0, wlan0.
22 .SS -v, --version
23 Show versioning information.
25 .SS -h, --help
26 Show user help.
28 .SH USAGE EXAMPLE
30 .SS netsniff-ng
31 The most simple command is to just run ``netsniff-ng''. This will start
32 listening on all available networking devices in promiscuous mode and dump
33 the packet dissector output to the terminal. No files will be recorded.
35 .SS  netsniff-ng --in eth0 --out dump.pcap -s -T 0xa1e2cb12 -b 0 tcp or udp
36 Capture TCP or UDP traffic from the networking device eth0 into the pcap file
37 named dump.pcap, which has netsniff-ng specific pcap extensions (see
38 ``netsniff-ng -D'' for capabilities). Also, do not print the content to the
39 terminal and pin the process and NIC IRQ affinity to CPU 0. The pcap write
40 method is scatter-gather I/O.
42 .SS  netsniff-ng --in wlan0 --rfraw --out dump.pcap --silent --bind-cpu 0
43 Put the wlan0 device into monitoring mode and capture all raw 802.11 frames
44 into the file dump.pcap. Do not dissect and print the content to the terminal
45 and pin the process and NIC IRQ affinity to CPU 0. The pcap write method is
46 scatter-gather I/O.
48 .SS  netsniff-ng --in dump.pcap --mmap --out eth0 -k1000 --silent --bind-cpu 0
49 Replay the pcap file dump.pcap which is read through mmap(2) I/O and send
50 the packets out via the eth0 networking device. Do not dissect and print the
51 content to the terminal and pin the process and NIC IRQ affinity to CPU 0.
52 Also trigger the kernel every 1000us to traverse the TX_RING instead of every
53 10us. Note that the pcap magic type is detected automatically from the pcap
54 file header.
56 .SS  netsniff-ng --in eth0 --out eth1 --silent --bind-cpu 0 --type host -r
57 Redirect network traffic from the networking device eth0 to eth1 for traffic
58 that is destined to our host, thus ignore broadcast, multicast and promiscuous
59 traffic. Randomize the order of packets for the outgoing device and do not
60 print any packet contents to the terminal. Also, pin the process and NIC IRQ
61 affinity to CPU 0.
63 .SS  netsniff-ng --in team0 --out /opt/probe/ -s -m -J --interval 100MiB -b 0
64 Capture on an aggregated team0 networkoing device and dump packets into multiple
65 pcap files that are split into 100MiB each. Use mmap(2) I/O as a pcap write
66 method, enable support for super jumbo frames up to 64KB, and do not print
67 the captured data to the terminal. Pin netsniff-ng to and NIC IRQ affinity to
68 CPU 0. The default pcap magic type is 0xa1b2c3d4 (tcpdump-capable pcap).
70 .SS  netsniff-ng --in vlan0 --out dump.pcap -c -u `id -u bob` -g `id -g bob`
71 Capture network traffic on device wlan0 into a pcap file called dump.pcap
72 by using normal read(2), write(2) I/O for the pcap file (slower but less
73 latency). Also, after setting up the RX_RING for capture, drop priviledges
74 from root to the user/group ``bob''. Invoke the packet dissector and print
75 packet contents to the terminal for further analysis.
77 .SS  netsniff-ng --in any --filter http.bpf -B --jumbo-support --ascii -V
78 Capture from all available networking interfaces and install a low-level
79 filter that was previously compiled by bpfc(8) into http.bpf in order to
80 filter HTTP traffic. Enable super jumbo frame support and only print
81 human readable packet data to the terminal, be also more verbose during
82 setup phase. Moreover, dump BPF disassembly from http.bpf.
84 .SS  netsniff-ng --in dump.pcap --out dump.cfg --silent
85 Convert the pcap file dump.pcap into a trafgen(8) configuration file dump.cfg.
86 Do not print pcap contents to the terminal.
88 .SS netsniff-ng -i dump.pcap -f beacon.bpf -o -
89 Convert the pcap file dump.pcap into a trafgen(8) configuration file to
90 stdout. However, do not dump all of its content, but only the one that
91 passes the low-level filter for raw 802.11 from beacon.bpf. The BPF engine
92 here is invoked in user space inside of netsniff-ng, so Linux extensions
93 are not available.
95 .SS cat foo.pcap | netsniff-ng -i - -o -
96 Read a pcap file from stdin and convert it into a trafgen(8) configuration
97 file to stdout.
99 .SH FILTER EXAMPLE
101 netsniff-ng supports both, low-level and high-level filters that are
102 attached to its packet(7) socket. Low-level filters are described in
103 the bpfc(8) man page.
105 Low-level filters can be used with netsniff-ng in the following way:
107     1. bpfc foo > bar
108     2. netsniff-ng -f bar
110 Here, foo is the bpfc program that will be translated into a netsniff-ng
111 readable ``opcodes'' file and passed to netsniff-ng through the -f option.
113 Similarly, high-level filter can be either passed through the -f option,
114 e.g. -f "tcp or udp" or at the end of all options without the ``-f''.
116 The filter syntax is the same as in tcpdump(8), which is described in
117 the man page pcap-filter(7). Just to quote some examples from pcap-filter(7):
119 .SS host sundown
120 To select all packets arriving at or departing from sundown.
122 .SS host helios and \( hot or ace \)
123 To select traffic between helios and either hot or ace.
125 .SS ip host ace and not helios
126 To select all IP packets between ace and any host except helios.
128 .SS net ucb-ether
129 To select all traffic between local hosts and hosts at Berkeley.
131 .SS gateway snup and (port ftp or ftp-data)
132 To select all ftp traffic through internet gateway snup.
134 .SS ip and not net localnet
135 To select traffic neither sourced from nor destined for local hosts (if you
136 gateway to one other net, this stuff should never make it onto your local net).
138 .SS tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
139 To select the start and end packets (the SYN and FIN packets) of each TCP
140 conversation that involve a non-local host.
142 .SS tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
143 To select all IPv4 HTTP packets to and from port 80, i.e. print only packets
144 that contain data, not, for example, SYN and FIN packets and ACK-only packets.
145 (IPv6 is left as an exercise for the reader.)
147 .SS gateway snup and ip[2:2] > 576
148 To select IP packets longer than 576 bytes sent through gateway snup.
150 .SS ether[0] & 1 = 0 and ip[16] >= 224
151 To select IP broadcast or multicast packets that were not sent via Ethernet
152 broadcast or multicast.
154 .SS icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
155 To select all ICMP packets that are not echo requests/replies (i.e., not
156 ping packets).
158 .SH NOTE
159 For introducing bit errors, delays with random variation and more
160 while replaying pcaps, make use of tc(8) with its disciplines such
161 as netem.
163 netsniff-ng does only some basic, architecture generic tuning on
164 startup. If you are considering to do high performance capturing,
165 you need to carefully tune your machine, hardware and software-wise.
166 Simply letting netsniff-ng run without thinking about your underlying
167 system might not necessarily give you the desired performance. Note
168 that tuning your system is always a tradeoff and fine-grained
169 balancing act (e.g. throughput vs. latency). You should know what
170 you're doing!
172 One recommendation for software-based tuning is tuned(8). Besides
173 that, there are many other things to consider. Just to throw you
174 a few things that you might want to look at: NAPI networking drivers,
175 tickless kernel, I/OAT DMA engine, Direct Cache Access, RAM-based
176 file systems, multi-queues, and many more things. Also, you might
177 want to read the kernel's Documentation/networking/scaling.txt file
178 regarding technologies such as RSS, RPS, RFS, aRFS and XPS. Also
179 check your ethtool(8) settings, e.g. regarding offloading.
181 Moreover, to get a deeper understanding of netsniff-ng internals
182 and how it interacts with the Linux kernel, the kernel documentation
183 under Documentation/networking/{packet_mmap.txt, filter.txt,
184 multiqueue.txt} might be of interest.
186 If you do not need to dump all possible traffic, you have to consider
187 running netsniff-ng with a BPF filter for the ingress path. For that
188 purpose, read the bpfc(8) man page.
190 Also, to aggregate multiple NICs that you want to capture on, you
191 should consider using team devices, further explained in libteam resp.
192 teamd(8).
194 The following netsniff-ng pcap magic numbers are compatible with other
195 tools, at least tcpdump or Wireshark:
197     0xa1b2c3d4 (tcpdump-capable pcap)
198     0xa1b23c4d (tcpdump-capable pcap with ns resolution)
199     0xa1b2cd34 (Alexey Kuznetzov's pcap)
201 .SH BUGS
203 When replaying pcap files, the timing information from the pcap packet
204 header is currently ignored.
206 Also, when replaying pcap files, demultiplexing traffic among multiple
207 networking interfaces does not work. Currently, it is only sent via the
208 interface that is given by the --out parameter.
210 .SH LEGAL
211 netsniff-ng is licensed under the GNU GPL version 2.0.
213 .SH HISTORY
214 .B netsniff-ng
215 was originally written for the netsniff-ng toolkit by Daniel Borkmann. Bigger
216 contributions were made by Emmanuel Roullit, Markus Amend, Tobias Klauser and
217 Christoph Jaeger. It is currently maintained by Tobias Klauser
218 <tklauser@distanz.ch> and Daniel Borkmann <dborkma@tik.ee.ethz.ch>.
220 .SH SEE ALSO
221 .BR trafgen (8),
222 .BR mausezahn (8),
223 .BR ifpps (8),
224 .BR bpfc (8),
225 .BR flowtop (8),
226 .BR astraceroute (8),
227 .BR curvetun (8)
229 .SH AUTHOR
230 Manpage was written by Daniel Borkmann.