aoishiの備忘録

備忘録

CentOS7のtcpdumpでインターフェースを指定しないとエラーになる

はじめに

CentOS7のtcpdumpで、ネットワークインターフェースを明示的に指定しない場合に下記のメッセージが出力されたので、その際に対応したことをまとめます。

$ sudo tcpdump
tcpdump: packet printing is not supported for link type NFLOG: use -w

環境

tcpdumpがエラーになった原因

tcpdumpはネットワークインターフェースが指定されなかった場合、インターフェース一覧の先頭のものに対して動作するようです。

利用可能なネットワークインターフェース一覧は、下記コマンドで確認できます。

$ sudo tcpdump -D
1.nflog (Linux netfilter log (NFLOG) interface)
2.nfqueue (Linux netfilter queue (NFQUEUE) interface)
3.usbmon1 (USB bus number 1)
4.usbmon2 (USB bus number 2)
5.ens160
6.any (Pseudo-device that captures on all interfaces)
7.lo [Loopback]

このため、1. のnflogというインターフェースで動作しており、このインターフェースでtcpdumpしようとしたことでエラーとなっていたようです。

なお上記の仕様については、manコマンドで確認できます。

$ man tcpdump
~~~
-i interface
--interface=interface
       Listen on interface.  If unspecified, tcpdump searches the sys‐
       tem  interface  list  for  the  lowest  numbered, configured up
       interface (excluding loopback), which may turn out to  be,  for
       example, ``eth0''.

       On  Linux systems with 2.2 or later kernels, an interface argu‐
       ment of ``any'' can be used to capture packets from all  inter‐
       faces.   Note  that  captures on the ``any'' device will not be
       done in promiscuous mode.

       If the -D flag is supported, an interface number as printed  by
       that  flag  can be used as the interface argument, if no inter‐
       face on the system has that number as a name.
~~~

tcpdumpでインターフェースを指定する方法

今回確認したかったのは、ens160(CentOS7では一般的?)なので、インターフェース名か一覧の番号を指定してtcpdumpし直します。

$ sudo tcpdump -i ens160
or 
$ sudo tcpdump -i 5

また、manの説明にもありましたが、anyを指定すると全インターフェースに対して動作させることができるようです。

$ sudo tcpdump -i any

まとめ

CentOS7のtcpdumpでインターフェースを明示的にしないことで発生したメッセージに対する対応方法をまとめてみました。

普段何気なく使っているtcpdumpですが、改めてmanを読むと新たな気づきとか勉強になることが沢山ありますね。

参考

��2898 CentOS7のtcpdumpがなにやらおかしい - Web Patio - CentOSで自宅サーバー構築