{"id":58760,"date":"2023-10-26T21:36:08","date_gmt":"2023-10-26T13:36:08","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=58760"},"modified":"2023-10-28T15:42:31","modified_gmt":"2023-10-28T07:42:31","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e4%b8%8a%e8%ae%be%e7%bd%ae%e7%bd%91%e7%bb%9c%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/58760.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0a\u8bbe\u7f6e\u7f51\u7edc\u63a5\u53e3"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u200b\u200b\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u914d\u7f6e\u7f51\u7edc\u63a5\u53e3\u662f\u4e00\u9879\u57fa\u7840\u4e14\u5173\u952e\u7684\u4efb\u52a1\u3002\u4ee5\u4e0b\u662f\u6b65\u9aa4\u6307\u5bfc\uff1a1.\u719f\u6089\u7f51\u7edc\u63a5\u53e3\u7684\u540d\u79f0\uff1b2.\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u914d\u7f6e\u63a5\u53e3\uff1b3.\u7f16\u8f91\u7f51\u7edc\u914d\u7f6e\u6587\u4ef6\uff1b4.\u6d4b\u8bd5\u548c\u9a8c\u8bc1\u7f51\u7edc\u8bbe\u7f6e\uff1b5.\u4e86\u89e3\u5e76\u4f7f\u7528\u9ad8\u7ea7\u7f51\u7edc\u7ba1\u7406\u5de5\u5177\u3002\u5728\u914d\u7f6e\u5f00\u59cb\uff0c\u5148\u786e\u4fdd\u4e86\u89e3\u6240\u6709\u7684\u7f51\u7edc\u63a5\u53e3\u4fe1\u606f\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u719f\u6089\u7f51\u7edc\u63a5\u53e3\u7684\u540d\u79f0<\/h2>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u786e\u5b9a\u7f51\u7edc\u63a5\u53e3\u7684\u540d\u79f0\u3002\u4f7f\u7528<strong>ip addr<\/strong>\u6216<strong>ifconfig<\/strong>\u547d\u4ee4\uff0c\u53ef\u4ee5\u67e5\u770b\u6240\u6709\u53ef\u7528\u7684\u7f51\u7edc\u63a5\u53e3\u3002\u5e38\u89c1\u7684\u63a5\u53e3\u540d\u79f0\u5982<strong>eth0<\/strong>\uff0c<strong>wlan0<\/strong>\u8868\u793a\u7b2c\u4e00\u4e2a\u6709\u7ebf\u548c\u65e0\u7ebf\u63a5\u53e3\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u914d\u7f6e\u63a5\u53e3<\/h2>\n\n\n\n<p>&nbsp;<strong>ip<\/strong>\u548c<strong>ifconfig<\/strong>\u662f\u4e24\u4e2a\u5e38\u7528\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u8981\u4e3a<strong>eth0<\/strong>\u63a5\u53e3\u914d\u7f6e\u4e00\u4e2aIP\u5730\u5740\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ip addr add 192.168.1.10\/24 dev eth0<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u4f7f\u7528<strong>ifconfig<\/strong>\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u7f16\u8f91\u7f51\u7edc\u914d\u7f6e\u6587\u4ef6<\/h2>\n\n\n\n<p>\u4e3a\u4e86\u4f7f\u7f51\u7edc\u914d\u7f6e\u6301\u4e45\u5316\uff0c\u5fc5\u987b\u7f16\u8f91\u76f8\u5173\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u5728Debian\u548cUbuntu\u7cfb\u7edf\u4e2d\uff0c\u8fd9\u662f<strong>\/etc\/network\/interfaces<\/strong>\uff1b\u800c\u5728Red Hat\u548cCentOS\u4e2d\uff0c\u5219\u662f<strong>\/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/strong>\u3002\u786e\u4fdd\u914d\u7f6e\u6b63\u786e\u5e76\u4e0e\u7f51\u7edc\u73af\u5883\u76f8\u5339\u914d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u6d4b\u8bd5\u548c\u9a8c\u8bc1\u7f51\u7edc\u8bbe\u7f6e<\/h2>\n\n\n\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u91cd\u542f\u7f51\u7edc\u670d\u52a1\u5e76\u6d4b\u8bd5\u65b0\u914d\u7f6e\u662f\u5426\u6709\u6548\u3002\u4f7f\u7528<strong>ping<\/strong>\u547d\u4ee4\u6d4b\u8bd5\u7f51\u7edc\u8fde\u901a\u6027\uff0c\u5e76\u4f7f\u7528<strong>ip addr<\/strong>\u6216<strong>ifconfig<\/strong>\u786e\u8ba4\u63a5\u53e3\u914d\u7f6e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u4e86\u89e3\u5e76\u4f7f\u7528\u9ad8\u7ea7\u7f51\u7edc\u7ba1\u7406\u5de5\u5177<\/h2>\n\n\n\n<p>\u9664\u57fa\u7840\u547d\u4ee4\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u9ad8\u7ea7\u5de5\u5177\u5982<strong>NetworkManager<\/strong>\u548c<strong>netplan<\/strong>\u53ef\u7528\u4e8e\u7ba1\u7406\u7f51\u7edc\u3002\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u56fe\u5f62\u754c\u9762\u548c\u547d\u4ee4\u884c\u754c\u9762\uff0c\u53ef\u4ee5\u66f4\u7b80\u6d01\u5730\u914d\u7f6e\u590d\u6742\u7684\u7f51\u7edc\u73af\u5883\u3002<\/p>\n\n\n\n<p>\u5728Linux\u4e2d\u8bbe\u7f6e\u7f51\u7edc\u63a5\u53e3\u53ef\u80fd\u521d\u770b\u590d\u6742\uff0c\u4f46\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5373\u53ef\u786e\u4fdd\u7f51\u7edc\u914d\u7f6e\u7684\u6b63\u786e\u6027\u3002\u540c\u65f6\uff0c\u4e86\u89e3\u7f51\u7edc\u57fa\u7840\u548c\u4f7f\u7528\u6b63\u786e\u7684\u5de5\u5177\u662f\u5173\u952e\u3002\u5728\u591a\u6b21\u914d\u7f6e\u540e\uff0c\u8fd9\u4e9b\u6b65\u9aa4\u5c06\u53d8\u5f97\u719f\u6089\uff0c\u4f7f\u7f51\u7edc\u914d\u7f6e\u4efb\u52a1\u53d8\u5f97\u7b80\u5355\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"484\" height=\"300\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u7ba1\u7406\u5b57\u4f53-29.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-58762\" \/><\/figure><\/div>\n\n\n<p><strong>\u5e38\u89c1\u95ee\u7b54\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u5728Linux\u4e0a\u8bbe\u7f6e\u7f51\u7edc\u63a5\u53e3\u7684\u65f6\u5019\uff0c\u4e3a\u4ec0\u4e48\u6211\u65e0\u6cd5\u542f\u52a8\u6216\u91cd\u65b0\u542f\u52a8\u7f51\u7edc\u670d\u52a1\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b58\u5728\u8bed\u6cd5\u9519\u8bef\u6216\u67d0\u4e9b\u53c2\u6570\u8bbe\u7f6e\u4e0d\u6b63\u786e\u3002\u4f60\u5e94\u8be5\u4f7f\u7528\u547d\u4ee4 <strong>sudo systemctl status networking.service<\/strong> \u6765\u68c0\u67e5\u670d\u52a1\u7684\u72b6\u6001\u548c\u53ef\u80fd\u7684\u9519\u8bef\u6d88\u606f\u3002\u6b64\u5916\uff0c\u68c0\u67e5 <strong>\/etc\/network\/interfaces<\/strong> \u6216\u5176\u4ed6\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6309\u7167\u6b63\u786e\u7684\u683c\u5f0f\u548c\u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u5982\u4f55\u5728Linux\u4e0a\u8bbe\u7f6e\u9759\u6001IP\u5730\u5740\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u8981\u5728Linux\u4e0a\u8bbe\u7f6e\u9759\u6001IP\u5730\u5740\uff0c\u4f60\u9700\u8981\u7f16\u8f91 <strong>\/etc\/network\/interfaces<\/strong> \u6587\u4ef6\uff0c\u5e76\u4e3a\u4f60\u7684\u7f51\u7edc\u63a5\u53e3\uff08\u5982 <strong>eth0<\/strong>\uff09\u6307\u5b9a\u9759\u6001\u7684IP\u3001\u5b50\u7f51\u63a9\u7801\u3001\u7f51\u5173\u7b49\u4fe1\u606f\u3002\u4f8b\u5982\uff1aiface eth0 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u91cd\u65b0\u542f\u52a8\u7f51\u7edc\u670d\u52a1\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u6211\u5df2\u7ecf\u66f4\u65b0\u4e86\u6211\u7684\u7f51\u7edc\u914d\u7f6e\uff0c\u4f46\u662f\u66f4\u6539\u5e76\u6ca1\u6709\u751f\u6548\uff0c\u6211\u5e94\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u4e3a\u4e86\u8ba9\u65b0\u7684\u7f51\u7edc\u914d\u7f6e\u751f\u6548\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u542f\u52a8\u7f51\u7edc\u670d\u52a1\u3002\u5728\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u4e0a\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <strong>sudo systemctl restart networking.service<\/strong> \u547d\u4ee4\u6765\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u8bf7\u786e\u4fdd\u914d\u7f6e\u6587\u4ef6\u7684\u8bed\u6cd5\u662f\u6b63\u786e\u7684\uff0c\u5e76\u4e14\u6ca1\u6709\u9057\u6f0f\u4efb\u4f55\u5fc5\u8981\u7684\u53c2\u6570\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u200b\u200b\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u914d\u7f6e\u7f51\u7edc\u63a5\u53e3\u662f\u4e00\u9879\u57fa\u7840\u4e14\u5173\u952e\u7684\u4efb\u52a1\u3002\u4ee5\u4e0b\u662f\u6b65\u9aa4\u6307\u5bfc\uff1a1.\u719f\u6089\u7f51\u7edc\u63a5\u53e3\u7684\u540d\u79f0\uff1b2.\u4f7f\u7528\u547d [&hellip;]","protected":false},"author":7,"featured_media":58763,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/58760"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=58760"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/58760\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/58763"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=58760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=58760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=58760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}