{"id":42776,"date":"2024-10-04T03:21:33","date_gmt":"2024-10-03T19:21:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/42776\/"},"modified":"2024-10-04T03:21:33","modified_gmt":"2024-10-03T19:21:33","slug":"centos-7-%e9%83%a8%e7%bd%b2-dns-%e4%bc%ba%e6%9c%8d%e5%99%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/42776\/","title":{"rendered":"CentOS 7 \u90e8\u7f72 DNS \u4f3a\u670d\u5668"},"content":{"rendered":"<h1 id=\"centos-7-%e9%83%a8%e7%bd%b2-dns-%e4%bc%ba%e6%9c%8d%e5%99%a8-IFEHIcydAO\">CentOS 7 \u90e8\u7f72 DNS \u4f3a\u670d\u5668<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cDNS\uff08\u57df\u540d\u7cfb\u7d71\uff09\u4f3a\u670d\u5668\u626e\u6f14\u8457\u81f3\u95dc\u91cd\u8981\u7684\u89d2\u8272\u3002\u5b83\u8ca0\u8cac\u5c07\u57df\u540d\u8f49\u63db\u70baIP\u5730\u5740\uff0c\u5f9e\u800c\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u8f15\u9b06\u8a2a\u554f\u7db2\u7ad9\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7 \u4e0a\u90e8\u7f72\u4e00\u500b\u57fa\u672c\u7684 DNS \u4f3a\u670d\u5668\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-IFEHIcydAO\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u60a8\u5df2\u7d93\u64c1\u6709\u4e00\u53f0\u904b\u884c CentOS 7 \u7684\u4f3a\u670d\u5668\uff0c\u4e26\u4e14\u64c1\u6709 root \u6b0a\u9650\u3002\u60a8\u9084\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u5fc5\u8981\u7684\u8edf\u4ef6\u5305\uff0c\u5305\u62ec BIND\uff08Berkeley Internet Name Domain\uff09\uff0c\u9019\u662f\u6700\u5e38\u7528\u7684 DNS \u4f3a\u670d\u5668\u8edf\u4ef6\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-bind-IFEHIcydAO\">\u5b89\u88dd BIND<\/h2>\n<p>\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u60a8\u7684\u7cfb\u7d71\uff1a<\/p>\n<pre><code>yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd BIND \u53ca\u5176\u76f8\u95dc\u5de5\u5177\uff1a<\/p>\n<pre><code>yum install bind bind-utils -y<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-bind-IFEHIcydAO\">\u914d\u7f6e BIND<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u914d\u7f6e BIND\u3002\u9996\u5148\uff0c\u7de8\u8f2f\u4e3b\u914d\u7f6e\u6587\u4ef6 \/etc\/named.conf\uff1a<\/p>\n<pre><code>vi \/etc\/named.conf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\uff0c\u60a8\u9700\u8981\u8a2d\u7f6e\u4ee5\u4e0b\u5e7e\u500b\u90e8\u5206\uff1a<\/p>\n<ul>\n<li><strong>\u5141\u8a31\u7684\u67e5\u8a62\uff1a<\/strong>\u78ba\u4fdd\u60a8\u7684\u4f3a\u670d\u5668\u53ef\u4ee5\u63a5\u6536\u4f86\u81ea\u7279\u5b9a IP \u7684\u67e5\u8a62\u3002<\/li>\n<li><strong>\u5340\u57df\u8a2d\u7f6e\uff1a<\/strong>\u5b9a\u7fa9\u60a8\u7684\u57df\u540d\u548c\u76f8\u61c9\u7684 DNS \u8a18\u9304\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>options {\n    listen-on port 53 { any; };\n    listen-on-v6 { any; };\n    directory       \"\/var\/named\";\n    dump-file       \"\/var\/named\/data\/cache_dump.db\";\n    statistics-file \"\/var\/named\/data\/named_stats.txt\";\n    memstatistics-file \"\/var\/named\/data\/named_mem_stats.txt\";\n    allow-query     { any; };\n};\n\nzone \"example.com\" IN {\n    type master;\n    file \"example.com.db\";\n};<\/code><\/pre>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e5%8d%80%e5%9f%9f%e6%96%87%e4%bb%b6-IFEHIcydAO\">\u5275\u5efa\u5340\u57df\u6587\u4ef6<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u5340\u57df\u6587\u4ef6\u4f86\u5b9a\u7fa9 DNS \u8a18\u9304\u3002\u9996\u5148\uff0c\u8907\u88fd\u4e00\u500b\u7bc4\u672c\u6587\u4ef6\uff1a<\/p>\n<pre><code>cp \/var\/named\/named.empty \/var\/named\/example.com.db<\/code><\/pre>\n<p>\u7136\u5f8c\u7de8\u8f2f\u8a72\u6587\u4ef6\uff1a<\/p>\n<pre><code>vi \/var\/named\/example.com.db<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>$TTL 86400\n@   IN  SOA     ns.example.com. admin.example.com. (\n            2023101001 ; Serial\n            3600       ; Refresh\n            1800       ; Retry\n            604800     ; Expire\n            86400 )    ; Negative Cache TTL\n\n; Name servers\n@   IN  NS      ns.example.com.\n\n; A records\nns  IN  A       192.0.2.1\n@   IN  A       192.0.2.1\nwww IN  A       192.0.2.1<\/code><\/pre>\n<p>\u8acb\u6839\u64da\u60a8\u7684\u5be6\u969b\u60c5\u6cc1\u66ff\u63db IP \u5730\u5740\u548c\u57df\u540d\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95-bind-%e6%9c%8d%e5%8b%99-IFEHIcydAO\">\u555f\u52d5 BIND \u670d\u52d9<\/h2>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u60a8\u53ef\u4ee5\u555f\u52d5 BIND \u670d\u52d9\u4e26\u8a2d\u7f6e\u5176\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>systemctl start named\nsystemctl enable named<\/code><\/pre>\n<h2 id=\"%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-IFEHIcydAO\">\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u78ba\u4fdd\u9632\u706b\u7246\u5141\u8a31 DNS \u6d41\u91cf\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u958b\u653e 53 \u7aef\u53e3\uff1a<\/p>\n<pre><code>firewall-cmd --permanent --add-service=dns\nfirewall-cmd --reload<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-dns-%e4%bc%ba%e6%9c%8d%e5%99%a8-IFEHIcydAO\">\u6e2c\u8a66 DNS \u4f3a\u670d\u5668<\/h2>\n<p>\u6700\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e2c\u8a66\u60a8\u7684 DNS \u4f3a\u670d\u5668\u662f\u5426\u6b63\u5e38\u904b\u884c\uff1a<\/p>\n<pre><code>dig @localhost example.com<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u770b\u5230\u76f8\u61c9\u7684 DNS \u8a18\u9304\u8fd4\u56de\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-IFEHIcydAO\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 7 \u4e0a\u90e8\u7f72\u4e00\u500b\u57fa\u672c\u7684 DNS \u4f3a\u670d\u5668\u3002\u901a\u904e\u5b89\u88dd BIND\u3001\u914d\u7f6e\u5340\u57df\u6587\u4ef6\u4ee5\u53ca\u8a2d\u7f6e\u9632\u706b\u7246\uff0c\u60a8\u53ef\u4ee5\u8f15\u9b06\u5730\u642d\u5efa\u81ea\u5df1\u7684 DNS \u4f3a\u670d\u5668\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u7db2\u7d61\u670d\u52d9\u7684\u7528\u6236\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u7121\u8ad6\u662f\u4f01\u696d\u9084\u662f\u500b\u4eba\u7528\u6236\uff0c\u64c1\u6709\u4e00\u500b\u53ef\u9760\u7684 DNS \u4f3a\u670d\u5668\u90fd\u80fd\u63d0\u5347\u7db2\u7d61\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 CentOS 7 \u4e0a\u90e8\u7f72 DNS \u4f3a\u670d\u5668\uff0c\u6b65\u9a5f\u7c21\u55ae\u660e\u77ad\uff0c\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u57df\u540d\u89e3\u6790\u3002<\/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-42776","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42776","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=42776"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42776\/revisions"}],"predecessor-version":[{"id":42777,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42776\/revisions\/42777"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=42776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=42776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=42776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}