{"id":92365,"date":"2024-04-02T02:46:25","date_gmt":"2024-04-01T18:46:25","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=92365"},"modified":"2024-04-02T02:46:25","modified_gmt":"2024-04-01T18:46:25","slug":"linux-tcpdump-example","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-tcpdump-example.html","title":{"rendered":"tcpdump \u5e38\u7528\u4f8b\u5b50"},"content":{"rendered":"

tcpdump<\/span> \u662f\u4e00\u4e2a\u5f88\u5e38\u7528\u7684\u7f51\u7edc\u5305\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u663e\u793a\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u5230\u672c\u7cfb\u7edf\u7684 TCP\/IP \u4ee5\u53ca\u5176\u4ed6\u7f51\u7edc\u7684\u6570\u636e\u5305\u3002tcpdump<\/span> \u4f7f\u7528 libpcap \u5e93\u6765\u6293\u53d6\u7f51\u7edc\u62a5\uff0c\u8fd9\u4e2a\u5e93\u5728\u51e0\u4e4e\u5728\u6240\u6709\u7684 Linux\/Unix \u4e2d\u90fd\u6709\u3002<\/p>\n

tcpdump<\/span> \u53ef\u4ee5\u4ece\u7f51\u5361\u6216\u4e4b\u524d\u521b\u5efa\u7684\u6570\u636e\u5305\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5185\u5bb9\uff0c\u4e5f\u53ef\u4ee5\u5c06\u5305\u5199\u5165\u6587\u4ef6\u4e2d\u4ee5\u4f9b\u540e\u7eed\u4f7f\u7528\u3002\u5fc5\u987b\u662f root \u7528\u6237\u6216\u8005\u4f7f\u7528 sudo \u7279\u6743\u6765\u8fd0\u884c tcpdump<\/span>\u3002<\/p>\n

\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4f1a\u901a\u8fc7\u4e00\u4e9b\u5b9e\u4f8b\u6765\u6f14\u793a\u5982\u4f55\u4f7f\u7528 tcpdump<\/span> \u547d\u4ee4\uff0c\u4f46\u9996\u5148\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5728\u5404\u79cd Linux \u64cd\u4f5c\u7cfb\u7edf\u4e2d\u662f\u5982\u4f55\u5b89\u88c5 tcpdump<\/span> \u7684\u3002<\/p>\n

\u5b89\u88c5<\/strong><\/div>\n

tcpdump<\/span> \u9ed8\u8ba4\u5728\u51e0\u4e4e\u6240\u6709\u7684 Linux \u53d1\u884c\u7248\u4e2d\u90fd\u53ef\u7528\uff0c\u4f46\u82e5\u4f60\u7684 Linux \u4e0a\u6ca1\u6709\u7684\u8bdd\uff0c\u4f7f\u7528\u4e0b\u9762\u65b9\u6cd5\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n

CentOS\/RHEL<\/strong><\/span><\/div>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5728 CentOS \u548c RHEL \u4e0a\u5b89\u88c5 tcpdump<\/span>\uff0c<\/p>\n

$ sudo yum install tcpdump*\r\n<\/pre>\n
Fedora<\/strong><\/span><\/div>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5728 Fedora \u4e0a\u5b89\u88c5 tcpdump<\/span>\uff1a<\/p>\n

$ dnf install tcpdump\r\n<\/pre>\n
Ubuntu\/Debian\/Linux Mint<\/strong><\/span><\/div>\n

\u5728 Ubuntu\/Debain\/Linux Mint \u4e0a\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5b89\u88c5 tcpdump<\/span>\uff1a<\/p>\n

$ apt-get install tcpdump\r\n<\/pre>\n

\u5b89\u88c5\u597d tcpdump<\/span> \u540e\uff0c\u73b0\u5728\u6765\u770b\u4e00\u4e9b\u4f8b\u5b50\u3002<\/p>\n

\u6848\u4f8b\u6f14\u793a<\/strong><\/div>\n
\u4ece\u6240\u6709\u7f51\u5361\u4e2d\u6355\u83b7\u6570\u636e\u5305<\/strong><\/span><\/div>\n

\u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\u6765\u4ece\u6240\u6709\u7f51\u5361\u4e2d\u6355\u83b7\u6570\u636e\u5305\uff1a<\/p>\n

$ tcpdump -i any\r\n<\/pre>\n
\u4ece\u6307\u5b9a\u7f51\u5361\u4e2d\u6355\u83b7\u6570\u636e\u5305<\/strong><\/span><\/div>\n

\u8981\u4ece\u6307\u5b9a\u7f51\u5361\u4e2d\u6355\u83b7\u6570\u636e\u5305\uff0c\u8fd0\u884c\uff1a<\/p>\n

$ tcpdump -i eth0\r\n<\/pre>\n
\u5c06\u6355\u83b7\u7684\u5305\u5199\u5165\u6587\u4ef6<\/strong><\/span><\/div>\n

\u4f7f\u7528 -w<\/span> \u9009\u9879\u5c06\u6240\u6709\u6355\u83b7\u7684\u5305\u5199\u5165\u6587\u4ef6\uff1a<\/p>\n

$ tcpdump -i eth1 -w packets_file\r\n<\/pre>\n
\u8bfb\u53d6\u4e4b\u524d\u4ea7\u751f\u7684 tcpdump \u6587\u4ef6<\/strong><\/span><\/div>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u4ece\u4e4b\u524d\u521b\u5efa\u7684 tcpdump \u6587\u4ef6\u4e2d\u8bfb\u53d6\u5185\u5bb9\uff1a<\/p>\n

$ tcpdump -r packets_file\r\n<\/pre>\n
\u83b7\u53d6\u66f4\u591a\u7684\u5305\u4fe1\u606f\uff0c\u5e76\u4e14\u4ee5\u53ef\u8bfb\u7684\u5f62\u5f0f\u663e\u793a\u65f6\u95f4\u6233<\/strong><\/span><\/div>\n

\u8981\u83b7\u53d6\u66f4\u591a\u7684\u5305\u4fe1\u606f\u540c\u65f6\u4ee5\u53ef\u8bfb\u7684\u5f62\u5f0f\u663e\u793a\u65f6\u95f4\u6233\uff0c\u4f7f\u7528\uff1a<\/p>\n

$ tcpdump -ttttnnvvS\r\n<\/pre>\n
\u67e5\u770b\u6574\u4e2a\u7f51\u7edc\u7684\u6570\u636e\u5305<\/strong><\/span><\/div>\n

\u8981\u83b7\u53d6\u6574\u4e2a\u7f51\u7edc\u7684\u6570\u636e\u5305\uff0c\u5728\u7ec8\u7aef\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

$ tcpdump net 192.168.1.0\/24\r\n<\/pre>\n
\u6839\u636e IP \u5730\u5740\u67e5\u770b\u62a5\u6587<\/strong><\/span><\/div>\n

\u8981\u83b7\u53d6\u6307\u5b9a IP \u7684\u6570\u636e\u5305\uff0c\u4e0d\u7ba1\u662f\u4f5c\u4e3a\u6e90\u5730\u5740\u8fd8\u662f\u76ee\u7684\u5730\u5740\uff0c\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

$ tcpdump host 192.168.1.100\r\n<\/pre>\n

\u8981\u6307\u5b9a IP \u5730\u5740\u662f\u6e90\u5730\u5740\u6216\u662f\u76ee\u7684\u5730\u5740\u5219\u4f7f\u7528\uff1a<\/p>\n

$ tcpdump src 192.168.1.100\r\n$ tcpdump dst 192.168.1.100\r\n<\/pre>\n
\u67e5\u770b\u67d0\u4e2a\u534f\u8bae\u6216\u7aef\u53e3\u53f7\u7684\u6570\u636e\u5305<\/strong><\/span><\/div>\n

\u8981\u67e5\u770b\u67d0\u4e2a\u534f\u8bae\u7684\u6570\u636e\u5305\uff0c\u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

$ tcpdump ssh\r\n<\/pre>\n

\u8981\u6355\u83b7\u67d0\u4e2a\u7aef\u53e3\u6216\u4e00\u4e2a\u8303\u56f4\u7684\u6570\u636e\u5305\uff0c\u4f7f\u7528\uff1a<\/p>\n

$ tcpdump port 22\r\n$ tcpdump portrange 22-125\r\n<\/pre>\n

\u6211\u4eec\u4e5f\u53ef\u4ee5\u4e0e src<\/span> \u548c dst<\/span> \u9009\u9879\u8fde\u7528\u6765\u6355\u83b7\u6307\u5b9a\u6e90\u7aef\u53e3\u6216\u6307\u5b9a\u76ee\u7684\u7aef\u53e3\u7684\u62a5\u6587\u3002<\/p>\n

\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528\u201c\u4e0e\u201d \uff08and<\/span>\uff0c&&<\/span>\uff09\u3001\u201c\u6216\u201d \uff08or<\/span>\uff0c||<\/span> ) \u548c\u201c\u975e\u201d\uff08not<\/span>\uff0c!<\/span>\uff09 \u6765\u5c06\u4e24\u4e2a\u6761\u4ef6\u7ec4\u5408\u8d77\u6765\u3002\u5f53\u6211\u4eec\u9700\u8981\u57fa\u4e8e\u67d0\u4e9b\u6761\u4ef6\u6765\u5206\u6790\u7f51\u7edc\u62a5\u6587\u662f\u975e\u5e38\u6709\u7528\u3002<\/p>\n

\u4f7f\u7528\u201c\u4e0e\u201d<\/strong><\/span><\/div>\n

\u53ef\u4ee5\u4f7f\u7528 and<\/span> \u6216\u8005\u7b26\u53f7 &&<\/span> \u6765\u5c06\u4e24\u4e2a\u6216\u591a\u4e2a\u6761\u4ef6\u7ec4\u5408\u8d77\u6765\u3002\u6bd4\u5982\uff1a<\/p>\n

$ tcpdump src 192.168.1.100 && port 22 -w ssh_packets\r\n<\/pre>\n
\u4f7f\u7528\u201c\u6216\u201d<\/strong><\/span><\/div>\n

\u201c\u6216\u201d\u4f1a\u68c0\u67e5\u662f\u5426\u5339\u914d\u547d\u4ee4\u6240\u5217\u6761\u4ef6\u4e2d\u7684\u5176\u4e2d\u4e00\u6761\uff0c\u50cf\u8fd9\u6837\uff1a<\/p>\n

$ tcpdump src 192.168.1.100 or dst 192.168.1.50 && port 22 -w ssh_packets\r\n$ tcpdump port 443 or 80 -w http_packets\r\n<\/pre>\n
\u4f7f\u7528\u201c\u975e\u201d<\/strong><\/span><\/div>\n

\u5f53\u6211\u4eec\u60f3\u8868\u8fbe\u4e0d\u5339\u914d\u67d0\u9879\u6761\u4ef6\u65f6\u53ef\u4ee5\u4f7f\u7528\u201c\u975e\u201d\uff0c\u50cf\u8fd9\u6837\uff1a<\/p>\n

$ tcpdump -i eth0 src port not 22\r\n<\/pre>\n

\u8fd9\u4f1a\u6355\u83b7 eth0 \u4e0a\u9664\u4e86 22 \u53f7\u7aef\u53e3\u7684\u6240\u6709\u901a\u8baf\u3002<\/p>\n

\u6211\u4eec\u7684\u6559\u7a0b\u81f3\u6b64\u5c31\u7ed3\u675f\u4e86\uff0c\u5728\u672c\u6559\u7a0b\u4e2d\u6211\u4eec\u8bb2\u89e3\u4e86\u5982\u4f55\u5b89\u88c5\u5e76\u4f7f\u7528 tcpdump<\/span> \u6765\u6355\u83b7\u7f51\u7edc\u6570\u636e\u5305\u3002<\/p>\n


\n

via: http:\/\/linuxtechlab.com\/learn-use-tcpdump-command-examples\/<\/a><\/p>\n

\u4f5c\u8005\uff1aShusain<\/a>[2]<\/span> \u8bd1\u8005\uff1alujun9972<\/a>[3]<\/span> \u6821\u5bf9\uff1awxy<\/a>[4]<\/span><\/p>\n

\u672c\u6587\u7531 LCTT<\/a>[5]<\/span> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>[6]<\/span> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9210-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/linux-tcpdump-example.html<\/a>\u7f16\u8f91\uff1a\u9004\u589e\u5b9d\uff0c\u5ba1\u6838\u5458\uff1a\u5218\u9044<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

tcpdump \u662f\u4e00\u4e2a\u5f88\u5e38\u7528\u7684\u7f51\u7edc\u5305\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u663e\u793a\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u5230\u672c\u7cfb\u7edf\u7684 TCP\/IP \u4ee5\u53ca\u5176\u4ed6\u7f51\u7edc\u7684 […]<\/p>\n","protected":false},"author":309,"featured_media":92366,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-92365","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/92365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=92365"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/92365\/revisions"}],"predecessor-version":[{"id":92369,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/92365\/revisions\/92369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/92366"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=92365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=92365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=92365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}