{"id":92902,"date":"2024-04-03T10:54:03","date_gmt":"2024-04-03T02:54:03","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=92902"},"modified":"2024-04-03T10:54:03","modified_gmt":"2024-04-03T02:54:03","slug":"ip-command-example","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ip-command-example.html","title":{"rendered":"iproute \u5b89\u88c5\u5305\u4e2d 12\u4e2a ip \u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"

\u4e00\u5e74\u53c8\u4e00\u5e74\uff0c\u6211\u4eec\u4e00\u76f4\u5728\u4f7f\u7528 ifconfig<\/span> \u547d\u4ee4\u6765\u6267\u884c\u7f51\u7edc\u76f8\u5173\u7684\u4efb\u52a1\uff0c\u6bd4\u5982\u68c0\u67e5\u548c\u914d\u7f6e\u7f51\u5361\u4fe1\u606f\u3002\u4f46\u662fifconfig<\/span> \u5df2\u7ecf\u4e0d\u518d\u88ab\u7ef4\u62a4\uff0c\u5e76\u4e14\u5728\u6700\u8fd1\u7248\u672c\u7684 Linux \u4e2d\u88ab\u5e9f\u9664\u4e86\uff01 ifconfig<\/span> \u547d\u4ee4\u5df2\u7ecf\u88ab ip<\/span> \u547d\u4ee4\u6240\u66ff\u4ee3\u4e86\u3002<\/p>\n

ip<\/span> \u547d\u4ee4\u8ddf ifconfig<\/span> \u547d\u4ee4\u6709\u4e9b\u7c7b\u4f3c\uff0c\u4f46\u8981\u5f3a\u529b\u7684\u591a\uff0c\u5b83\u6709\u8bb8\u591a\u65b0\u529f\u80fd\u3002ip<\/span> \u547d\u4ee4\u5b8c\u6210\u5f88\u591a ifconfig<\/span>\u547d\u4ee4\u65e0\u6cd5\u5b8c\u6210\u7684\u4efb\u52a1\u3002<\/p>\n

\"\"<\/p>\n

\u672c\u6559\u7a0b\u5c06\u4f1a\u8ba8\u8bba ip<\/span> \u547d\u4ee4\u7684 12 \u4e2d\u6700\u5e38\u7528\u6cd5\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\u3002<\/p>\n

\u6848\u4f8b 1\uff1a\u68c0\u67e5\u7f51\u5361\u4fe1\u606f<\/strong><\/div>\n

\u68c0\u67e5\u7f51\u5361\u7684\u8bf8\u5982 IP \u5730\u5740\uff0c\u5b50\u7f51\u7b49\u7f51\u7edc\u4fe1\u606f\uff0c\u4f7f\u7528 ip addr show<\/span> \u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ ip addr show\r\n\r\n\u6216\r\n\r\n[linuxtechi@localhost]$ ip a s\r\n<\/pre>\n

\u8fd9\u4f1a\u663e\u793a\u7cfb\u7edf\u4e2d\u6240\u6709\u53ef\u7528\u7f51\u5361\u7684\u76f8\u5173\u7f51\u7edc\u4fe1\u606f\uff0c\u4e0d\u8fc7\u5982\u679c\u4f60\u60f3\u67e5\u770b\u67d0\u5757\u7f51\u5361\u7684\u4fe1\u606f\uff0c\u5219\u547d\u4ee4\u4e3a\uff1a<\/p>\n

[linuxtechi@localhost]$ ip addr show enp0s3\r\n<\/pre>\n

\u8fd9\u91cc enp0s3<\/span> \u662f\u7f51\u5361\u7684\u540d\u5b57\u3002<\/p>\n

\"\"<\/p>\n

IP-addr-show-commant-output<\/em><\/p>\n

\u6848\u4f8b 2\uff1a\u542f\u7528\/\u7981\u7528\u7f51\u5361<\/strong><\/div>\n

\u4f7f\u7528 ip<\/span> \u547d\u4ee4\u6765\u542f\u7528\u4e00\u4e2a\u88ab\u7981\u7528\u7684\u7f51\u5361\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip link set enp0s3 up\r\n<\/pre>\n

\u800c\u8981\u7981\u7528\u7f51\u5361\u5219\u4f7f\u7528 down<\/span> \u89e6\u53d1\u5668\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip link set enp0s3 down\r\n<\/pre>\n
\u6848\u4f8b 3\uff1a\u4e3a\u7f51\u5361\u5206\u914d IP \u5730\u5740\u4ee5\u53ca\u5176\u4ed6\u7f51\u7edc\u4fe1\u606f<\/strong><\/div>\n

\u8981\u4e3a\u7f51\u5361\u5206\u914d IP \u5730\u5740\uff0c\u6211\u4eec\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip addr add 192.168.0.50\/255.255.255.0 dev enp0s3\r\n<\/pre>\n

\u4e5f\u53ef\u4ee5\u4f7f\u7528 ip<\/span> \u547d\u4ee4\u6765\u8bbe\u7f6e\u5e7f\u64ad\u5730\u5740\u3002\u9ed8\u8ba4\u662f\u6ca1\u6709\u8bbe\u7f6e\u5e7f\u64ad\u5730\u5740\u7684\uff0c\u8bbe\u7f6e\u5e7f\u64ad\u5730\u5740\u7684\u547d\u4ee4\u4e3a\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo\u00a0 ip addr add broadcast 192.168.0.255 dev enp0s3\r\n<\/pre>\n

\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u6765\u6839\u636e IP \u5730\u5740\u8bbe\u7f6e\u6807\u51c6\u7684\u5e7f\u64ad\u5730\u5740\uff1a<\/p>\n

[linuxtechi@localhost]$ \u00a0sudo ip addr add 192.168.0.10\/24 brd + dev enp0s3\r\n<\/pre>\n

\u5982\u4e0a\u9762\u4f8b\u5b50\u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 brd<\/span> \u4ee3\u66ff broadcast<\/span> \u6765\u8bbe\u7f6e\u5e7f\u64ad\u5730\u5740\u3002<\/p>\n

\u6848\u4f8b 4\uff1a\u5220\u9664\u7f51\u5361\u4e2d\u914d\u7f6e\u7684 IP \u5730\u5740<\/strong><\/div>\n

\u82e5\u60f3\u4ece\u7f51\u5361\u4e2d\u5220\u6389\u67d0\u4e2a IP\uff0c\u4f7f\u7528\u5982\u4e0b ip<\/span> \u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip addr del 192.168.0.10\/24 dev enp0s3\r\n<\/pre>\n
\u6848\u4f8b 5\uff1a\u4e3a\u7f51\u5361\u6dfb\u52a0\u522b\u540d\uff08\u5047\u8bbe\u7f51\u5361\u540d\u4e3a enp0s3\uff09<\/strong><\/div>\n

\u6dfb\u52a0\u522b\u540d\uff0c\u5373\u4e3a\u7f51\u5361\u6dfb\u52a0\u4e0d\u6b62\u4e00\u4e2a IP\uff0c\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a
\n\"\"<\/p>\n

[linuxtechi@localhost]$ \u00a0sudo ip addr add 192.168.0.20\/24 dev enp0s3 label enp0s3:1\r\n<\/pre>\n

ip-command-add-alias-linux<\/em><\/p>\n

\u6848\u4f8b 6\uff1a\u68c0\u67e5\u8def\u7531\/\u9ed8\u8ba4\u7f51\u5173\u7684\u4fe1\u606f<\/strong><\/div>\n

\u67e5\u770b\u8def\u7531\u4fe1\u606f\u4f1a\u7ed9\u6211\u4eec\u663e\u793a\u6570\u636e\u5305\u5230\u8fbe\u76ee\u7684\u5730\u7684\u8def\u7531\u8def\u5f84\u3002\u8981\u67e5\u770b\u7f51\u7edc\u8def\u7531\u4fe1\u606f\uff0c\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ \u00a0ip route show\r\n<\/pre>\n

\"\"<\/p>\n

ip-route-command-output<\/em><\/p>\n

\u5728\u4e0a\u9762\u8f93\u51fa\u7ed3\u679c\u4e2d\uff0c\u6211\u4eec\u80fd\u591f\u770b\u5230\u6240\u6709\u7f51\u5361\u4e0a\u6570\u636e\u5305\u7684\u8def\u7531\u4fe1\u606f\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u83b7\u53d6\u7279\u5b9a IP \u7684\u8def\u7531\u4fe1\u606f\uff0c\u65b9\u6cd5\u662f\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip route get 192.168.0.1\r\n<\/pre>\n
\u6848\u4f8b 7\uff1a\u6dfb\u52a0\u9759\u6001\u8def\u7531<\/strong><\/div>\n

\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528 IP \u6765\u4fee\u6539\u6570\u636e\u5305\u7684\u9ed8\u8ba4\u8def\u7531\u3002\u65b9\u6cd5\u662f\u4f7f\u7528 ip route<\/span> \u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip route add default via 192.168.0.150\/24\r\n<\/pre>\n

\u8fd9\u6837\u6240\u6709\u7684\u7f51\u7edc\u6570\u636e\u5305\u901a\u8fc7 192.168.0.150<\/span> \u6765\u8f6c\u53d1\uff0c\u800c\u4e0d\u662f\u4ee5\u524d\u7684\u9ed8\u8ba4\u8def\u7531\u4e86\u3002\u82e5\u8981\u4fee\u6539\u67d0\u4e2a\u7f51\u5361\u7684\u9ed8\u8ba4\u8def\u7531\uff0c\u6267\u884c\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip route add 172.16.32.32 via 192.168.0.150\/24 dev enp0s3\r\n<\/pre>\n
\u6848\u4f8b 8\uff1a\u5220\u9664\u9ed8\u8ba4\u8def\u7531<\/strong><\/div>\n

\u8981\u5220\u9664\u4e4b\u524d\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u8def\u7531\uff0c\u6253\u5f00\u7ec8\u7aef\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n

[linuxtechi@localhost]$ \u00a0sudo ip route del 192.168.0.150\/24\r\n<\/pre>\n

\u6ce8\u610f\uff1a<\/strong> \u7528\u4e0a\u9762\u65b9\u6cd5\u4fee\u6539\u7684\u9ed8\u8ba4\u8def\u7531\u53ea\u662f\u4e34\u65f6\u6709\u6548\u7684\uff0c\u5728\u7cfb\u7edf\u91cd\u542f\u540e\u6240\u6709\u7684\u6539\u52a8\u90fd\u4f1a\u4e22\u5931\u3002\u8981\u6c38\u4e45\u4fee\u6539\u8def\u7531\uff0c\u9700\u8981\u4fee\u6539\u6216\u521b\u5efa route-enp0s3<\/span> \u6587\u4ef6\u3002\u5c06\u4e0b\u9762\u8fd9\u884c\u52a0\u5165\u5176\u4e2d\uff1a<\/p>\n

[linuxtechi@localhost]$ \u00a0sudo vi \/etc\/sysconfig\/network-scripts\/route-enp0s3\r\n\r\n172.16.32.32 via 192.168.0.150\/24 dev enp0s3\r\n<\/pre>\n

\u4fdd\u5b58\u5e76\u9000\u51fa\u8be5\u6587\u4ef6\u3002<\/p>\n

\u82e5\u4f60\u4f7f\u7528\u7684\u662f\u57fa\u4e8e Ubuntu \u6216 debian \u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5219\u8be5\u8981\u4fee\u6539\u7684\u6587\u4ef6\u4e3a \/etc\/network\/interfaces<\/span>\uff0c\u7136\u540e\u6dfb\u52a0 ip route add 172.16.32.32 via 192.168.0.150\/24 dev enp0s3<\/span> \u8fd9\u884c\u5230\u6587\u4ef6\u672b\u5c3e\u3002<\/p>\n

\u6848\u4f8b 9\uff1a\u68c0\u67e5\u6240\u6709\u7684 ARP \u8bb0\u5f55<\/strong><\/div>\n

ARP\uff0c\u662f\u5730\u5740\u89e3\u6790\u534f\u8baeAddress Resolution Protocol<\/rt><\/ruby>\u7684\u7f29\u5199\uff0c\u7528\u4e8e\u5c06 IP \u5730\u5740\u8f6c\u6362\u4e3a\u7269\u7406\u5730\u5740\uff08\u4e5f\u5c31\u662f MAC \u5730\u5740\uff09\u3002\u6240\u6709\u7684 IP \u548c\u5176\u5bf9\u5e94\u7684 MAC \u660e\u7ec6\u90fd\u5b58\u50a8\u5728\u4e00\u5f20\u8868\u4e2d\uff0c\u8fd9\u5f20\u8868\u53eb\u505a ARP \u7f13\u5b58\u3002<\/p>\n

\u8981\u67e5\u770b ARP \u7f13\u5b58\u4e2d\u7684\u8bb0\u5f55\uff0c\u5373\u8fde\u63a5\u5230\u5c40\u57df\u7f51\u4e2d\u8bbe\u5907\u7684 MAC \u5730\u5740\uff0c\u5219\u4f7f\u7528\u5982\u4e0b ip \u547d\u4ee4\uff1a<\/p>\n

[linuxtechi@localhost]$ \u00a0ip neigh\r\n<\/pre>\n

\"\"<\/p>\n

ip-neigh-command-linux<\/em><\/p>\n

\u6848\u4f8b 10\uff1a\u4fee\u6539 ARP \u8bb0\u5f55<\/strong><\/div>\n

\u5220\u9664 ARP \u8bb0\u5f55\u7684\u547d\u4ee4\u4e3a\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip neigh del 192.168.0.106 dev enp0s3\r\n<\/pre>\n

\u82e5\u60f3\u5f80 ARP \u7f13\u5b58\u4e2d\u6dfb\u52a0\u65b0\u8bb0\u5f55\uff0c\u5219\u547d\u4ee4\u4e3a\uff1a<\/p>\n

[linuxtechi@localhost]$ sudo ip neigh add 192.168.0.150 lladdr 33:1g:75:37:r3:84 dev enp0s3 nud perm\r\n<\/pre>\n

\u8fd9\u91cc nud<\/span> \u7684\u610f\u601d\u662f \u201cneghbour state\u201d\uff08\u7f51\u7edc\u90bb\u5c45\u72b6\u6001\uff09\uff0c\u5b83\u7684\u503c\u53ef\u4ee5\u662f\uff1a<\/p>\n