{"id":254921,"date":"2022-10-21T08:17:46","date_gmt":"2022-10-21T00:17:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=254921"},"modified":"2022-10-20T12:18:11","modified_gmt":"2022-10-20T04:18:11","slug":"linux-find-ip","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-find-ip.html","title":{"rendered":"\u5728 Linux \u547d\u4ee4\u884c\u4e2d\u67e5\u627e IP \u5730\u5740\u4ecb\u7ecd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u51e0\u5e74\u524d\uff0cifconfig \u662f Linux \u4e2d\u6700\u53d7\u6b22\u8fce\u7684\u67e5\u8be2\u672c\u673a IP \u5730\u5740\u7684\u65b9\u6cd5\u3002\u4f46\u662f\u73b0\u5982\u4eca ifconfig \u547d\u4ee4\u5df2\u7ecf\u88ab\u542f\u7528\u4e86\u3002\u5728\u67d0\u4e9b Linux \u53d1\u884c\u7248\u4e0a\u5df2\u7ecf\u4e0d\u7528\u4e86\u3002\u90a3\u4e48\uff0c\u9664\u6b64\u4ee5\u5916\u8fd8\u6709\u4ec0\u4e48\u522b\u7684\u65b9\u5f0f\u6765\u67e5\u8be2 IP \u5730\u5740\u5462\uff1f\u4eca\u5929\u6211\u4eec\u5c31\u6765\u4e86\u89e3\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5728 Linux \u547d\u4ee4\u884c\u4e2d\u67e5\u627e IP \u5730\u5740<\/strong><\/div>\n

\u73b0\u5728\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0ip\u00a0\u547d\u4ee4\u6765\u67e5\u8be2 IP \u5730\u5740\u3002ip \u547d\u4ee4\u662f\u901a\u7528\u7684\uff0c\u53ef\u4ee5\u7528\u4e8e\u7f51\u7edc\u76f8\u5173\u7684\u5176\u4ed6\u4e00\u4e9b\u4e8b\u60c5\u3002<\/p>\n

\u4e0d\u8fc7\uff0c\u8981\u663e\u793a IP \u5730\u5740\uff0c\u53ef\u4ee5\u4f7f\u7528 ip addr\uff0cip a \u6216\u8005 ip address\uff0c\u5982\u4e0b\u6240\u793a\u547d\u4ee4\uff1a<\/p>\n

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\r\nlink\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\r\ninet 127.0.0.1\/8 scope host lo\r\nvalid_lft forever preferred_lft forever\r\ninet6 ::1\/128 scope host\r\nvalid_lft forever preferred_lft forever\r\n2: wlp58s0: mtu 1500 qdisc mq state UP group default qlen 1000\r\nlink\/ether 9c:b6:d0:d0:fc:b5 brd ff:ff:ff:ff:ff:ff\r\ninet 192.168.1.20\/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp58s0\r\nvalid_lft 5962sec preferred_lft 5962sec\r\ninet6 fe80::bf14:21e3:4223:e5e4\/64 scope link noprefixroute\r\nvalid_lft forever preferred_lft forever<\/pre>\n

\u5728\u4e0a\u9762\u7684\u8f93\u51fa\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5ffd\u7565\u7b2c\u4e00\u4e2a\u540d\u4e3alo\uff08loopback\uff09\u7684\u8f93\u51fa\uff0c\u9664\u6b64\u4ee5\u5916\uff0c\u53ef\u4ee5\u770b\u5230 IP \u5730\u5740\u663e\u793a\u4e3a192.168.1.20\u3002\u5b83\u540e\u9762\u768424\u662f\u5b50\u7f51\u63a9\u7801\u3002<\/p>\n

\"\"<\/p>\n

\u5982\u4e0a\u6240\u793a\uff0c\u53ef\u4ee5\u4f7f\u7528 ip \u547d\u4ee4\u83b7\u53d6\u4e3b\u673a\u7684 IP \u5730\u5740\u3002\u9664\u6b64\u4ee5\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7 bash \u811a\u672c\u83b7\u53d6 IP \u5730\u5740\u3002<\/p>\n

\u83b7\u53d6 IP \u5730\u5740\u7684\u5176\u4ed6\u65b9\u6cd5<\/strong><\/div>\n

\u9664\u4e86\u4f7f\u7528 ip \u547d\u4ee4\u4ee5\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u7684\u51e0\u4e2a\u65b9\u6cd5\u6765\u83b7\u53d6 IP \u5730\u5740\u3002<\/p>\n

\u4f7f\u7528 hostname \u547d\u4ee4\u67e5\u770bIP\u5730\u5740<\/strong><\/div>\n

hostname \u547d\u4ee4\u901a\u5e38\u7528\u4e8e\u663e\u793a\u7cfb\u7edf\u7684\u4e3b\u673a\u540d\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u663e\u793a\u4e3b\u673a\u7684IP\u5730\u5740\uff1a<\/p>\n

hostname<\/pre>\n

\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u663e\u793a\u4e3b\u673a\u7684 IP \u5730\u5740\uff1a\u200b<\/p>\n

$ hostname -I192.168.0.106<\/pre>\n
\u4f7f\u7528 nmcli \u5de5\u5177\u663e\u793a IP \u5730\u5740<\/strong><\/div>\n

\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u90fd\u6709\u4e00\u4e2a Network Manager \u7684\u5de5\u5177\uff0c\u8be5\u5de5\u5177\u6709\u4e00\u4e2a\u540d\u4e3a nmcli \u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64 nmcli \u5de5\u5177\u6765\u67e5\u770b\u7f51\u7edc\u914d\u7f6e\u3002\u6bd4\u5982\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u67e5\u770b IP \u5730\u5740\uff1a<\/p>\n

nmcli<\/pre>\n
\u90a3\u4e48\uff0cifconfig \u5462\uff1f<\/strong><\/span><\/div>\n

\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528 ifconfig \u547d\u4ee4\u3002\u5982\u679c\u7cfb\u7edf\u4e2d\u4e0d\u5b58\u5728\u8fd9\u4e2a\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\uff0c\u5b83\u5b58\u5728\u4e8e\u7f51\u7edc\u5de5\u5177\u5305\u4e2d\u3002<\/p>\n

\u5728\u57fa\u4e8e Ubuntu \u7684 Linux \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5\u7f51\u7edc\u5de5\u5177\uff1a<\/p>\n

sudo<\/pre>\n

\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 ifconfig \u547d\u4ee4\u6765\u67e5\u8be2 IP \u5730\u5740\u4e86\uff1a<\/p>\n

ifconfig<\/pre>\n

\u8f93\u51fa\u5982\u4e0b\uff1a\u200b<\/p>\n

lo: flags=73 mtu 65536\r\ninet 127.0.0.1 netmask 255.0.0.0\r\ninet6 ::1 prefixlen 128 scopeid 0x10\r\nloop txqueuelen 1000 (Local Loopback)\r\nRX packets 14855 bytes 3027297 (3.0 MB)\r\nRX errors 0 dropped 0 overruns 0 frame 0\r\nTX packets 14855 bytes 3027297 (3.0 MB)\r\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 0\r\nwlp58s0: flags=4163 mtu 1500\r\ninet 192.168.0.106 netmask 255.255.255.0 broadcast 192.168.0.255\r\ninet6 fe80::bf14:21e3:4223:e5e4 prefixlen 64 scopeid 0x20\r\nether 9c:b6:d0:d0:fc:b5 txqueuelen 1000 (Ethernet)\r\nRX packets 88413 bytes 61851930 (61.8 MB)\r\nRX errors 0 dropped 0 overruns 0 frame 0\r\nTX packets 56505 bytes 11409219 (11.4 MB)\r\nTX errors 0 dropped 0 overruns 0 carrier 0 collisions 0<\/pre>\n

\u4e0d\u8fc7\uff0c\u56e0\u4e3a ifconfig \u547d\u4ee4\u5df2\u7ecf\u88ab\u5f03\u7528\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u4e0d\u9f13\u52b1\u4f7f\u7528\u7f51\u7edc\u5de5\u5177\uff0c\u5efa\u8bae\u4f7f\u7528 ip \u547d\u4ee4\u3002<\/p>\n

\u67e5\u8be2\u516c\u7f51IP\u5730\u5740<\/strong><\/span><\/div>\n

\u4e0a\u9762\u6211\u4eec\u4ecb\u7ecd\u7684\u90fd\u662f\u67e5\u8be2\u672c\u5730\u5185\u7f51IP\u5730\u5740\u7684\u65b9\u6cd5\uff0c\u4e5f\u5c31\u662f\u5c40\u57df\u7f51\u7684 IP \u5730\u5740\u3002<\/p>\n

\u5185\u7f51 IP \u5730\u5740\u662f\u5c40\u9650\u5728\u5c40\u57df\u7f51\u4e2d\u7684\u5730\u5740\uff0c\u7528\u4e8e\u4e0e\u5c40\u57df\u7f51\u4e2d\u7684\u5176\u4ed6\u8bbe\u5907\u8fdb\u884c\u901a\u4fe1\u3002\u5c40\u57df\u7f51\u4e4b\u5916\u7684\u5176\u4ed6\u8bbe\u5907\u65e0\u6cd5\u901a\u8fc7\u8fd9\u4e2a IP \u5730\u5740\u627e\u5230\u4f60\u3002\u6211\u4eec\u6240\u8bf4\u7684\u516c\u7f51\u5730\u5740\u4e00\u822c\u662f\u6307\u8def\u7531\u5668\u7684IP\u5730\u5740\uff0c\u8def\u7531\u5668\u901a\u8fc7\u5185\u7f51 IP \u4e0e\u4f60\u7684\u8bbe\u5907\u901a\u4fe1\u3002<\/p>\n

\u90a3\u4e48\uff0c\u5982\u4f55\u83b7\u53d6\u516c\u7f51IP\u5730\u5740\u5462\uff1f\u8fd9\u5c31\u9700\u8981\u501f\u52a9\u4e8e\u7b2c\u4e09\u65b9\u5de5\u5177\u4e86\u3002<\/p>\n

\u6bd4\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 OpenDNS \u7684 host \u547d\u4ee4\u6765\u83b7\u53d6\u516c\u7f51 IP \u5730\u5740\u3002<\/p>\n

host myip.opendns.com resolver1.opendns.com<\/pre>\n

\u5176\u8f93\u51fa\u5982\u4e0b\uff1a\u200b<\/p>\n

Using domain server:\r\nName: resolver1.opendns.com\r\nAddress: 208.67.222.222#53\r\nAliases:\r\nmyip.opendns.com has address 202.91.87.117\r\nHost myip.opendns.com not found: 3(NXDOMAIN)\r\nHost myip.opendns.com not found: 3(NXDOMAIN)<\/pre>\n

\u4ee5\u4e0a\u5c31\u662f\u672c\u6b21\u5206\u4eab\u5168\u90e8\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u73b0\u5728\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0ip\u00a0\u547d\u4ee4\u6765\u67e5\u8be2 IP \u5730\u5740\u3002ip \u547d\u4ee4\u662f\u901a\u7528\u7684\uff0c\u53ef\u4ee5\u7528\u4e8e\u7f51\u7edc\u76f8\u5173\u7684\u5176\u4ed6\u4e00\u4e9b\u4e8b\u60c5\u3002 \u4e0d\u8fc7\uff0c\u8981\u663e […]<\/p>\n","protected":false},"author":323,"featured_media":254561,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-254921","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\/254921","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\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=254921"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254921\/revisions"}],"predecessor-version":[{"id":255508,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254921\/revisions\/255508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/254561"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=254921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=254921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=254921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}