ubuntu 20.04 设置DNS
<svg xmlns="http://www.w3.org/2000/svg" style="display: none"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"></path>
</svg>
<p></p>
<div class="toc">
<h3>ubuntu 20.04 设置DNS</h3>
<ul><li>ubuntu 20.04 设置DNS 快捷步骤</li><li>下面是命令解释</li><li><ul><li>1、决定系统dns的文件是/etc/resolv.conf</li><li>2、谁能最终影响/etc/resolv.conf,就是/etc/systemd/resolved.conf</li><li>3、/etc/resolv.conf软链接到/run/systemd/resolve/resolv.conf</li></ul>
</li></ul>
</div>
<p></p>
<h1>ubuntu 20.04 设置DNS 快捷步骤</h1>
<p>修改 /etc/systemd/resolved.conf 文件,在其中添加dns;<br> sudo vi /etc/systemd/resolved.conf;<br> 加入一个新行<br> DNS=114.114.114.114 8.8.8.8 8.8.4.4;<br> systemctl restart systemd-resolved.service;<br> sudo mv /etc/resolv.conf /etc/resolv.conf.bak;<br> sudo ln -s /run/systemd/resolve/resolv.conf /etc/;</p>
<h1>下面是命令解释</h1>
<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>
<h2>1、决定系统dns的文件是/etc/resolv.conf</h2>
<p>改变此文件就可以设置DNS。<br> 此文件改了也没用,受其他影响,重启服务后还是会丢配置。<br> <img src="https://img-blog.csdnimg.cn/044f0c2b91264a1e879ba7e55110fff8.png" alt="在这里插入图片描述"></p>
<h2>2、谁能最终影响/etc/resolv.conf,就是/etc/systemd/resolved.conf</h2>
<p>找到系统中动态变化的影响DNS的文件,/etc/resolv.conf软链接到此文件即可。<br> 这个文件就是/run/systemd/resolve/resolv.conf。</p>
<p>/run/systemd/resolve/resolv.conf的内容随/etc/systemd/resolved.conf改变而改变,像是link。<br> 因此需要改变/etc/systemd/resolved.conf的内容,写入dns<br> vi /etc/systemd/resolved.conf<br> DNS=114.114.114.114 8.8.8.8 8.8.4.4<br> <img src="https://img-blog.csdnimg.cn/026cd6c1f0014e318baa85774176d441.png" alt="在这里插入图片描述"><br> 重启systemd-resolved.service<br> systemctl restart systemd-resolved.service<br> cat /run/systemd/resolve/resolv.conf 和/etc/systemd/resolved.conf保持一致<br> <img src="https://img-blog.csdnimg.cn/2e95c61042d042b0bccacac1480eb351.png" alt="在这里插入图片描述"></p>
<h2>3、/etc/resolv.conf软链接到/run/systemd/resolve/resolv.conf</h2>
<p>原来是软链接到这个文件,这个文件不影响系统DNS,所以不起作用。<br> <img src="https://img-blog.csdnimg.cn/5e3d1254864541a7957047f037d51eab.png" alt="ubuntu 20.04 设置DNS"><br> cat /run/systemd/resolve/stub-resolv.conf<br> <img src="https://img-blog.csdnimg.cn/b88ea6b26f51446c8fe081665be22d4b.png" alt="ubuntu 20.04 设置DNS"><br> 做完软链接后,查看/etc/resolv.conf 已经改变。<br> cat /etc/resolv.conf<br> <img src="https://img-blog.csdnimg.cn/9457fd04a47d4ae1a26cea577fee40ee.png" alt="在这里插入图片描述"></p>
</div>
<div id="MySignature" role="contentinfo">
<p></p>
<p></p>
时光如水,总是无言。若你安好,便是晴天。
<p></p>
<p>本文来自博客园,作者:OceanWaves,转载请注明原文链接:https://www.cnblogs.com/OceanWaves/p/17312444.html</p><br><br>
来源:https://www.cnblogs.com/OceanWaves/p/17312444.html
頁:
[1]