{"id":257567,"date":"2022-12-12T09:17:08","date_gmt":"2022-12-12T01:17:08","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=257567"},"modified":"2022-11-22T12:19:45","modified_gmt":"2022-11-22T04:19:45","slug":"linux-xc-getway","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-xc-getway.html","title":{"rendered":"Linux \u4e2d\u5982\u4f55\u67e5\u8be2\u9ed8\u8ba4\u7f51\u5173"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n \u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\u6211\u4eec\u4ecb\u7ecd\u8fc7\u5982\u4f55\u67e5\u627e IP \u5730\u5740\uff0c\u4eca\u5929\u6211\u4eec\u4e86\u89e3\u4e00\u4e0b\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e2d\u67e5\u627e\u9ed8\u8ba4\u7f51\u5173\u3002 <\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u7f51\u5173\u662f\u4e24\u4e2a\u7f51\u7edc\u4e4b\u95f4\u7684\u5165\u53e3\uff0c\u8def\u7531\u5668\u5c31\u662f\u7f51\u5173\u7684\u4e00\u4e2a\u4f8b\u5b50\u3002\u4f60\u7684\u7f51\u7edc\u4e2d\u6240\u6709\u7684\u6d41\u91cf\u90fd\u662f\u6d41\u5411\u8def\u7531\u5668\uff0c\u7136\u540e\u518d\u901a\u8fc7\u8def\u7531\u5668\u6d41\u5411\u4e92\u8054\u7f51\u3002
\n\u6709\u65f6\u5019\u4f60\u9700\u8981\u77e5\u9053\u8def\u7531\u5668\u7684 IP \u5730\u5740\uff0c\u7f51\u5173 IP \u5176\u5b9e\u5c31\u662f\u6b63\u5e38\u8bbe\u7f6e\u4e2d\u8def\u7531\u5668\u7684 IP \u5730\u5740\u3002
\n\u4e0b\u9762\u6211\u4eec\u4f7f\u7528 ip \u547d\u4ee4\u5728\u547d\u4ee4\u884c\u4e2d\u663e\u793a\u7f51\u5173 IP\uff0c\u6253\u5f00\u4e00\u4e2a\u7ec8\u7aef\uff0c\u7136\u540e\u8f93\u5165\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\r\nip route\r\n<\/pre>\n

\u4f1a\u770b\u5230\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n

\r\ndefault via 192.168.0.1 dev wlp58s0 proto dhcp metric 600\r\n169.254.0.0\/16 dev wlp58s0 scope link metric 1000\r\n192.168.0.0\/24 dev wlp58s0 proto kernel scope link src 192.168.0.106 metric 600\r\n<\/pre>\n

\u4e0a\u9762\u7684\u8f93\u51fa\u4e2d\uff0c\u6ce8\u610f default \u5f00\u5934\u7684\u90a3\u4e00\u884c\uff0c\u540e\u9762\u8ddf\u7684\u5c31\u662f\u9ed8\u8ba4\u7f51\u5173 IP \u5730\u5740\u3002
\n\u6216\u8005\uff0c\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u547d\u4ee4\u4e0e grep \u7ed3\u5408\u4f7f\u7528\uff1a<\/p>\n

\r\nip route | grep default\r\n<\/pre>\n

\u8fd9\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u53ea\u4f1a\u7ed9\u51fa\u9ed8\u8ba4\u7f51\u5173 IP\uff1a<\/p>\n

\r\ndefault via 192.168.0.1 dev wlp1s0 proto dhcp metric 600\r\n<\/pre>\n

\u5982\u4e0a\u6240\u793a\uff0c192.168.0.1 \u5373\u4e3a\u6211\u4eec\u4f8b\u5b50\u4e2d\u7684\u9ed8\u8ba4\u7f51\u5173 IP\u3002<\/p>\n

\u67e5\u627e\u7f51\u5173IP\u5730\u5740\u7684\u5176\u4ed6\u65b9\u6cd5 <\/strong><\/div>\n

Linux \u4e2d\u7684 ip \u547d\u4ee4\u63d0\u4f9b\u4e86\u5927\u591a\u6570\u7f51\u7edc\u76f8\u5173\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u7528\u8fc7\u4e00\u6bb5\u65f6\u95f4\u7684 Linux \u7cfb\u7edf\uff0c\u6211\u4eec\u53ef\u80fd\u5c31\u4f1a\u6ce8\u610f\u5230\uff0c\u8981\u5b8c\u6210\u67d0\u4ef6\u4e8b\u60c5\uff0c\u4e00\u822c\u4f1a\u6709\u591a\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u6240\u4ee5\uff0c\u8981\u67e5\u770b\u9ed8\u8ba4\u7f51\u5173\uff0c\u8fd8\u6709\u5176\u4ed6\u7684\u4e00\u4e9b\u65b9\u6cd5\uff0c\u6bd4\u5982\u4f7f\u7528\u5176\u4ed6\u7f51\u7edc\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u6765\u770b\u4e00\u4e0b\u3002<\/p>\n

\u4f7f\u7528 route \u547d\u4ee4\u67e5\u8be2\u7f51\u5173\u5730\u5740 <\/strong><\/span><\/div>\n

\u6211\u4eec\u53ef\u4ee5\u5728 route \u547d\u4ee4\u4e2d\u4f7f\u7528 -n \u9009\u9879\u6765\u663e\u793a\u5305\u542b IP \u5730\u5740\u7684\u8def\u7531\u8868\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\r\nroute -n\r\n<\/pre>\n

\u8f93\u51fa\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags Metric Ref    Use Iface\r\n0.0.0.0         192.168.0.1     0.0.0.0         UG    600    0        0 wlp58s0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlp58s0\r\n192.168.0.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp58s0\r\n<\/pre>\n

\u6ce8\u610f\u5230\u5176\u4e2d\u7684 U \u548c G \u6807\u5fd7\u4e86\u5417\uff1fU \u8868\u793a\u8def\u7531\u201c\u5411\u4e0a\u201d\uff0cG \u8868\u793a\u5b83\u662f\u7f51\u5173\u3002<\/p>\n

\u4f7f\u7528 netstat \u547d\u4ee4\u67e5\u8be2\u7f51\u5173 <\/strong><\/span><\/div>\n

\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 netstat \u547d\u4ee4\u663e\u793a\u7ec4\u6210\u7f51\u5173\u7684\u8def\u7531\u8868\uff0c\u4ee5\u6b64\u6765\u83b7\u53d6\u7f51\u5173\u5730\u5740\u3002\u770b\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

\r\nnetstat -r -n\r\n<\/pre>\n

\u5176\u8f93\u51fa\u4e0e route \u547d\u4ee4\u7684\u8f93\u51fa\u76f8\u540c\uff1a<\/p>\n

\r\nKernel IP routing table\r\nDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface\r\n0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 wlp58s0\r\n169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlp58s0\r\n192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp58s0\r\n<\/pre>\n

\u53ef\u4ee5\u901a\u8fc7 G \u6807\u5fd7\u6765\u627e\u5230\u7f51\u5173\u5730\u5740\u3002\u4ee5\u4e0a\u5c31\u662f\u6211\u4eec\u672c\u6b21\u5206\u4eab\u7684\u5173\u4e8e\u83b7\u53d6\u9ed8\u8ba4\u7f51\u5173\u7684\u76f8\u5173\u5185\u5bb9\uff0c\u6b22\u8fce\u7559\u8a00\u8ba8\u8bba\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u7f51\u5173\u662f\u4e24\u4e2a\u7f51\u7edc\u4e4b\u95f4\u7684\u5165\u53e3\uff0c\u8def\u7531\u5668\u5c31\u662f\u7f51\u5173\u7684\u4e00\u4e2a\u4f8b\u5b50\u3002\u4f60\u7684\u7f51\u7edc\u4e2d\u6240\u6709\u7684\u6d41\u91cf\u90fd\u662f\u6d41\u5411\u8def\u7531\u5668\uff0c\u7136\u540e\u518d\u901a\u8fc7\u8def\u7531\u5668\u6d41\u5411\u4e92 […]<\/p>\n","protected":false},"author":643,"featured_media":257570,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-257567","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\/257567","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\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=257567"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/257567\/revisions"}],"predecessor-version":[{"id":257569,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/257567\/revisions\/257569"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/257570"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=257567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=257567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=257567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}