{"id":255622,"date":"2022-11-03T08:37:11","date_gmt":"2022-11-03T00:37:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=255622"},"modified":"2022-10-23T09:37:47","modified_gmt":"2022-10-23T01:37:47","slug":"linux-ip-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ip-linux.html","title":{"rendered":"\u5728 Linux \u4e2d\u5982\u4f55\u4ece\u547d\u4ee4\u884c\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173\u7684 IP \u5730\u5740"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6307\u5357\u4e2d\uff0c\u6211\u4eec\u5217\u51fa\u4e86\u5728 Linux \u548c Unix \u7cfb\u7edf\u4e2d\u627e\u5230\u9ed8\u8ba4\u7f51\u5173\u7684 5 \u79cd\u4e0d\u540c\u65b9\u6cd5\uff0c\u6211\u4eec\u8fd8\u5728\u6bcf\u79cd\u65b9\u6cd5\u4e2d\u5305\u542b\u4e86\u663e\u793a\u7f51\u5173\/\u8def\u7531\u5668 IP \u5730\u5740\u7684\u793a\u4f8b\u547d\u4ee4\u3002\u5e0c\u671b\u5b83\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\"\"<\/p>\n

Free operationg system. The word \"Linux\" is lined with gold letters on wooden planks. 3D illustration graphics<\/p>\n<\/div>\n

Linux \u4e0b\u67e5\u627e\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\u7684 5 \u79cd\u65b9\u6cd5\u3002<\/p>\n

\u7f51\u5173 \u662f\u4e00\u4e2a\u8282\u70b9\u6216\u4e00\u4e2a\u8def\u7531\u5668\uff0c\u5f53\u8fde\u63a5\u5230\u540c\u4e00\u8def\u7531\u5668\u65f6\uff0c\u5b83\u5141\u8bb8\u4e24\u4e2a\u6216\u591a\u4e2a IP \u5730\u5740\u4e0d\u540c\u7684\u4e3b\u673a\u76f8\u4e92\u901a\u4fe1\u3002\u5982\u679c\u6ca1\u6709\u7f51\u5173\uff0c\u5b83\u4eec\u5c06\u65e0\u6cd5\u76f8\u4e92\u901a\u4fe1\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u7f51\u5173\u5145\u5f53\u63a5\u5165\u70b9\uff0c\u5c06\u7f51\u7edc\u6570\u636e\u4ece\u672c\u5730\u7f51\u7edc\u4f20\u8f93\u5230\u8fdc\u7a0b\u7f51\u7edc\u3002\u5728\u672c\u6307\u5357\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230\u5728 Linux \u548c Unix \u4e2d\u4ece\u547d\u4ee4\u884c\u627e\u5230\u9ed8\u8ba4\u7f51\u5173\u7684\u6240\u6709\u53ef\u80fd\u65b9\u6cd5\u3002<\/p>\n

\u5728 Linux \u4e2d\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173<\/strong><\/div>\n

Linux \u4e2d\u6709\u5404\u79cd\u5404\u6837\u7684\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u7528\u4e8e\u67e5\u770b\u7f51\u5173 IP \u5730\u5740\u3002\u6700\u5e38\u7528\u7684\u5de5\u5177\u662f\uff1a\u200b\u200bip\u200b\u200b\u200b\u3001\u200b\u200bss\u200b\u200b\u200b \u548c \u200b\u200bnetcat\u200b\u200b\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u793a\u4f8b\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u6bcf\u79cd\u5de5\u5177\u67e5\u770b\u9ed8\u8ba4\u7f51\u5173\u3002<\/p>\n

1\u3001\u4f7f\u7528 ip \u547d\u4ee4\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173<\/strong><\/span><\/div>\n

\u200b\u200bip\u200b\u200b \u547d\u4ee4\u7528\u4e8e\u663e\u793a\u548c\u64cd\u4f5c Linux \u4e2d\u7684\u8def\u7531\u3001\u7f51\u7edc\u8bbe\u5907\u3001\u63a5\u53e3\u548c\u96a7\u9053\u3002<\/p>\n

\u8981\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\uff0c\u53ea\u9700\u8fd0\u884c\uff1a<\/p>\n

$ ip route<\/pre>\n

\u6216\u8005\uff1a<\/p>\n

$ ip r\r\n<\/pre>\n

\u6216\u8005\uff1a<\/p>\n

$ ip route show\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

default via 192.168.1.101 dev eth0 proto static metric 100 172.17.0.0\/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 192.168.1.0\/24 dev eth0 proto kernel scope link src 192.168.1.20 metric 100\r\n<\/pre>\n

\u4f60\u4ece\u8f93\u51fa\u4e2d\u770b\u5230\u4e86 \u200b\u200bdefault via 192.168.1.101\u200b\u200b\u200b \u8fd9\u4e00\u884c\u5417\uff1f\u5b83\u5c31\u662f\u9ed8\u8ba4\u7f51\u5173\u3002\u6211\u7684\u9ed8\u8ba4\u7f51\u5173\u662f \u200b\u200b192.168.1.101\u200b\u200b\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528 \u200b\u200b-4\u200b\u200b\u200b \u53c2\u6570\u53ea\u200b\u200b\u663e\u793a IPv4 \u7f51\u5173\u200b\u200b\uff1a<\/p>\n

$ ip -4 route\r\n<\/pre>\n

\u6216\u8005\uff0c\u4f7f\u7528 \u200b\u200b-6\u200b\u200b \u53c2\u6570\u53ea\u663e\u793a IPv6 \u7f51\u5173\uff1a<\/p>\n

$ ip -6 route\r\n<\/pre>\n

\u5982\u4f60\u6240\u89c1\uff0cIP \u5730\u5740\u548c\u5b50\u7f51\u8be6\u7ec6\u4fe1\u606f\u4e5f\u4e00\u5e76\u663e\u793a\u4e86\u3002\u5982\u679c\u4f60\u60f3\u53ea\u663e\u793a\u9ed8\u8ba4\u7f51\u5173\uff0c\u6392\u9664\u6240\u6709\u5176\u4ed6\u7ec6\u8282\uff0c\u53ef\u4ee5\u4f7f\u7528 \u200b\u200bip route\u200b\u200b\u200b \u642d\u914d \u200b\u200bawk\u200b\u200b \u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

\u4f7f\u7528 \u200b\u200bip route\u200b\u200b\u200b \u548c \u200b\u200bawk\u200b\u200b \u547d\u4ee4\u6253\u5370\u7f51\u5173\u5730\u5740\uff0c\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n

$ ip route | awk '\/^default\/{print $3}'\r\n<\/pre>\n

\uff08LCTT \u8bd1\u6ce8\uff1awsl1 \u4e0a\u65e0\u8f93\u51fa\u7ed3\u679c\uff0c\u6b63\u5e38 Linux \u53d1\u884c\u7248\u65e0\u95ee\u9898\uff09<\/p>\n

\u6216\u8005\uff1a<\/p>\n

$ ip route show default | awk '{print $3}'\r\n<\/pre>\n

\u8fd9\u5c06\u53ea\u5217\u51fa\u7f51\u5173 IP\uff1a
\n\"\"
\n\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

192.168.1.101\r\n<\/pre>\n

\u4f7f\u7528 ip \u547d\u4ee4\u5217\u51fa\u9ed8\u8ba4\u7f51\u5173<\/p>\n

\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 \u200b\u200bgrep\u200b\u200b\u200b \u547d\u4ee4\u914d\u5408 \u200b\u200bip route\u200b\u200b \u5bf9\u9ed8\u8ba4\u7f51\u5173\u8fdb\u884c\u8fc7\u6ee4\u3002<\/p>\n

\u4f7f\u7528 \u200b\u200bip route\u200b\u200b\u200b \u548c \u200b\u200bgrep\u200b\u200b \u67e5\u627e\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740\uff0c\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n

$ ip route | grep defaultdefault via 192.168.1.101 dev eth0 proto static metric 100\r\n<\/pre>\n

\u5728\u6700\u65b0\u7684 Linux \u53d1\u884c\u7248\u4e2d\uff0c\u200b\u200bip route\u200b\u200b\u200b \u662f\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740\u7684\u63a8\u8350\u547d\u4ee4\u3002\u7136\u800c\uff0c\u4f60\u4eec\u4e2d\u7684\u4e00\u4e9b\u4eba\u53ef\u80fd\u4ecd\u7136\u5728\u4f7f\u7528\u4f20\u7edf\u7684\u5de5\u5177\uff0c\u5982 \u200b\u200broute\u200b\u200b\u200b \u548c \u200b\u200bnetstat\u200b\u200b\u200b\u3002\u65e7\u4e60\u96be\u6539\uff0c\u5bf9\u5427\uff1f\u4e0b\u9762\u7684\u90e8\u5206\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728 Linux \u4e2d\u4f7f\u7528 \u200b\u200broute\u200b\u200b\u200b \u548c \u200b\u200bnetstat\u200b\u200b \u547d\u4ee4\u786e\u5b9a\u7f51\u5173\u3002<\/p>\n

2\u3001\u4f7f\u7528 route \u547d\u4ee4\u663e\u793a\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740<\/strong><\/span><\/div>\n

\u200b\u200broute\u200b\u200b \u547d\u4ee4\u7528\u4e8e\u5728\u8f83\u8001\u7684 Linux \u53d1\u884c\u7248\u4e2d\u663e\u793a\u548c\u64cd\u4f5c\u8def\u7531\u8868\uff0c\u5982 RHEL 6\u3001CentOS 6 \u7b49\u3002<\/p>\n

\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528\u8f83\u8001\u7684 Linux \u53d1\u884c\u7248\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 \u200b\u200broute\u200b\u200b \u547d\u4ee4\u6765\u663e\u793a\u9ed8\u8ba4\u7f51\u5173\u3002<\/p>\n

\u8bf7\u6ce8\u610f\uff0c\u5728\u6700\u65b0\u7684 Linux \u53d1\u884c\u7248\u4e2d\uff0c\u200b\u200broute\u200b\u200b\u200b \u5de5\u5177\u5df2\u88ab\u5f03\u7528\uff0c\u200b\u200bip route\u200b\u200b\u200b \u547d\u4ee4\u53d6\u800c\u4ee3\u4e4b\u3002\u5982\u679c\u4f60\u56e0\u4e3a\u67d0\u4e9b\u539f\u56e0\u4ecd\u7136\u60f3\u4f7f\u7528 \u200b\u200broute\u200b\u200b\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u5b83\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u68c0\u67e5\u54ea\u4e2a\u5305\u63d0\u4f9b\u4e86 \u200b\u200broute\u200b\u200b \u547d\u4ee4\u3002\u4e3a\u6b64\uff0c\u5728\u57fa\u4e8e RHEL \u7684\u7cfb\u7edf\u4e0a\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

$ dnf provides route<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

net-tools-2.0-0.52.20160912git.el8.x86_64 : Basic networking toolsRepo        : @SystemMatched from:Filename    : \/usr\/sbin\/routenet-tools-2.0-0.52.20160912git.el8.x86_64 : Basic networking toolsRepo        : baseosMatched from:Filename    : \/usr\/sbin\/route\r\n<\/pre>\n

\u5982\u4f60\u6240\u89c1\uff0c\u200b\u200bnet-tools\u200b\u200b\u200b \u5305\u63d0\u4f9b\u4e86 \u200b\u200broute\u200b\u200b \u547d\u4ee4\u3002\u6240\u4ee5\uff0c\u8ba9\u6211\u4eec\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n

$ sudo dnf install net-tools\r\n<\/pre>\n

\u73b0\u5728\uff0c\u8fd0\u884c\u5e26\u6709 \u200b\u200b-n\u200b\u200b\u200b \u53c2\u6570\u7684 \u200b\u200broute\u200b\u200b \u547d\u4ee4\u6765\u663e\u793a Linux \u7cfb\u7edf\u4e2d\u7684\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\uff1a<\/p>\n

$ route -n\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

Kernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.1.101   0.0.0.0         UG    100    0        0 eth0172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0\r\n<\/pre>\n

\u4f7f\u7528 route \u547d\u4ee4\u663e\u793a\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740<\/p>\n

\"\"
\n\u5982\u4f60\u6240\u89c1\uff0c\u7f51\u5173 IP \u5730\u5740\u662f 192.168.1.101\u3002\u4f60\u8fd8\u5c06\u5728 Flags \u4e0b\u9762\u770b\u5230\u4e24\u4e2a\u5b57\u6bcd \u200b\u200bUG\u200b\u200b\u200b\u3002\u5b57\u6bcd \u200b\u200bU\u200b\u200b\u200b \u4ee3\u8868\u63a5\u53e3\u662f \u201cUp\u201d\uff08\u5728\u8fd0\u884c\uff09\uff0c\u200b\u200bG\u200b\u200b \u8868\u793a \u201cGateway\u201d\uff08\u7f51\u5173\uff09\u3002<\/p>\n

3\u3001\u4f7f\u7528 netstat \u547d\u4ee4\u67e5\u770b\u7f51\u5173 IP \u5730\u5740<\/strong><\/span><\/div>\n

\u200b\u200bnetstat\u200b\u200b\u200b \u4f1a\u8f93\u51fa Linux \u7f51\u7edc\u5b50\u7cfb\u7edf\u7684\u4fe1\u606f\u3002\u4f7f\u7528 \u200b\u200bnetstat\u200b\u200b \u5de5\u5177\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 Linux \u548c Unix \u7cfb\u7edf\u4e2d\u6253\u5370\u7f51\u7edc\u8fde\u63a5\u3001\u8def\u7531\u8868\u3001\u63a5\u53e3\u7edf\u8ba1\u4fe1\u606f\u3001\u4f2a\u88c5\u8fde\u63a5\u548c\u7ec4\u64ad\u6210\u5458\u5173\u7cfb\u3002<\/p>\n

\u200b\u200bnetstat\u200b\u200b\u200b \u662f \u200b\u200bnet-tools\u200b\u200b \u5305\u7684\u4e00\u90e8\u5206\uff0c\u6240\u4ee5\u786e\u4fdd\u4f60\u5df2\u7ecf\u5728 Linux \u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86\u5b83\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728\u57fa\u4e8e RHEL \u7684\u7cfb\u7edf\u4e2d\u5b89\u88c5\u5b83\uff1a<\/p>\n

$ sudo dnf install net-tools\r\n<\/pre>\n

\u4f7f\u7528 netstat \u547d\u4ee4\u6253\u5370\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740\uff1a<\/p>\n

$ netstat -rn\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

Kernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface0.0.0.0         192.168.1.101   0.0.0.0         UG        0 0          0 eth0172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 docker0192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0\r\n<\/pre>\n

\"\"
\n\u4f7f\u7528 netstat \u547d\u4ee4\u67e5\u770b\u7f51\u5173 IP \u5730\u5740<\/p>\n

\u200b\u200bnetstat\u200b\u200b\u200b \u547d\u4ee4\u4e0e \u200b\u200broute\u200b\u200b\u200b \u547d\u4ee4\u7684\u8f93\u51fa\u4fe1\u606f\u76f8\u540c\u3002\u5982\u4e0a\u8f93\u51fa\u53ef\u77e5\uff0c\u7f51\u5173\u7684 IP \u5730\u5740\u4e3a \u200b\u200b192.168.1.191\u200b\u200b\u200b\uff0c\u200b\u200bUG\u200b\u200b\u200b \u8868\u793a\u7f51\u5173\u8fde\u63a5\u7684\u7f51\u5361\u662f\u6709\u6548\u7684\uff0c\u200b\u200bG\u200b\u200b \u8868\u793a\u7f51\u5173\u3002<\/p>\n

\u8bf7\u6ce8\u610f \u200b\u200bnetstat\u200b\u200b\u200b \u4e5f\u5df2\u5f03\u7528\uff0c\u5efa\u8bae\u4f7f\u7528 \u200b\u200bss\u200b\u200b\u200b \u547d\u4ee4\u4ee3\u66ff \u200b\u200bnetstat\u200b\u200b\u3002<\/p>\n

4\u3001\u4f7f\u7528 routel \u547d\u4ee4\u6253\u5370\u9ed8\u8ba4\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740<\/strong><\/span><\/div>\n

\u200b\u200broutel\u200b\u200b\u200b \u662f\u4e00\u4e2a\u811a\u672c\uff0c\u5b83\u4ee5\u4e00\u79cd\u6f02\u4eae\u683c\u5f0f\u7684\u8f93\u51fa\u8def\u7531\u3002\u200b\u200broutel\u200b\u200b\u200b \u811a\u672c\u7684\u8f93\u51fa\u8ba9\u4e00\u4e9b\u4eba\u8ba4\u4e3a\u6bd4 \u200b\u200bip route\u200b\u200b \u5217\u8868\u66f4\u76f4\u89c2\u3002<\/p>\n

\u200b\u200broutel\u200b\u200b\u200b \u811a\u672c\u4e5f\u662f \u200b\u200bnet-tools\u200b\u200b \u5305\u7684\u4e00\u90e8\u5206\u3002<\/p>\n

\u6253\u5370\u9ed8\u8ba4\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\uff0c\u4e0d\u5e26\u4efb\u4f55\u53c2\u6570\u8fd0\u884c \u200b\u200broutel\u200b\u200b \u811a\u672c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

$ routel\r\n\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

target            gateway          source    proto    scope    dev tbl        default      192.168.1.101                   static            eth0     172.17.0.0\/ 16                      172.17.0.1   kernel     linkdocker0    192.168.1.0\/ 24                    192.168.1.20   kernel     link   eth0      127.0.0.0\/ 8            local       127.0.0.1   kernel     host     lo local      127.0.0.1              local       127.0.0.1   kernel     host     lo local127.255.255.255          broadcast       127.0.0.1   kernel     link     lo local     172.17.0.1              local      172.17.0.1   kernel     hostdocker0 local 172.17.255.255          broadcast      172.17.0.1   kernel     linkdocker0 local   192.168.1.20              local    192.168.1.20   kernel     host   eth0 local  192.168.1.255          broadcast    192.168.1.20   kernel     link   eth0 local            ::1                                      kernel              lo             ::\/ 96     unreachable                                       lo ::ffff:0.0.0.0\/ 96     unreachable                                       lo     2002:a00::\/ 24     unreachable                                       lo    2002:7f00::\/ 24     unreachable                                       lo    2002:a9fe::\/ 32     unreachable                                       lo    2002:ac10::\/ 28     unreachable                                       lo    2002:c0a8::\/ 32     unreachable                                       lo    2002:e000::\/ 19     unreachable                                       lo    3ffe:ffff::\/ 32     unreachable                                       lo         fe80::\/ 64                                   kernel            eth0             ::1              local                   kernel              lo localfe80::d085:cff:fec7:c1c3              local                   kernel            eth0 local\r\n<\/pre>\n

\"\"
\n\u4f7f\u7528 routel \u547d\u4ee4\u6253\u5370\u9ed8\u8ba4\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740<\/p>\n

\u53ea\u6253\u5370\u9ed8\u8ba4\u7f51\u5173\uff0c\u548c \u200b\u200bgrep\u200b\u200b \u547d\u4ee4\u914d\u5408\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

$ routel | grep default        default      192.168.1.101                   static            eth0\r\n<\/pre>\n
5\u3001\u4ece\u4ee5\u592a\u7f51\u914d\u7f6e\u6587\u4ef6\u4e2d\u67e5\u627e\u7f51\u5173<\/strong><\/span><\/div>\n

\u5982\u679c\u4f60\u5728 \u200b\u200bLinux \u6216 Unix \u4e2d\u914d\u7f6e\u4e86\u9759\u6001 IP \u5730\u5740\u200b\u200b\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u7f51\u7edc\u914d\u7f6e\u6587\u4ef6\u67e5\u770b\u9ed8\u8ba4\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\u3002<\/p>\n

\u5728\u57fa\u4e8e RPM \u7684\u7cfb\u7edf\u4e0a\uff0c\u5982 Fedora\u3001RHEL\u3001CentOS\u3001AlmaLinux \u548c Rocky Linux \u7b49\uff0c\u7f51\u7edc\u63a5\u53e3\u5361\u914d\u7f6e\u5b58\u50a8\u5728 \u200b\u200b\/etc\/sysconfig\/network-scripts\/\u200b\u200b \u76ee\u5f55\u4e0b\u3002<\/p>\n

\u67e5\u627e\u7f51\u5361\u7684\u540d\u79f0\uff1a<\/p>\n

# ip link show\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000    link\/ether d2:85:0c:c7:c1:c3 brd ff:ff:ff:ff:ff:ff link-netnsid 0\r\n<\/pre>\n

\u7f51\u5361\u540d\u4e3a \u200b\u200beth0\u200b\u200b\u3002\u6240\u4ee5\u8ba9\u6211\u4eec\u6253\u5f00\u8fd9\u4e2a\u7f51\u5361\u6587\u4ef6\u7684\u7f51\u5361\u914d\u7f6e\uff1a<\/p>\n

# cat \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

DEVICE=eth0ONBOOT=yesUUID=eb6b6a7c-37f5-11ed-a59a-a0e70bdf3dfbBOOTPROTO=noneIPADDR=192.168.1.20NETMASK=255.255.255.0GATEWAY=192.168.1.101DNS1=8.8.8.8\r\n<\/pre>\n

\u5982\u4f60\u6240\u89c1\uff0c\u7f51\u5173 IP \u4e3a \u200b\u200b192.168.1.101\u200b\u200b\u3002<\/p>\n

\u5728 Debian\u3001Ubuntu \u53ca\u5176\u884d\u751f\u7248\u4e2d\uff0c\u6240\u6709\u7684\u7f51\u7edc\u914d\u7f6e\u6587\u4ef6\u90fd\u5b58\u50a8\u5728 \u200b\u200b\/etc\/network\u200b\u200b \u76ee\u5f55\u4e0b\u3002<\/p>\n

$ cat \/etc\/network\/interfaces\r\n<\/pre>\n

\u793a\u4f8b\u8f93\u51fa\uff1a<\/p>\n

auto ens18iface ens18 inet static        address 192.168.1.150        netmask 255.255.255.0        gateway 192.168.1.101        dns-nameservers 8.8.8.8\r\n<\/pre>\n

\u8bf7\u6ce8\u610f\uff0c\u6b64\u65b9\u6cd5\u4ec5\u5728\u624b\u52a8\u914d\u7f6e IP \u5730\u5740\u65f6\u6709\u6548\u3002\u5bf9\u4e8e\u542f\u7528 DHCP \u7684\u7f51\u7edc\uff0c\u9700\u8981\u6309\u7167\u524d\u9762\u7684 4 \u79cd\u65b9\u6cd5\u64cd\u4f5c\u3002<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u5728\u672c\u6307\u5357\u4e2d\uff0c\u6211\u4eec\u5217\u51fa\u4e86\u5728 Linux \u548c Unix \u7cfb\u7edf\u4e2d\u627e\u5230\u9ed8\u8ba4\u7f51\u5173\u7684 5 \u79cd\u4e0d\u540c\u65b9\u6cd5\uff0c\u6211\u4eec\u8fd8\u5728\u6bcf\u79cd\u65b9\u6cd5\u4e2d\u5305\u542b\u4e86\u663e\u793a\u7f51\u5173\/\u8def\u7531\u5668 IP \u5730\u5740\u7684\u793a\u4f8b\u547d\u4ee4\u3002\u5e0c\u671b\u5b83\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Linux \u4e0b\u67e5\u627e\u7f51\u5173\u6216\u8def\u7531\u5668 IP \u5730\u5740\u7684 5 \u79cd\u65b9\u6cd5\u3002 \u7f51\u5173 \u662f\u4e00\u4e2a\u8282\u70b9\u6216\u4e00\u4e2a\u8def\u7531\u5668\uff0c\u5f53\u8fde\u63a5\u5230\u540c\u4e00\u8def\u7531\u5668\u65f6 […]<\/p>\n","protected":false},"author":1469,"featured_media":255626,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-255622","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\/255622","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\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=255622"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/255622\/revisions"}],"predecessor-version":[{"id":255642,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/255622\/revisions\/255642"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/255626"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=255622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=255622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=255622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}