Ubuntu 20.04设置DNS解析(解决resolve.conf被覆盖问题)。
<p>ubuntu在域名解析时,最直接使用的是/etc/resolve.conf文件,它是/run/systemd/resolve/<br>resolve.conf的软链接,而对于刚装完的ubuntu系统,该文件的内容如下:<br>
<img src="https://img2022.cnblogs.com/blog/2140575/202205/2140575-20220505111732082-1501862247.png"></p>
<h1 id="this-file-is-managed-by-mansystemd-resolved8-do-not-edit">This file is managed by man:systemd-resolved(8). Do not edit.</h1>
<h1 id="_"></h1>
<h1 id="this-is-a-dynamic-resolvconf-file-for-connecting-local-clients-to-the">This is a dynamic resolv.conf file for connecting local clients to the</h1>
<h1 id="internal-dns-stub-resolver-of-systemd-resolved-this-file-lists-all">internal DNS stub resolver of systemd-resolved. This file lists all</h1>
<h1 id="configured-search-domains">configured search domains.</h1>
<h1 id="_-1"></h1>
<h1 id="run-resolvectl-status-to-see-details-about-the-uplink-dns-servers">Run "resolvectl status" to see details about the uplink DNS servers</h1>
<h1 id="currently-in-use">currently in use.</h1>
<h1 id="_-2"></h1>
<h1 id="third-party-programs-must-not-access-this-file-directly-but-only-through-the">Third party programs must not access this file directly, but only through the</h1>
<h1 id="symlink-at-etcresolvconf-to-manage-manresolvconf5-in-a-different-way">symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,</h1>
<h1 id="replace-this-symlink-by-a-static-file-or-a-different-symlink">replace this symlink by a static file or a different symlink.</h1>
<h1 id="_-3"></h1>
<h1 id="see-mansystemd-resolvedservice8-for-details-about-the-supported-modes-of">See man:systemd-resolved.service(8) for details about the supported modes of</h1>
<h1 id="operation-for-etcresolvconf">operation for /etc/resolv.conf.</h1>
<p>nameserver 127.0.0.53<br>
options edns0 trust-ad</p>
<p>直接修改/etc/resolv.conf中的nameserver 配置,例如nameserver 192.168.4.2,修改完成后,重启服务会重新还原文件。<br>
解决:</p>
<ol>
<li>修改/etc/systemd/resolved.conf,例如:<br>
<br>
DNS=8.8.8.8 114.114.114.114 192.168.4.2<br>
2.重启域名解析服务<br>
systemctl restart systemd-resolved<br>
systemctl enable systemd-resolved<br>
3.备份当前的/etc/resolve.conf,并重新设置/run/systemd/resolve/resolv.conf到/etc/resolve.conf的软链接<br>
mv /etc/resolv.conf /etc/resolv.conf.bak<br>
ln-s /run/systemd/resolve/resolv.conf /etc/resolv.conf<br>
4.查看验证,<br>
cat /etc/resolv.conf<br>
重启服务再查看。ping www.baidu.com可以ping通。</li>
</ol><br><br>
来源:https://www.cnblogs.com/zhaichao93/p/16224163.html
頁:
[1]