{"id":51747,"date":"2024-10-08T21:13:20","date_gmt":"2024-10-08T13:13:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51747\/"},"modified":"2024-11-14T10:41:58","modified_gmt":"2024-11-14T02:41:58","slug":"ubuntu-18-04-%e4%bf%ae%e6%94%b9-hosts-%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51747\/","title":{"rendered":"Ubuntu 18.04 \u4fee\u6539 hosts \u65b9\u6cd5"},"content":{"rendered":"<h1 id=\"ubuntu-18-04-%e4%bf%ae%e6%94%b9-hosts-%e6%96%b9%e6%b3%95-TTsOQcQWQX\">Ubuntu 18.04 \u4fee\u6539 hosts \u65b9\u6cd5<\/h1>\n<p>\u5728\u4f7f\u7528 Ubuntu 18.04 \u7cfb\u7d71\u6642\uff0c\u4fee\u6539 hosts \u6a94\u6848\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\u3002\u9019\u500b\u6a94\u6848\u4e3b\u8981\u7528\u65bc\u5c07\u4e3b\u6a5f\u540d\u7a31\u6620\u5c04\u5230 IP \u5730\u5740\uff0c\u5c0d\u65bc\u7db2\u7d61\u914d\u7f6e\u3001\u958b\u767c\u74b0\u5883\u7684\u8a2d\u7f6e\u4ee5\u53ca\u6e2c\u8a66\u7db2\u7ad9\u7b49\u60c5\u6cc1\u90fd\u975e\u5e38\u91cd\u8981\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu 18.04 \u4e2d\u4fee\u6539 hosts \u6a94\u6848\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-hosts-%e6%aa%94%e6%a1%88%ef%bc%9f-TTsOQcQWQX\">\u4ec0\u9ebc\u662f hosts \u6a94\u6848\uff1f<\/h2>\n<p>hosts \u6a94\u6848\u662f\u4e00\u500b\u6587\u672c\u6a94\u6848\uff0c\u4f4d\u65bc\u7cfb\u7d71\u7684 \/etc \u76ee\u9304\u4e0b\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c07\u4e3b\u6a5f\u540d\u7a31\u89e3\u6790\u70ba IP \u5730\u5740\uff0c\u9019\u5728 DNS \u670d\u52d9\u5668\u4e0d\u53ef\u7528\u6216\u9700\u8981\u9032\u884c\u672c\u5730\u6e2c\u8a66\u6642\u7279\u5225\u6709\u7528\u3002\u6bcf\u4e00\u884c\u901a\u5e38\u5305\u542b\u4e00\u500b IP \u5730\u5740\u548c\u4e00\u500b\u6216\u591a\u500b\u4e3b\u6a5f\u540d\u7a31\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code>127.0.0.1   localhost\n192.168.1.1   myserver.local\n<\/code><\/pre>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9-hosts-%e6%aa%94%e6%a1%88-TTsOQcQWQX\">\u5982\u4f55\u4fee\u6539 hosts \u6a94\u6848<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4fee\u6539 Ubuntu 18.04 \u4e2d hosts \u6a94\u6848\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-1%ef%bc%9a%e6%89%93%e9%96%8b%e7%b5%82%e7%ab%af-TTsOQcQWQX\">\u6b65\u9a5f 1\uff1a\u6253\u958b\u7d42\u7aef<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u6253\u958b\u7d42\u7aef\u3002\u53ef\u4ee5\u901a\u904e\u6309\u4e0b <code>Ctrl + Alt + T<\/code> \u9375\u4f86\u5feb\u901f\u6253\u958b\u7d42\u7aef\u7a97\u53e3\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-2%ef%bc%9a%e4%bd%bf%e7%94%a8%e6%96%87%e6%9c%ac%e7%b7%a8%e8%bc%af%e5%99%a8%e6%89%93%e9%96%8b-hosts-%e6%aa%94%e6%a1%88-TTsOQcQWQX\">\u6b65\u9a5f 2\uff1a\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b hosts \u6a94\u6848<\/h3>\n<p>\u5728\u7d42\u7aef\u4e2d\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u5177\u6709\u7ba1\u7406\u6b0a\u9650\u7684\u6587\u672c\u7de8\u8f2f\u5668\u4f86\u6253\u958b hosts \u6a94\u6848\u3002\u9019\u88e1\u4ee5 nano \u7de8\u8f2f\u5668\u70ba\u4f8b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo nano \/etc\/hosts\n<\/code><\/pre>\n<p>\u7cfb\u7d71\u6703\u8981\u6c42\u60a8\u8f38\u5165\u5bc6\u78bc\uff0c\u8acb\u8f38\u5165\u60a8\u7684\u7528\u6236\u5bc6\u78bc\u4ee5\u7372\u53d6\u7ba1\u7406\u6b0a\u9650\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-3%ef%bc%9a%e7%b7%a8%e8%bc%af-hosts-%e6%aa%94%e6%a1%88-TTsOQcQWQX\">\u6b65\u9a5f 3\uff1a\u7de8\u8f2f hosts \u6a94\u6848<\/h3>\n<p>\u5728 nano \u7de8\u8f2f\u5668\u4e2d\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u76ee\u524d\u7684 hosts \u6a94\u6848\u5167\u5bb9\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u8981\u6dfb\u52a0\u6216\u4fee\u6539\u689d\u76ee\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u5c07\u4e00\u500b\u65b0\u7684\u4e3b\u6a5f\u540d\u7a31\u6620\u5c04\u5230\u7279\u5b9a\u7684 IP \u5730\u5740\uff0c\u53ef\u4ee5\u5728\u6a94\u6848\u7684\u672b\u5c3e\u6dfb\u52a0\u4e00\u884c\uff1a<\/p>\n<pre><code>192.168.1.100   mynewsite.local\n<\/code><\/pre>\n<p>\u5b8c\u6210\u7de8\u8f2f\u5f8c\uff0c\u6309\u4e0b <code>Ctrl + O<\/code> \u4fdd\u5b58\u66f4\u6539\uff0c\u7136\u5f8c\u6309 <code>Ctrl + X<\/code> \u9000\u51fa\u7de8\u8f2f\u5668\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f-4%ef%bc%9a%e6%aa%a2%e6%9f%a5%e6%9b%b4%e6%94%b9-TTsOQcQWQX\">\u6b65\u9a5f 4\uff1a\u6aa2\u67e5\u66f4\u6539<\/h3>\n<p>\u70ba\u4e86\u78ba\u4fdd\u60a8\u7684\u66f4\u6539\u5df2\u6210\u529f\u61c9\u7528\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\u4e3b\u6a5f\u540d\u7a31\u662f\u5426\u6b63\u78ba\u89e3\u6790\uff1a<\/p>\n<pre><code>ping mynewsite.local\n<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u770b\u5230\u6b63\u78ba\u7684 IP \u5730\u5740\u97ff\u61c9\uff0c\u5247\u8868\u793a\u4fee\u6539\u6210\u529f\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-TTsOQcQWQX\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<ul>\n<li>\u5728\u7de8\u8f2f hosts \u6a94\u6848\u6642\uff0c\u8acb\u78ba\u4fdd\u4e0d\u522a\u9664\u6216\u4fee\u6539\u73fe\u6709\u7684\u7cfb\u7d71\u689d\u76ee\uff0c\u7279\u5225\u662f localhost \u7684\u689d\u76ee\u3002<\/li>\n<li>\u4fee\u6539 hosts \u6a94\u6848\u5f8c\uff0c\u67d0\u4e9b\u61c9\u7528\u7a0b\u5e8f\u53ef\u80fd\u9700\u8981\u91cd\u65b0\u555f\u52d5\u624d\u80fd\u8b58\u5225\u66f4\u6539\u3002<\/li>\n<li>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u7db2\u7d61\u7ba1\u7406\u5de5\u5177\uff0c\u8acb\u78ba\u4fdd\u9019\u4e9b\u5de5\u5177\u4e0d\u6703\u8986\u84cb\u60a8\u7684\u624b\u52d5\u66f4\u6539\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-TTsOQcQWQX\">\u7e3d\u7d50<\/h2>\n<p>\u4fee\u6539 Ubuntu 18.04 \u7684 hosts \u6a94\u6848\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u5f0f\u4f86\u7ba1\u7406\u4e3b\u6a5f\u540d\u7a31\u548c IP \u5730\u5740\u7684\u6620\u5c04\u3002\u7121\u8ad6\u662f\u7528\u65bc\u958b\u767c\u74b0\u5883\u9084\u662f\u6e2c\u8a66\u7db2\u7ad9\uff0c\u6b63\u78ba\u7684\u914d\u7f6e\u90fd\u80fd\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u670d\u52d9\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u4f86\u652f\u6301\u60a8\u7684\u9700\u6c42\u3002\u900f\u904e <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u670d\u52a1\u5668<\/a>\uff0c\u60a8\u53ef\u4ee5\u7372\u5f97\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u914d\u7f6e\u9078\u9805\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to modify the hosts file in Ubuntu 18.04 to manage hostname resolution and improve network configuration easily.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51747","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51747"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51747\/revisions"}],"predecessor-version":[{"id":51748,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51747\/revisions\/51748"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}