{"id":97682,"date":"2024-06-06T14:41:13","date_gmt":"2024-06-06T06:41:13","guid":{"rendered":"https:\/\/gulass.cn\/?p=97682"},"modified":"2024-06-06T14:41:13","modified_gmt":"2024-06-06T06:41:13","slug":"share-dnsmasq-skill","status":"publish","type":"post","link":"https:\/\/gulass.cn\/share-dnsmasq-skill.html","title":{"rendered":"\u8fd0\u7ef4\u5206\u4eab\u4e4bDnsmasq \u8fdb\u9636\u6280\u5de7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8bb8\u591a\u4eba\u719f\u77e5\u5e76\u70ed\u7231 Dnsmasq\uff0c\u5e76\u5728\u4ed6\u4eec\u7684\u672c\u5730\u57df\u540d\u670d\u52a1\u4e0a\u4f7f\u7528\u5b83\u3002\u4eca\u5929\u6211\u4eec\u5c06\u4ecb\u7ecd\u8fdb\u9636\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406\u3001\u5982\u4f55\u6d4b\u8bd5\u4f60\u7684\u914d\u7f6e\u3001\u4e00\u4e9b\u57fa\u7840\u7684\u5b89\u5168\u77e5\u8bc6\u3001DNS \u6cdb\u57df\u540d\u3001\u5feb\u901f DNS \u914d\u7f6e\uff0c\u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u6280\u5de7\u4e0e\u7a8d\u95e8\u3002\u4e0b\u4e2a\u661f\u671f\u6211\u4eec\u5c06\u7ee7\u7eed\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u914d\u7f6e DNS \u548c DHCP\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u6d4b\u8bd5\u914d\u7f6e<\/strong><\/div>\n

\n\u5f53\u4f60\u6d4b\u8bd5\u65b0\u7684\u914d\u7f6e\u7684\u65f6\u5019\uff0c\u4f60\u5e94\u8be5\u4ece\u547d\u4ee4\u884c\u8fd0\u884c Dnsmasq\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5b88\u62a4\u8fdb\u7a0b\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u6f14\u793a\u4e86\u5982\u4f55\u4e0d\u7528\u5b88\u62a4\u8fdb\u7a0b\u8fd0\u884c\u5b83\uff0c\u540c\u65f6\u663e\u793a\u6307\u4ee4\u7684\u8f93\u51fa\u5e76\u4fdd\u7559\u8fd0\u884c\u65e5\u5fd7\uff1a<\/p>\n

\r\n# dnsmasq --no-daemon --log-queries\r\ndnsmasq: started, version 2.75 cachesize 150\r\ndnsmasq: compile time options: IPv6 GNU-getopt\r\n DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack\r\n ipset auth DNSSEC loop-detect inotify\r\ndnsmasq: reading \/etc\/resolv.conf\r\ndnsmasq: using nameserver 192.168.0.1#53\r\ndnsmasq: read \/etc\/hosts - 9 addresses<\/pre>\n

\u5728\u8fd9\u4e2a\u5c0f\u4f8b\u5b50\u4e2d\u4f60\u80fd\u770b\u5230\u8bb8\u591a\u6709\u7528\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u7248\u672c\u3001\u7f16\u8bd1\u53c2\u6570\u3001\u7cfb\u7edf\u540d\u5b57\u670d\u52a1\u6587\u4ef6\uff0c\u4ee5\u53ca\u5b83\u7684\u76d1\u542c\u5730\u5740\u3002\u53ef\u4ee5\u4f7f\u7528 Ctrl+C \u505c\u6b62\u8fdb\u7a0b\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cDnsmasq \u6ca1\u6709\u81ea\u5df1\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u6240\u4ee5\u65e5\u5fd7\u4f1a\u88ab\u8bb0\u5f55\u5230 \/var\/log \u76ee\u5f55\u4e0b\u7684\u591a\u4e2a\u5730\u65b9\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u7ecf\u5178\u7684 grep \u6765\u627e\u5230 Dnsmasq \u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u4e0b\u9762\u8fd9\u6761\u6307\u4ee4\u4f1a\u9012\u5f52\u5f0f\u5730\u641c\u7d22 \/var\/log\uff0c\u5728\u6bcf\u4e2a\u5339\u914d\u7684\u6587\u4ef6\u540d\u4e4b\u540e\u663e\u793a\u5339\u914d\u7684\u884c\u53f7\uff0c\u5e76\u5ffd\u7565 \/var\/log\/dist-upgrade \u91cc\u7684\u5185\u5bb9\uff1a<\/p>\n

# grep -ir --exclude-dir=dist-upgrade dnsmasq \/var\/log\/<\/pre>\n

\u4f7f\u7528 grep --exclude-dir= \u65f6\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u5c0f\u9677\u9631\u9700\u8981\u6ce8\u610f\uff1a\u4e0d\u8981\u4f7f\u7528\u5b8c\u6574\u8def\u5f84\uff0c\u800c\u5e94\u8be5\u53ea\u5199\u76ee\u5f55\u540d\u79f0\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u7684\u547d\u4ee4\u884c\u53c2\u6570\u6765\u8ba9 Dnsmasq \u4f7f\u7528\u4f60\u6307\u5b9a\u7684\u6587\u4ef6\u4f5c\u4e3a\u5b83\u4e13\u5c5e\u7684\u65e5\u5fd7\u6587\u4ef6\uff1a<\/p>\n

# dnsmasq --no-daemon --log-queries --log-facility=\/var\/log\/dnsmasq.log<\/pre>\n

\u6216\u8005\u5728\u4f60\u7684 Dnsmasq \u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u4e0a log-facility=\/var\/log\/dnsmasq.log\u3002<\/p>\n

\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n

\nDnsmasq \u7684\u914d\u7f6e\u6587\u4ef6\u4f4d\u4e8e \/etc\/dnsmasq.conf\u3002\u4f60\u7684 Linux \u53d1\u884c\u7248\u4e5f\u53ef\u80fd\u4f1a\u4f7f\u7528 \/etc\/default\/dnsmasq\u3001\/etc\/dnsmasq.d\/\uff0c\u6216\u8005 \/etc\/dnsmasq.d-available\/\uff08\u4e0d\uff0c\u6211\u4eec\u4e0d\u80fd\u7edf\u4e00\u6807\u51c6\uff0c\u56e0\u4e3a\u8fd9\u8fdd\u53cd\u4e86 Linux \u4e03\u5634\u516b\u820c\u79d8\u5bc6\u8bae\u4f1aLinux Cat Herd Ruling Cabal\u7684\u65e8\u610f\uff09\u3002\u4f60\u6709\u5f88\u591a\u81ea\u7531\u6765\u968f\u610f\u5b89\u7f6e\u4f60\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n

\/etc\/dnsmasq.conf \u662f\u5fb7\u9ad8\u671b\u91cd\u7684\u8001\u5927\u3002Dnsmasq \u5728\u542f\u52a8\u65f6\u4f1a\u6700\u5148\u8bfb\u53d6\u5b83\u3002\/etc\/dnsmasq.conf \u53ef\u4ee5\u4f7f\u7528 conf-file= \u9009\u9879\u6765\u8c03\u7528\u5176\u4ed6\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982 conf-file=\/etc\/dnsmasqextrastuff.conf\uff0c\u6216\u4f7f\u7528 conf-dir= \u9009\u9879\u6765\u8c03\u7528\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\uff0c\u4f8b\u5982 conf-dir=\/etc\/dnsmasq.d\u3002<\/p>\n

\u6bcf\u5f53\u4f60\u5bf9\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u4f60\u90fd\u5fc5\u987b\u91cd\u542f Dnsmasq\u3002<\/p>\n

\u4f60\u4e5f\u53ef\u4ee5\u6839\u636e\u6269\u5c55\u540d\u6765\u5305\u542b\u6216\u5ffd\u7565\u914d\u7f6e\u6587\u4ef6\u3002\u661f\u53f7\u8868\u793a\u5305\u542b\uff0c\u4e0d\u52a0\u661f\u53f7\u8868\u793a\u6392\u9664\uff1a<\/p>\n

\r\nconf-dir=\/etc\/dnsmasq.d\/, *.conf, *.foo\r\nconf-dir=\/etc\/dnsmasq.d, .old, .bak, .tmp<\/pre>\n

\u4f60\u53ef\u4ee5\u7528 --addn-hosts= \u9009\u9879\u6765\u628a\u4f60\u7684\u4e3b\u673a\u914d\u7f6e\u5206\u5e03\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\u3002<\/p>\n

Dnsmasq \u5305\u542b\u4e86\u4e00\u4e2a\u8bed\u6cd5\u68c0\u67e5\u5668\uff1a<\/p>\n

\r\n$ dnsmasq --test\r\ndnsmasq: syntax check OK.<\/pre>\n<\/p>\n
\u5b9e\u7528\u914d\u7f6e<\/strong><\/div>\n

\u6c38\u8fdc\u52a0\u5165\u8fd9\u51e0\u884c\uff1a<\/p>\n

\r\ndomain-needed\r\nbogus-priv<\/pre>\n
\r\n\u5b83\u4eec\u53ef\u4ee5\u907f\u514d\u542b\u6709\u683c\u5f0f\u51fa\u9519\u7684\u57df\u540d\u6216\u79c1\u6709 IP \u5730\u5740\u7684\u6570\u636e\u5305\u79bb\u5f00\u4f60\u7684\u7f51\u7edc\u3002\r\n\r\n\u8ba9\u4f60\u7684\u540d\u5b57\u670d\u52a1\u53ea\u4f7f\u7528 Dnsmasq\uff0c\u800c\u4e0d\u53bb\u4f7f\u7528 \/etc\/resolv.conf \u6216\u4efb\u4f55\u5176\u4ed6\u7684\u540d\u5b57\u670d\u52a1\u6587\u4ef6\uff1a\r\n\r\nno-resolv\r\n\u4f7f\u7528\u5176\u4ed6\u7684\u57df\u540d\u670d\u52a1\u5668\u3002\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u662f\u53ea\u5bf9\u4e8e\u67d0\u4e00\u4e2a\u57df\u540d\u4f7f\u7528\u4e0d\u540c\u7684\u57df\u540d\u670d\u52a1\u5668\u3002\u7b2c\u4e8c\u4e2a\u548c\u7b2c\u4e09\u4e2a\u4f8b\u5b50\u662f OpenDNS \u516c\u7528\u670d\u52a1\u5668\uff1a\r\n<\/pre>\n
\r\nserver=\/fooxample.com\/192.168.0.1\r\nserver=208.67.222.222\r\nserver=208.67.220.220<\/pre>\n

\u4f60\u4e5f\u53ef\u4ee5\u5c06\u67d0\u4e9b\u57df\u540d\u9650\u5236\u4e3a\u53ea\u80fd\u672c\u5730\u89e3\u6790\uff0c\u4f46\u4e0d\u5f71\u54cd\u5176\u4ed6\u57df\u540d\u3002\u8fd9\u4e9b\u88ab\u9650\u5236\u7684\u57df\u540d\u53ea\u80fd\u4ece \/etc\/hosts \u6216 DHCP \u89e3\u6790\uff1a<\/p>\n

\r\nlocal=\/mehxample.com\/\r\nlocal=\/fooxample.com\/<\/pre>\n

\u9650\u5236 Dnsmasq \u76d1\u542c\u7684\u7f51\u7edc\u63a5\u53e3\uff1a<\/p>\n

\r\ninterface=eth0\r\ninterface=wlan1<\/pre>\n

Dnsmasq \u5728\u9ed8\u8ba4\u8bbe\u7f6e\u4e0b\u4f1a\u8bfb\u53d6\u5e76\u4f7f\u7528 \/etc\/hosts\u3002\u8fd9\u662f\u4e00\u4e2a\u53c8\u5feb\u53c8\u597d\u7684\u914d\u7f6e\u5927\u91cf\u57df\u540d\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14 \/etc\/hosts \u53ea\u9700\u8981\u548c Dnsmasq \u5728\u540c\u4e00\u53f0\u7535\u8111\u4e0a\u3002\u4f60\u8fd8\u53ef\u4ee5\u8ba9\u8fd9\u4e2a\u8fc7\u7a0b\u518d\u5feb\u4e00\u4e9b\uff0c\u53ef\u4ee5\u5728 \/etc\/hosts \u6587\u4ef6\u4e2d\u53ea\u5199\u4e3b\u673a\u540d\uff0c\u7136\u540e\u7528 Dnsmasq \u6765\u6dfb\u52a0\u57df\u540d\u3002\/etc\/hosts \u770b\u4e0a\u53bb\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n

\r\n127.0.0.1 localhost\r\n192.168.0.1 host2\r\n192.168.0.2 host3\r\n192.168.0.3 host4<\/pre>\n

\u7136\u540e\u628a\u4e0b\u9762\u8fd9\u51e0\u884c\u5199\u5165 dnsmasq.conf\uff08\u5f53\u7136\uff0c\u8981\u6362\u6210\u4f60\u81ea\u5df1\u7684\u57df\u540d\uff09\uff1a<\/p>\n

\r\nexpand-hosts\r\ndomain=mehxample.com<\/pre>\n

Dnsmasq \u4f1a\u81ea\u52a8\u628a\u8fd9\u4e9b\u4e3b\u673a\u540d\u6269\u5c55\u4e3a\u5b8c\u6574\u7684\u57df\u540d\uff0c\u6bd4\u5982 host2 \u4f1a\u53d8\u4e3a host2.mehxample.com\u3002<\/p>\n

DNS \u6cdb\u57df\u540d<\/strong><\/div>\n

\u4e00\u822c\u6765\u8bf4\uff0c\u4f7f\u7528 DNS \u6cdb\u57df\u540d\u4e0d\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\uff0c\u56e0\u4e3a\u5b83\u4eec\u592a\u5bb9\u6613\u88ab\u8bef\u7528\u4e86\u3002\u4f46\u5b83\u4eec\u6709\u65f6\u4f1a\u5f88\u6709\u7528\uff0c\u6bd4\u5982\u5728\u4f60\u7684\u5c40\u57df\u7f51\u7684\u4e25\u5bc6\u4fdd\u62a4\u4e4b\u4e0b\u7684\u65f6\u5019\u3002\u4e00\u4e2a\u4f8b\u5b50\u662f\u4f7f\u7528 DNS \u6cdb\u57df\u540d\u4f1a\u8ba9 Kubernetes \u96c6\u7fa4\u53d8\u5f97\u5bb9\u6613\u7ba1\u7406\u8bb8\u591a\uff0c\u9664\u975e\u4f60\u559c\u6b22\u7ed9\u4f60\u6210\u767e\u4e0a\u5343\u7684\u5e94\u7528\u5199 DNS \u8bb0\u5f55\u3002\u5047\u8bbe\u4f60\u7684 Kubernetes \u57df\u540d\u662f mehxample.com\uff0c\u90a3\u4e48\u4e0b\u9762\u8fd9\u884c\u914d\u7f6e\u53ef\u4ee5\u8ba9 Dnsmasq \u89e3\u6790\u6240\u6709\u5bf9 mehxample.com \u7684\u8bf7\u6c42\uff1a<\/p>\n

\r\naddress=\/mehxample.com\/192.168.0.5<\/pre>\n
\r\n\u8fd9\u91cc\u4f7f\u7528\u7684\u5730\u5740\u662f\u4f60\u7684\u96c6\u7fa4\u7684\u516c\u7f51 IP \u5730\u5740\u3002\u8fd9\u4f1a\u54cd\u5e94\u5bf9 mehxample.com \u7684\u6240\u6709\u4e3b\u673a\u540d\u548c\u5b50\u57df\u540d\u7684\u8bf7\u6c42\uff0c\u9664\u975e\u8bf7\u6c42\u7684\u76ee\u6807\u5730\u5740\u5df2\u7ecf\u5728 DHCP \u6216\u8005 \/etc\/hosts \u4e2d\u914d\u7f6e\u8fc7\u3002\r\n\r\n\u4e0b\u661f\u671f\u6211\u4eec\u5c06\u63a2\u7d22\u66f4\u591a\u7684\u7ba1\u7406 DNS \u548c DHCP \u7684\u7ec6\u8282\uff0c\u5305\u62ec\u5bf9\u4e0d\u540c\u7684\u5b50\u7f51\u7edc\u4f7f\u7528\u4e0d\u540c\u7684\u8bbe\u7f6e\uff0c\u4ee5\u53ca\u63d0\u4f9b\u6743\u5a01\u57df\u540d\u670d\u52a1\u5668\u3002<\/pre>\n<\/p>\n
\n

\u4f5c\u8005\uff1aCARLA SCHRODER \u8bd1\u8005\uff1ayixunx \u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7ffb\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-9438-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/gulass.cn\/share-dnsmasq-skill.html<\/a>\u7f16\u8f91\uff1a\u5f20@\u5b87\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u8bb8\u591a\u4eba\u719f\u77e5\u5e76\u70ed\u7231 Dnsmasq\uff0c\u5e76\u5728\u4ed6\u4eec\u7684\u672c\u5730\u57df\u540d\u670d\u52a1\u4e0a\u4f7f\u7528\u5b83\u3002\u4eca\u5929\u6211\u4eec\u5c06\u4ecb\u7ecd\u8fdb\u9636\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406\u3001\u5982\u4f55\u6d4b […]<\/p>\n","protected":false},"author":310,"featured_media":97685,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-97682","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/97682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=97682"}],"version-history":[{"count":4,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/97682\/revisions"}],"predecessor-version":[{"id":291835,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/97682\/revisions\/291835"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/97685"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=97682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=97682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=97682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}