man: netsniff-ng: add description paragraph and some options
[netsniff-ng.git] / man / netsniff-ng.8
blob9e7fe0beafb31c9aba29ed398b445c668856e313
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 netsniff-ng is a fast, minimal tool to i) analyze network packets, ii) capture
16 pcap files, iii) replay pcap files or iv) redirect traffic between interfaces
17 with the help of zero-copy packet(7) sockets. netsniff-ng uses both, Linux
18 specific RX_RING and TX_RING interfaces to perform zero-copy, that is, to avoid
19 copies and system call overhead between kernel and user address space. At the
20 time, we started hacking on netsniff-ng, the pcap(3) library did not use this
21 zero-copy facility.
23 netsniff-ng is Linux specific only, meaning there is no support for other
24 operating systems, thus we can keep the code footprint quite minimal and to
25 the point. Linux' packet(7) sockets and its RX_RING and TX_RING interfaces
26 bypass the normal packet processing path through the networking stack. Thus,
27 this is the fastest one can get out of the box in terms of capturing or
28 transmission performance from user space, without having to load unsupported
29 or non-mainline third-party kernel modules. We explicitly refuse to build
30 netsniff-ng on top of ntop/PF_RING. Not because we do not like it (we do find
31 it interesting), but because of the fact that it is not part of the mainline
32 kernel. Therefore, the ntop project has to maintain/sync out-of-tree drivers
33 to adapt them to their DNA. Eventually, we went for untainted Linux kernel,
34 since its code has a higher rate of reviews, maintenance, security and bug
35 fixes.
37 netsniff-ng also supports early packet filtering in the kernel. It has support
38 for low-level and high-level packet filters that are translated into Berkeley
39 Packet Filter instructions.
41 netsniff-ng can capture pcap files in several different pcap formats that
42 are interoperable with other tools. It has different pcap I/O methods supported
43 (scatter-gather, mmap(2), read(2)/write(2)) for efficient to-disc capturing.
44 netsniff-ng is also able to rotate pcap files based on data size or time
45 intervals, thus, making it a useful backend tool for subsequent traffic
46 analysis.
48 netsniff-ng itself also supports analysis, dumping or replay of raw 802.11
49 frames. For online or offline analysis netsniff-ng has a built-in packet
50 dissector for currently 802.3 (Ethernet), 802.11* (WLAN), ARP, MPLS, 802.1Q
51 (VLAN), 802.1QinQ, LLDP, IPv4, IPv6, ICMPv4, ICMPv6, IGMP, TCP and UDP,
52 including GeoIP location analysis. Since netsniff-ng does not establish any
53 state or reassembly during packet dissection, its memory footprint is quite
54 low, thus, making netsniff-ng quite efficient for offline analysis of large
55 pcap files as well.
57 .SH OPTIONS
59 .\"  -i|-d|--dev|--in <dev|pcap|->  Input source as netdev, pcap or pcap stdin
60 .\"  -o|--out <dev|pcap|dir|cfg|->  Output sink as netdev, pcap, directory, trafgen, or stdout
61 .\"  -f|--filter <bpf-file|expr>    Use BPF filter file from bpfc or tcpdump-like expression
62 .\"  -t|--type <type>               Filter for: host|broadcast|multicast|others|outgoing
63 .\"  -F|--interval <size|time>      Dump interval if -o is a dir: <num>KiB/MiB/GiB/s/sec/min/hrs
64 .\"  -J|--jumbo-support             Support for 64KB Super Jumbo Frames (def: 2048B)
65 .\"  -R|--rfraw                     Capture or inject raw 802.11 frames
66 .\"  -n|--num <0|uint>              Number of packets until exit (def: 0)
67 .\"  -P|--prefix <name>             Prefix for pcaps stored in directory
68 .\"  -T|--magic <pcap-magic>        Pcap magic number/pcap format to store, see -D
69 .\"  -D|--dump-pcap-types           Dump pcap types and magic numbers and quit
70 .\"  -B|--dump-bpf                  Dump generated BPF assembly
71 .\"  -r|--rand                      Randomize packet forwarding order (dev->dev)
72 .\"  -M|--no-promisc                No promiscuous mode for netdev
73 .\"  -A|--no-sock-mem               Don't tune core socket memory
74 .\"  -m|--mmap                      Mmap(2) pcap file i.e., for replaying pcaps
75 .\"  -G|--sg                        Scatter/gather pcap file I/O
76 .\"  -c|--clrw                      Use slower read(2)/write(2) I/O
77 .\"  -S|--ring-size <size>          Specify ring size to: <num>KiB/MiB/GiB
78 .\"  -k|--kernel-pull <uint>        Kernel pull from user interval in us (def: 10us)
79 .\"  -b|--bind-cpu <cpu>            Bind to specific CPU
80 .\"  -u|--user <userid>             Drop privileges and change to userid
81 .\"  -g|--group <groupid>           Drop privileges and change to groupid
82 .\"  -H|--prio-high                 Make this high priority process
83 .\"  -Q|--notouch-irq               Do not touch IRQ CPU affinity of NIC
84 .\"  -s|--silent                    Do not print captured packets
85 .\"  -q|--less                      Print less-verbose packet information
86 .\"  -X|--hex                       Print packet data in hex format
87 .\"  -l|--ascii                     Print human-readable packet data
89 .SS -U, --update
90 If geographical IP locationing should be used, the built-in database update
91 mechanism will be invoked to get Maxmind's latest database. To configure
92 search locations for databases, the file /etc/netsniff-ng/geoip.conf contains
93 possible addresses. Thus, to save bandwidth or for mirroring Maxmind's
94 databases (to bypass their traffic limit policy), different hosts or IP
95 addresses can be placed into geoip.conf, separated by a newline.
97 .SS -V, --verbose
98 Be more verbose during startup, i.e. show detailled ring setup information.
100 .SS -v, --version
101 Show versioning information.
103 .SS -h, --help
104 Show user help.
106 .SH USAGE EXAMPLE
108 .SS netsniff-ng
109 The most simple command is to just run ``netsniff-ng''. This will start
110 listening on all available networking devices in promiscuous mode and dump
111 the packet dissector output to the terminal. No files will be recorded.
113 .SS  netsniff-ng --in eth0 --out dump.pcap -s -T 0xa1e2cb12 -b 0 tcp or udp
114 Capture TCP or UDP traffic from the networking device eth0 into the pcap file
115 named dump.pcap, which has netsniff-ng specific pcap extensions (see
116 ``netsniff-ng -D'' for capabilities). Also, do not print the content to the
117 terminal and pin the process and NIC IRQ affinity to CPU 0. The pcap write
118 method is scatter-gather I/O.
120 .SS  netsniff-ng --in wlan0 --rfraw --out dump.pcap --silent --bind-cpu 0
121 Put the wlan0 device into monitoring mode and capture all raw 802.11 frames
122 into the file dump.pcap. Do not dissect and print the content to the terminal
123 and pin the process and NIC IRQ affinity to CPU 0. The pcap write method is
124 scatter-gather I/O.
126 .SS  netsniff-ng --in dump.pcap --mmap --out eth0 -k1000 --silent --bind-cpu 0
127 Replay the pcap file dump.pcap which is read through mmap(2) I/O and send
128 the packets out via the eth0 networking device. Do not dissect and print the
129 content to the terminal and pin the process and NIC IRQ affinity to CPU 0.
130 Also trigger the kernel every 1000us to traverse the TX_RING instead of every
131 10us. Note that the pcap magic type is detected automatically from the pcap
132 file header.
134 .SS  netsniff-ng --in eth0 --out eth1 --silent --bind-cpu 0 --type host -r
135 Redirect network traffic from the networking device eth0 to eth1 for traffic
136 that is destined to our host, thus ignore broadcast, multicast and promiscuous
137 traffic. Randomize the order of packets for the outgoing device and do not
138 print any packet contents to the terminal. Also, pin the process and NIC IRQ
139 affinity to CPU 0.
141 .SS  netsniff-ng --in team0 --out /opt/probe/ -s -m -J --interval 100MiB -b 0
142 Capture on an aggregated team0 networkoing device and dump packets into multiple
143 pcap files that are split into 100MiB each. Use mmap(2) I/O as a pcap write
144 method, enable support for super jumbo frames up to 64KB, and do not print
145 the captured data to the terminal. Pin netsniff-ng to and NIC IRQ affinity to
146 CPU 0. The default pcap magic type is 0xa1b2c3d4 (tcpdump-capable pcap).
148 .SS  netsniff-ng --in vlan0 --out dump.pcap -c -u `id -u bob` -g `id -g bob`
149 Capture network traffic on device wlan0 into a pcap file called dump.pcap
150 by using normal read(2), write(2) I/O for the pcap file (slower but less
151 latency). Also, after setting up the RX_RING for capture, drop priviledges
152 from root to the user/group ``bob''. Invoke the packet dissector and print
153 packet contents to the terminal for further analysis.
155 .SS  netsniff-ng --in any --filter http.bpf -B --jumbo-support --ascii -V
156 Capture from all available networking interfaces and install a low-level
157 filter that was previously compiled by bpfc(8) into http.bpf in order to
158 filter HTTP traffic. Enable super jumbo frame support and only print
159 human readable packet data to the terminal, be also more verbose during
160 setup phase. Moreover, dump BPF disassembly from http.bpf.
162 .SS  netsniff-ng --in dump.pcap --out dump.cfg --silent
163 Convert the pcap file dump.pcap into a trafgen(8) configuration file dump.cfg.
164 Do not print pcap contents to the terminal.
166 .SS netsniff-ng -i dump.pcap -f beacon.bpf -o -
167 Convert the pcap file dump.pcap into a trafgen(8) configuration file to
168 stdout. However, do not dump all of its content, but only the one that
169 passes the low-level filter for raw 802.11 from beacon.bpf. The BPF engine
170 here is invoked in user space inside of netsniff-ng, so Linux extensions
171 are not available.
173 .SS cat foo.pcap | netsniff-ng -i - -o -
174 Read a pcap file from stdin and convert it into a trafgen(8) configuration
175 file to stdout.
177 .SH FILTER EXAMPLE
179 netsniff-ng supports both, low-level and high-level filters that are
180 attached to its packet(7) socket. Low-level filters are described in
181 the bpfc(8) man page.
183 Low-level filters can be used with netsniff-ng in the following way:
185     1. bpfc foo > bar
186     2. netsniff-ng -f bar
188 Here, foo is the bpfc program that will be translated into a netsniff-ng
189 readable ``opcodes'' file and passed to netsniff-ng through the -f option.
191 Similarly, high-level filter can be either passed through the -f option,
192 e.g. -f "tcp or udp" or at the end of all options without the ``-f''.
194 The filter syntax is the same as in tcpdump(8), which is described in
195 the man page pcap-filter(7). Just to quote some examples from pcap-filter(7):
197 .SS host sundown
198 To select all packets arriving at or departing from sundown.
200 .SS host helios and \( hot or ace \)
201 To select traffic between helios and either hot or ace.
203 .SS ip host ace and not helios
204 To select all IP packets between ace and any host except helios.
206 .SS net ucb-ether
207 To select all traffic between local hosts and hosts at Berkeley.
209 .SS gateway snup and (port ftp or ftp-data)
210 To select all ftp traffic through internet gateway snup.
212 .SS ip and not net localnet
213 To select traffic neither sourced from nor destined for local hosts (if you
214 gateway to one other net, this stuff should never make it onto your local net).
216 .SS tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
217 To select the start and end packets (the SYN and FIN packets) of each TCP
218 conversation that involve a non-local host.
220 .SS tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
221 To select all IPv4 HTTP packets to and from port 80, i.e. print only packets
222 that contain data, not, for example, SYN and FIN packets and ACK-only packets.
223 (IPv6 is left as an exercise for the reader.)
225 .SS gateway snup and ip[2:2] > 576
226 To select IP packets longer than 576 bytes sent through gateway snup.
228 .SS ether[0] & 1 = 0 and ip[16] >= 224
229 To select IP broadcast or multicast packets that were not sent via Ethernet
230 broadcast or multicast.
232 .SS icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
233 To select all ICMP packets that are not echo requests/replies (i.e., not
234 ping packets).
236 .SH NOTE
237 For introducing bit errors, delays with random variation and more
238 while replaying pcaps, make use of tc(8) with its disciplines such
239 as netem.
241 netsniff-ng does only some basic, architecture generic tuning on
242 startup. If you are considering to do high performance capturing,
243 you need to carefully tune your machine, hardware and software-wise.
244 Simply letting netsniff-ng run without thinking about your underlying
245 system might not necessarily give you the desired performance. Note
246 that tuning your system is always a tradeoff and fine-grained
247 balancing act (e.g. throughput vs. latency). You should know what
248 you're doing!
250 One recommendation for software-based tuning is tuned(8). Besides
251 that, there are many other things to consider. Just to throw you
252 a few things that you might want to look at: NAPI networking drivers,
253 tickless kernel, I/OAT DMA engine, Direct Cache Access, RAM-based
254 file systems, multi-queues, and many more things. Also, you might
255 want to read the kernel's Documentation/networking/scaling.txt file
256 regarding technologies such as RSS, RPS, RFS, aRFS and XPS. Also
257 check your ethtool(8) settings, e.g. regarding offloading.
259 Moreover, to get a deeper understanding of netsniff-ng internals
260 and how it interacts with the Linux kernel, the kernel documentation
261 under Documentation/networking/{packet_mmap.txt, filter.txt,
262 multiqueue.txt} might be of interest.
264 If you do not need to dump all possible traffic, you have to consider
265 running netsniff-ng with a BPF filter for the ingress path. For that
266 purpose, read the bpfc(8) man page.
268 Also, to aggregate multiple NICs that you want to capture on, you
269 should consider using team devices, further explained in libteam resp.
270 teamd(8).
272 The following netsniff-ng pcap magic numbers are compatible with other
273 tools, at least tcpdump or Wireshark:
275     0xa1b2c3d4 (tcpdump-capable pcap)
276     0xa1b23c4d (tcpdump-capable pcap with ns resolution)
277     0xa1b2cd34 (Alexey Kuznetzov's pcap)
279 Pcap files with different meta data endianess are supported by netsniff-ng
280 as well.
282 .SH BUGS
284 When replaying pcap files, the timing information from the pcap packet
285 header is currently ignored.
287 Also, when replaying pcap files, demultiplexing traffic among multiple
288 networking interfaces does not work. Currently, it is only sent via the
289 interface that is given by the --out parameter.
291 .SH LEGAL
292 netsniff-ng is licensed under the GNU GPL version 2.0.
294 .SH HISTORY
295 .B netsniff-ng
296 was originally written for the netsniff-ng toolkit by Daniel Borkmann. Bigger
297 contributions were made by Emmanuel Roullit, Markus Amend, Tobias Klauser and
298 Christoph Jaeger. It is currently maintained by Tobias Klauser
299 <tklauser@distanz.ch> and Daniel Borkmann <dborkma@tik.ee.ethz.ch>.
301 .SH SEE ALSO
302 .BR trafgen (8),
303 .BR mausezahn (8),
304 .BR ifpps (8),
305 .BR bpfc (8),
306 .BR flowtop (8),
307 .BR astraceroute (8),
308 .BR curvetun (8)
310 .SH AUTHOR
311 Manpage was written by Daniel Borkmann.