{"id":106386,"date":"2024-10-03T19:02:10","date_gmt":"2024-10-03T11:02:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=106386"},"modified":"2024-10-03T19:02:10","modified_gmt":"2024-10-03T11:02:10","slug":"linux-ip-tools-skills","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ip-tools-skills.html","title":{"rendered":"Linux \u4e2d IP\u5de5\u5177\u4f7f\u7528\u6280\u5de7"},"content":{"rendered":"
\u5982\u4f55\u4f7f\u7528 IP \u5de5\u5177\u6765\u5feb\u901f\u8f7b\u677e\u5730\u627e\u5230\u4f60\u7684 IP \u5730\u5740\u3001\u663e\u793a\u8def\u7531\u8868\u7b49\u7b49\u3002<\/p>\n
<\/p>\n
ifconfig<\/span> \u547d\u4ee4\u5728 Linux \u4e0a\u88ab\u5f03\u7528\u5df2\u6709\u5341\u591a\u5e74\u7684\u65f6\u95f4\u4e86\uff0c\u800c iproute2<\/span> \u9879\u76ee\u5305\u542b\u4e86\u795e\u5947\u7684\u5de5\u5177 ip<\/span>\u3002\u8bb8\u591a\u5728\u7ebf\u6559\u7a0b\u8d44\u6e90\u4ecd\u7136\u91c7\u7528\u65e7\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5982 ifconfig<\/span>\u3001route<\/span> \u548c netstat<\/span>\u3002\u672c\u6559\u7a0b\u7684\u76ee\u6807\u662f\u5206\u4eab\u4e00\u4e9b\u53ef\u4ee5\u4f7f\u7528 ip<\/span> \u5de5\u5177\u8f7b\u677e\u5b8c\u6210\u7684\u7f51\u7edc\u76f8\u5173\u7684\u4e8b\u60c5\u3002<\/p>\n ip addr show<\/span> \u4f1a\u544a\u8bc9\u4f60\u5f88\u591a\u5173\u4e8e\u4f60\u7684\u6240\u6709\u7f51\u7edc\u94fe\u63a5\u8bbe\u5907\u7684\u4fe1\u606f\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u7684\u65e0\u7ebf\u4ee5\u592a\u7f51\u5361\uff08wlp4s0<\/span>\uff09\u662f IPv4 \u5730\u5740\uff08inet<\/span> \u5b57\u6bb5\uff0910.16.196.113\/23<\/span>\u3002 \/23<\/span> \u8868\u793a 32 \u4f4d IP \u5730\u5740\u4e2d\u7684 23 \u4f4d\u5c06\u88ab\u8be5\u5b50\u7f51\u4e2d\u7684\u6240\u6709 IP \u5730\u5740\u5171\u4eab\u3002\u5b50\u7f51\u4e2d\u7684 IP \u5730\u5740\u8303\u56f4\u4ece 10.16.196.0<\/span> \u5230 10.16.197.254<\/span>\u3002\u5b50\u7f51\u7684\u5e7f\u64ad\u5730\u5740\uff08IP \u5730\u5740\u540e\u9762\u7684 brd<\/span> \u5b57\u6bb5\uff0910.16.197.255<\/span> \u4fdd\u7559\u7ed9\u5b50\u7f51\u4e0a\u6240\u6709\u4e3b\u673a\u7684\u5e7f\u64ad\u6d41\u91cf\u3002<\/p>\n \u6211\u4eec\u80fd\u53ea\u4f7f\u7528 ip addr show dev wlp4s0<\/span> \u6765\u663e\u793a\u5355\u4e2a\u8bbe\u5907\u7684\u4fe1\u606f\u3002<\/p>\n \u8def\u7531\u8868\u662f\u672c\u5730\u4e3b\u673a\u5e2e\u52a9\u7f51\u7edc\u6d41\u91cf\u786e\u5b9a\u53bb\u54ea\u91cc\u7684\u65b9\u5f0f\u3002\u5b83\u5305\u542b\u4e00\u7ec4\u8def\u6807\uff0c\u5c06\u6d41\u91cf\u53d1\u9001\u5230\u7279\u5b9a\u7684\u63a5\u53e3\uff0c\u4ee5\u53ca\u5728\u5176\u65c5\u9014\u4e2d\u7684\u7279\u5b9a\u4e0b\u4e00\u4e2a\u5730\u70b9\u3002<\/p>\n \u5982\u679c\u4f60\u8fd0\u884c\u4efb\u4f55\u865a\u62df\u673a\u6216\u5bb9\u5668\uff0c\u5b83\u4eec\u5c06\u83b7\u5f97\u81ea\u5df1\u7684 IP \u5730\u5740\u548c\u5b50\u7f51\uff0c\u8fd9\u53ef\u80fd\u4f1a\u4f7f\u8fd9\u4e9b\u8def\u7531\u8868\u975e\u5e38\u590d\u6742\uff0c\u4f46\u5728\u5355\u4e2a\u4e3b\u673a\u4e2d\uff0c\u901a\u5e38\u6709\u4e24\u6761\u6307\u4ee4\u3002\u5bf9\u4e8e\u672c\u5730\u6d41\u91cf\uff0c\u5c06\u5176\u53d1\u9001\u5230\u672c\u5730\u4ee5\u592a\u7f51\u4e0a\uff0c\u5e76\u4e14\u7f51\u7edc\u4ea4\u6362\u673a\u5c06\u627e\u51fa\uff08\u4f7f\u7528\u79f0\u4e3a ARP \u7684\u534f\u8bae\uff09\u54ea\u4e2a\u4e3b\u673a\u62e5\u6709\u76ee\u6807 IP \u5730\u5740\uff0c\u5e76\u4e14\u8981\u5c06\u6d41\u91cf\u53d1\u9001\u5230\u54ea\u91cc\u3002\u5bf9\u4e8e\u5230\u4e92\u8054\u7f51\u7684\u6d41\u91cf\uff0c\u5c06\u5176\u53d1\u9001\u5230\u672c\u5730\u7f51\u5173\u8282\u70b9\uff0c\u5b83\u5c06\u66f4\u597d\u5730\u4e86\u89e3\u5982\u4f55\u5230\u8fbe\u76ee\u7684\u5730\u3002<\/p>\n \u5728\u4e0a\u9762\u7684\u60c5\u51b5\u4e2d\uff0c\u7b2c\u4e00\u884c\u4ee3\u8868\u5916\u90e8\u6d41\u91cf\u7684\u5916\u90e8\u7f51\u5173\uff0c\u7b2c\u4e8c\u884c\u4ee3\u8868\u672c\u5730\u6d41\u91cf\uff0c\u7b2c\u4e09\u884c\u4ee3\u8868\u4e3b\u673a\u4e0a\u8fd0\u884c\u7684\u865a\u62df\u673a\u7684\u865a\u62df\u7f51\u6865\uff0c\u4f46\u8be5\u94fe\u63a5\u5f53\u524d\u672a\u6fc0\u6d3b\u3002<\/p>\n ip monitor<\/span> \u547d\u4ee4\u53ef\u7528\u4e8e\u76d1\u89c6\u8def\u7531\u8868\uff08\u7f51\u7edc\u63a5\u53e3\u4e0a\u7684\u7f51\u7edc\u5bfb\u5740\uff09\u7684\u66f4\u6539\u6216\u672c\u5730\u4e3b\u673a\u4e0a ARP \u8868\u7684\u66f4\u6539\u3002\u6b64\u547d\u4ee4\u5728\u8c03\u8bd5\u4e0e\u5bb9\u5668\u548c\u7f51\u7edc\u76f8\u5173\u7684\u7f51\u7edc\u95ee\u9898\u65f6\u7279\u522b\u6709\u7528\uff0c\u5982\u5f53\u4e24\u4e2a\u865a\u62df\u673a\u5e94\u8be5\u80fd\u5f7c\u6b64\u901a\u4fe1\uff0c\u4f46\u5b9e\u9645\u4e0d\u80fd\u3002<\/p>\n \u5728\u4f7f\u7528 all<\/span> \u65f6\uff0cip monitor<\/span> \u4f1a\u62a5\u544a\u6240\u6709\u7684\u66f4\u6539\uff0c\u524d\u7f00\u4ee5 [LINK]<\/span>\uff08\u7f51\u7edc\u63a5\u53e3\u66f4\u6539\uff09\u3001[ROUTE]<\/span>\uff08\u66f4\u6539\u8def\u7531\u8868\uff09\u3001[ADDR]<\/span>\uff08IP \u5730\u5740\u66f4\u6539\uff09\u6216 [NEIGH]<\/span>\uff08\u4e0e\u9a6c\u65e0\u5173 \u2014\u2014 \u4e0e\u90bb\u5c45\u7684 ARP \u5730\u5740\u76f8\u5173\u7684\u53d8\u5316\uff09\u3002<\/p>\n \u4f60\u8fd8\u53ef\u4ee5\u76d1\u89c6\u7279\u5b9a\u5bf9\u8c61\u4e0a\u7684\u66f4\u6539\uff08\u4f8b\u5982\uff0c\u7279\u5b9a\u7684\u8def\u7531\u8868\u6216 IP \u5730\u5740\uff09\u3002<\/p>\n \u53e6\u4e00\u4e2a\u9002\u7528\u4e8e\u8bb8\u591a\u547d\u4ee4\u7684\u6709\u7528\u9009\u9879\u662f ip -s<\/span>\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7edf\u8ba1\u4fe1\u606f\u3002\u6dfb\u52a0\u7b2c\u4e8c\u4e2a -s<\/span> \u9009\u9879\u53ef\u4ee5\u6dfb\u52a0\u66f4\u591a\u7edf\u8ba1\u4fe1\u606f\u3002\u4e0a\u9762\u7684 ip -s link list wlp4s0<\/span> \u4f1a\u7ed9\u51fa\u5f88\u591a\u5173\u4e8e\u63a5\u6536\u548c\u53d1\u9001\u7684\u6570\u636e\u5305\u7684\u4fe1\u606f\u3001\u4e22\u5f03\u7684\u6570\u636e\u5305\u6570\u91cf\u3001\u68c0\u6d4b\u5230\u7684\u9519\u8bef\u7b49\u7b49\u3002<\/p>\n \u4e00\u822c\u6765\u8bf4\uff0c\u5bf9\u4e8e ip<\/span> \u5de5\u5177\uff0c\u4f60\u53ea\u9700\u8981\u5305\u542b\u8db3\u591f\u7684\u5b57\u6bcd\u6765\u552f\u4e00\u6807\u8bc6\u4f60\u60f3\u8981\u505a\u7684\u4e8b\u60c5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 ip mon<\/span> \u6765\u4ee3\u66ff ip monitor<\/span>\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 ip a l<\/span>\uff0c\u800c\u4e0d\u662f ip addr list<\/span>\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528 ip r<\/span>\u6765\u4ee3\u66ff ip route<\/span>\u3002ip link list<\/span> \u53ef\u4ee5\u7f29\u5199\u4e3a ip l ls<\/span>\u3002\u8981\u4e86\u89e3\u53ef\u7528\u4e8e\u66f4\u6539\u547d\u4ee4\u884c\u4e3a\u7684\u8bb8\u591a\u9009\u9879\uff0c\u8bf7\u6d4f\u89c8 ip \u624b\u518c\u9875<\/a>[1]<\/span>\u3002<\/p>\n via: https:\/\/opensource.com\/article\/18\/5\/useful-things-you-can-do-with-IP-tool-Linux<\/a><\/p>\n \u4f5c\u8005\uff1aDave Neary<\/a>[2]<\/span> \u9009\u9898\uff1alujun9972<\/a>[3]<\/span> \u8bd1\u8005\uff1ageekpi<\/a>[4]<\/span> \u6821\u5bf9\uff1awxy<\/a>[5]<\/span><\/p>\n \u672c\u6587\u7531 LCTT<\/a>[6]<\/span> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a>[7]<\/span> \u8363\u8a89\u63a8\u51fa<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9704-1.html<\/a><\/p>\n[dneary@host]$ ip addr show\r\n[snip]\r\n44: wlp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000\r\n link\/ether 5c:e0:c5:c7:f0:f1 brd ff:ff:ff:ff:ff:ff\r\n inet 10.16.196.113\/23 brd 10.16.197.255 scope global dynamic wlp4s0\r\n valid_lft 74830sec preferred_lft 74830sec\r\n inet6 fe80::5ee0:c5ff:fec7:f0f1\/64 scope link\r\n valid_lft forever preferred_lft forever\r\n<\/pre>\n
[dneary@host]$ ip route list\r\ndefault via 10.16.197.254 dev wlp4s0 proto static metric 600\r\n10.16.196.0\/23 dev wlp4s0 proto kernel scope link src 10.16.196.113 metric 601\r\n192.168.122.0\/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown\r\n<\/pre>\n
[dneary@host]$ ip monitor all\r\n[dneary@host]$ ip -s link list wlp4s0\r\n<\/pre>\n
\n\n