{"id":442449,"date":"2026-02-24T16:32:22","date_gmt":"2026-02-24T08:32:22","guid":{"rendered":"https:\/\/idc.net\/help\/?p=442449"},"modified":"2026-02-12T16:33:50","modified_gmt":"2026-02-12T08:33:50","slug":"ubuntu-server-%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e9%9d%99%e6%80%81-ip-%e5%9c%b0%e5%9d%80","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/442449\/","title":{"rendered":"Ubuntu Server \u5982\u4f55\u8bbe\u7f6e\u9759\u6001 IP \u5730\u5740"},"content":{"rendered":"<p dir=\"auto\">Ubuntu Server\uff08\u4ece 17.10 \u5f00\u59cb\uff0c\u5305\u62ec\u5f53\u524d\u7684 24.04 LTS Noble Numbat \u7cfb\u5217\u53ca\u540e\u7eed\u7248\u672c\uff09\u7edf\u4e00\u4f7f\u7528 <strong>Netplan<\/strong> \u4f5c\u4e3a\u7f51\u7edc\u914d\u7f6e\u5de5\u5177\u3002Netplan \u662f\u4e00\u4e2a\u58f0\u660e\u5f0f\u7684 YAML \u914d\u7f6e\u7cfb\u7edf\uff0c\u5b83\u5c06\u7f51\u7edc\u8bbe\u7f6e\u62bd\u8c61\u51fa\u6765\uff0c\u7531\u540e\u7aef\u6e32\u67d3\u5668\uff08\u901a\u5e38\u662f networkd \u6216 NetworkManager\uff09\u5b9e\u9645\u5e94\u7528\u5230\u7cfb\u7edf\u3002<\/p>\n<p dir=\"auto\">Server \u7248\u9ed8\u8ba4\u4f7f\u7528 systemd-networkd \u4f5c\u4e3a\u6e32\u67d3\u5668\uff0c\u8fd9\u4f7f\u5f97\u9759\u6001 IP \u914d\u7f6e\u975e\u5e38\u7a33\u5b9a\u3001\u53ef\u9884\u6d4b\u4e14\u9002\u5408\u65e0\u5934\u73af\u5883\u3002<\/p>\n<h2 dir=\"auto\">\u6838\u5fc3\u539f\u7406<\/h2>\n<ul dir=\"auto\">\n<li>\u914d\u7f6e\u6587\u4ef6\u7edf\u4e00\u653e\u5728 \/etc\/netplan\/ \u76ee\u5f55\u4e0b\uff0c\u540e\u7f00\u4e3a .yaml \u6216 .yml<\/li>\n<li>\u6587\u4ef6\u6309\u5b57\u6bcd\u987a\u5e8f\u52a0\u8f7d\uff0c\u540e\u52a0\u8f7d\u7684\u6587\u4ef6\u4f1a\u8986\u76d6\/\u5408\u5e76\u524d\u9762\u7684\u914d\u7f6e\uff08\u56e0\u6b64\u5e38\u4f7f\u7528 50-xxx.yaml\u300199-custom.yaml \u7b49\u547d\u540d\u6765\u63a7\u5236\u4f18\u5148\u7ea7\uff09<\/li>\n<li>\u5178\u578b\u9ed8\u8ba4\u6587\u4ef6\uff1a50-cloud-init.yaml\uff08\u4e91\u955c\u50cf\u5e38\u89c1\uff09\u6216 01-netcfg.yaml\u300100-installer-config.yaml \u7b49<\/li>\n<li>\u914d\u7f6e\u53d8\u66f4\u540e\uff0c\u5fc5\u987b\u6267\u884c netplan generate\uff08\u751f\u6210\u4e2d\u95f4\u914d\u7f6e\uff09+ netplan apply\uff08\u5e94\u7528\u5230\u7cfb\u7edf\uff09<\/li>\n<li>\u8bed\u6cd5\u4e25\u683c\uff1aYAML \u5bf9\u7f29\u8fdb\u3001\u5192\u53f7\u540e\u7a7a\u683c\u975e\u5e38\u654f\u611f\uff0c\u9519\u8bef\u4f1a\u5bfc\u81f4\u5e94\u7528\u5931\u8d25<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u8bbe\u7f6e\u9759\u6001 IP \u7684\u6807\u51c6\u6b65\u9aa4<\/h2>\n<h3 dir=\"auto\">1. \u8bc6\u522b\u7f51\u7edc\u63a5\u53e3\u540d\u79f0<\/h3>\n<p dir=\"auto\">\u5148\u67e5\u770b\u5f53\u524d\u63a5\u53e3\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>ip link show\r\n# \u6216\u66f4\u8be6\u7ec6\r\nip -c addr show<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u5e38\u89c1\u540d\u79f0\uff1a<\/p>\n<ul dir=\"auto\">\n<li>enp0s3\u3001ens33\u3001eno1\uff08\u6709\u7ebf\u4ee5\u592a\u7f51\uff09<\/li>\n<li>enp1s0\u3001eth0\uff08\u65e7\u5f0f\u547d\u540d\uff09<\/li>\n<li>wlp2s0\uff08\u65e0\u7ebf\uff0c\u4f46 Server \u901a\u5e38\u65e0 Wi-Fi\uff09<\/li>\n<\/ul>\n<p dir=\"auto\">\u8bb0\u4f4f\u4f60\u8981\u914d\u7f6e\u7684\u63a5\u53e3\u540d\uff0c\u4f8b\u5982 enp1s0\u3002<\/p>\n<h3 dir=\"auto\">2. \u5907\u4efd\u73b0\u6709\u914d\u7f6e\uff08\u5f3a\u70c8\u63a8\u8350\uff09<\/h3>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>cd \/etc\/netplan\/\r\nsudo cp *.yaml *.yaml.bak<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">3. \u7f16\u8f91\u6216\u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p dir=\"auto\">\u63a8\u8350\u521b\u5efa\u4e00\u4e2a\u9ad8\u4f18\u5148\u7ea7\u6587\u4ef6\uff08\u5982 99-static-ip.yaml\uff09\uff0c\u907f\u514d\u4fee\u6539\u9ed8\u8ba4\u6587\u4ef6\u5bfc\u81f4\u5347\u7ea7\u8986\u76d6\u3002<\/p>\n<p dir=\"auto\">\u4f7f\u7528\u7f16\u8f91\u5668\uff08nano\/vi\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code>sudo nano \/etc\/netplan\/99-static-ip.yaml<\/code><\/pre>\n<\/div>\n<div>\u5178\u578b\u9759\u6001 IP \u914d\u7f6e\u793a\u4f8b\uff08IPv4\uff09\uff1a<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>YAML<\/div>\n<div>\n<pre tabindex=\"0\"><code>network:\r\n  version: 2\r\n  renderer: networkd\r\n  ethernets:\r\n    enp1s0:                  # \u2190 \u66ff\u6362\u6210\u4f60\u7684\u5b9e\u9645\u63a5\u53e3\u540d\r\n      dhcp4: false           # \u5173\u95ed IPv4 DHCP\r\n      dhcp6: false           # \u5173\u95ed IPv6 DHCP\uff08\u82e5\u4e0d\u9700\u8981 IPv6\uff09\r\n      addresses:\r\n        - 192.168.1.100\/24   # \u4f60\u7684\u9759\u6001 IP + \u5b50\u7f51\u63a9\u7801\uff08CIDR \u8868\u793a\uff09\r\n      routes:\r\n        - to: default\r\n          via: 192.168.1.1   # \u9ed8\u8ba4\u7f51\u5173\uff08\u8def\u7531\u5668 IP\uff09\r\n      nameservers:\r\n        addresses: [8.8.8.8, 8.8.4.4]   # DNS \u670d\u52a1\u5668\uff0c\u53ef\u7528 1.1.1.1\u3001114.114.114.114 \u7b49\r\n        search: [localdomain]           # \u53ef\u9009\uff0c\u57df\u540d\u641c\u7d22\u540e\u7f00<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u66f4\u5b8c\u6574\u7684\u751f\u4ea7\u793a\u4f8b\uff08\u542b metric \u4f18\u5148\u7ea7\u3001\u5907\u7528 DNS\uff09\uff1a<\/p>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>YAML<\/div>\n<div>\n<pre tabindex=\"0\"><code>network:\r\n  version: 2\r\n  renderer: networkd\r\n  ethernets:\r\n    enp1s0:\r\n      dhcp4: false\r\n      dhcp6: false\r\n      addresses:\r\n        - 10.10.20.45\/23\r\n      routes:\r\n        - to: default\r\n          via: 10.10.20.1\r\n          metric: 100\r\n      nameservers:\r\n        addresses:\r\n          - 10.10.20.10\r\n          - 1.1.1.1\r\n          - 8.8.8.8<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 dir=\"auto\">4. \u9a8c\u8bc1 YAML \u8bed\u6cd5\u5e76\u5e94\u7528<\/h3>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code># \u5148\u6d4b\u8bd5\u751f\u6210\uff08\u4e0d\u4f1a\u5e94\u7528\uff0c\u4f46\u4f1a\u62a5\u544a\u8bed\u6cd5\u9519\u8bef\uff09\r\nsudo netplan generate\r\n\r\n# \u5982\u679c\u6ca1\u62a5\u9519\uff0c\u518d\u771f\u6b63\u5e94\u7528\r\nsudo netplan apply<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">netplan apply \u662f\u5b89\u5168\u7684\uff0c\u4e0d\u4f1a\u4e2d\u65ad\u73b0\u6709\u8fde\u63a5\uff08\u9664\u975e\u4f60\u6539\u9519\u4e86\u81ea\u5df1\u7684 IP\uff09\u3002<\/p>\n<h3 dir=\"auto\">5. \u9a8c\u8bc1\u7ed3\u679c<\/h3>\n<div dir=\"auto\">\n<div data-testid=\"code-block\">\n<div>\n<div>Bash<\/div>\n<div>\n<pre tabindex=\"0\"><code># \u67e5\u770b IP \u662f\u5426\u6b63\u786e\u7ed1\u5b9a\r\nip -c addr show enp1s0\r\n\r\n# \u6d4b\u8bd5\u8fde\u901a\u6027\r\nping 8.8.8.8\r\nping www.google.com\r\n\r\n# \u67e5\u770b\u8def\u7531\u8868\r\nip route show<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2 dir=\"auto\">\u5e38\u89c1\u95ee\u9898\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h2>\n<ul dir=\"auto\">\n<li><strong>YAML \u7f29\u8fdb\u9519\u8bef<\/strong>\uff1a\u6700\u5e38\u89c1\u5931\u8d25\u539f\u56e0\u3002\u5fc5\u987b\u7528\u7a7a\u683c\uff082 \u6216 4 \u4e2a\uff09\uff0c\u4e0d\u80fd\u7528 Tab\u3002\u5efa\u8bae\u7528 sudo netplan --debug apply \u67e5\u770b\u8be6\u7ec6\u9519\u8bef\u3002<\/li>\n<li><strong>\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u6709\u591a\u4e2a .yaml \u6587\u4ef6\uff0c\u786e\u4fdd dhcp4: true \u7684\u6587\u4ef6\u4f18\u5148\u7ea7\u4f4e\u4e8e\u4f60\u7684\u9759\u6001\u6587\u4ef6\uff0c\u6216\u76f4\u63a5\u5220\u9664\/\u6ce8\u91ca\u9ed8\u8ba4 DHCP \u914d\u7f6e\u3002<\/li>\n<li><strong>\u4e91\u73af\u5883\uff08AWS\u3001Azure\u3001GCP\u3001\u963f\u91cc\u4e91\u7b49\uff09<\/strong>\uff1a\u4e91\u521d\u59cb\u5316\uff08cloud-init\uff09\u4f1a\u8986\u76d6 Netplan\uff0c\u5efa\u8bae\u5728 \/etc\/netplan\/ \u4e0b\u521b\u5efa\u66f4\u9ad8\u4f18\u5148\u7ea7\u6587\u4ef6\uff0c\u6216\u4fee\u6539 cloud-init \u914d\u7f6e\u3002<\/li>\n<li><strong>\u65e0\u7ebf\u7f51\u7edc<\/strong>\uff1aServer \u7248\u5f88\u5c11\u7528 Wi-Fi\uff0c\u82e5\u9700\u8981\uff0c\u7528 wifis: \u6bb5\u4ee3\u66ff ethernets:\uff0c\u5e76\u6dfb\u52a0 access-points: \u914d\u7f6e SSID \u548c\u5bc6\u7801\u3002<\/li>\n<li><strong>IPv6 \u9759\u6001<\/strong>\uff1a\u7c7b\u4f3c\uff0c\u52a0 addresses: [2001:db8::123\/64] \u7b49\u3002<\/li>\n<li><strong>\u56de\u6eda<\/strong>\uff1a\u51fa\u9519\u65ad\u5f00\u8fde\u63a5\u65f6\uff0c\u901a\u8fc7\u4e91\u63a7\u5236\u53f0\u3001\u7269\u7406\u673a\u5c4f\u5e55\u6216 rescue \u6a21\u5f0f\u6062\u590d\u5907\u4efd\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<h2 dir=\"auto\">\u603b\u7ed3<\/h2>\n<p dir=\"auto\">\u5728 2026 \u5e74\u7684 Ubuntu Server \u4e2d\uff0c\u8bbe\u7f6e\u9759\u6001 IP \u5df2\u6807\u51c6\u5316\u4e3a\u201c\u7f16\u8f91 Netplan YAML \u2192 netplan apply\u201d\u4e24\u6b65\u6d41\u7a0b\u3002\u76f8\u6bd4\u65e7\u7684 \/etc\/network\/interfaces\uff0cNetplan \u66f4\u5177\u53ef\u8bfb\u6027\u3001\u53ef\u7ec4\u5408\u6027\u548c\u8de8\u53d1\u884c\u7248\u4e00\u81f4\u6027\uff0c\u5c24\u5176\u9002\u5408\u5bb9\u5668\u5316\u3001\u4e91\u539f\u751f\u548c\u81ea\u52a8\u5316\u90e8\u7f72\u73af\u5883\u3002<\/p>\n<p dir=\"auto\">\u8bb0\u4f4f\u5173\u952e\u70b9\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u63a5\u53e3\u540d\u5fc5\u987b\u51c6\u786e\uff08ip link\uff09<\/li>\n<li>dhcp4: false \u662f\u5173\u95ed\u52a8\u6001\u5206\u914d\u7684\u6838\u5fc3<\/li>\n<li>\u5e94\u7528\u524d\u5907\u4efd + \u6d4b\u8bd5\u8bed\u6cd5<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u628a DNS \u4e5f\u8bbe\u4e3a\u53ef\u9760\u7684\u516c\u5171\u670d\u52a1\u5668\u6216\u672c\u5730\u9012\u5f52 DNS<\/li>\n<\/ul>\n<p dir=\"auto\">\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4f60\u7684\u670d\u52a1\u5668\u5c31\u62e5\u6709\u4e86\u56fa\u5b9a\u3001\u53ef\u9884\u6d4b\u7684\u7f51\u7edc\u8eab\u4efd\uff0c\u9002\u5408\u8fd0\u884c Web \u670d\u52a1\u3001\u6570\u636e\u5e93\u3001NAS\u3001\u5bb9\u5668\u4e3b\u673a\u7b49\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu Server\uff08\u4ece 17.10 \u5f00\u59cb\uff0c\u5305\u62ec\u5f53\u524d\u7684 24.04 LTS Noble Numbat \u7cfb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-442449","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=442449"}],"version-history":[{"count":1,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442449\/revisions"}],"predecessor-version":[{"id":442450,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442449\/revisions\/442450"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=442449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=442449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=442449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}