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>\n5\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}]}}