Seá*_*yes 339 linux networking dns debian dnsmasq
我在网上看到的大部分信息都说要编辑/etc/resolv.conf,但我在那里所做的任何更改都会被覆盖。
$ cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- 
#     YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
Run Code Online (Sandbox Code Playgroud)
似乎 127.0.1.1 是dnsmasq. 该dnsmasq文件说来编辑/etc/resolv.conf。我试图把自定义的域名服务器中/etc/resolv.conf.d/base,但在变化没露面/etc/resolv.conf后运行sudo resolvconf -u。
仅供参考,我不想在每个连接的基础上更改 DNS,我想设置默认 DNS 设置以在未另行指定时用于所有连接。
更新:
我自己回答了这个问题:https : //unix.stackexchange.com/a/163506/67024
我认为这是最好的解决方案,因为:
slm*_*slm 282
我相信如果您想覆盖 DNS 名称服务器,您只需base在resolv.conf.d.
$ sudo vim /etc/resolvconf/resolv.conf.d/base
Run Code Online (Sandbox Code Playgroud)
然后像这样把你的名字服务器列表放进去:
nameserver 8.8.8.8
nameserver 8.8.4.4
Run Code Online (Sandbox Code Playgroud)
最后更新resolvconf:
$ sudo resolvconf -u
Run Code Online (Sandbox Code Playgroud)
如果您查看手册页,resolvconf它描述了/etc/resolvconf/resolv.conf.d/.
   /etc/resolvconf/resolv.conf.d/base
          File  containing  basic  resolver  information.  The lines in this 
          file are included in the resolver configuration file even when no
          interfaces are configured.
   /etc/resolvconf/resolv.conf.d/head
          File to be prepended to the dynamically generated resolver 
          configuration file.  Normally this is just a comment line.
   /etc/resolvconf/resolv.conf.d/tail
          File to be appended to the dynamically generated resolver 
          configuration file.  To append nothing, make this  an  empty  
          file.   This file is a good place to put a resolver options line 
          if one is needed, e.g.,
              options inet6
Run Code Online (Sandbox Code Playgroud)
即使head文件顶部有警告:
$ cat /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
Run Code Online (Sandbox Code Playgroud)
此警告在那里,以便在构建这些文件时,警告最终将进入resolv.conf这些文件将用于制作的结果文件中。因此,您也可以轻松地nameserver将上述base文件行添加到head文件中。
bra*_*rad 85
我也对这个问题感兴趣,我尝试了@sim 提出的解决方案。
为了测试它,我把
nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
在/etc/resolvconf/resolv.conf.d/base和
nameserver 8.8.4.4
Run Code Online (Sandbox Code Playgroud)
在 /etc/resolvconf/resolv.conf.d/head
然后我重新启动了网络
sudo service network-manager restart
Run Code Online (Sandbox Code Playgroud)
结果/etc/resolv.conf看起来像
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.4.4
nameserver 127.0.1.1
Run Code Online (Sandbox Code Playgroud)
并nm-tool指出 dnsserver 是
DNS:             208.67.222.222
DNS:             208.67.220.220
Run Code Online (Sandbox Code Playgroud)
这是我的路由器提供的。另一方面,挖掘地址告诉我们
;; Query time: 28 msec
;; SERVER: 8.8.4.4#53(8.8.4.4)
Run Code Online (Sandbox Code Playgroud)
如果我是对的,我从这一切中得出的结论是
总而言之,它有效,但我认为这不是所要求的预期结果。我认为更接近的解决方案如下。编辑
sudo vim /etc/dhcp/dhclient.conf
Run Code Online (Sandbox Code Playgroud)
然后加
supersede domain-name-servers 8.8.8.8;
Run Code Online (Sandbox Code Playgroud)
结果如下:resolv.conf只包含127.0.0.1,这意味着调用了dnsmasq缓存,nm-tool说
DNS:             8.8.8.8
Run Code Online (Sandbox Code Playgroud)
这意味着如果搜索的名称不在缓存中,那么它会在 8.8.8.8 而不是由 dhcp 提供的服务器上请求。
另一个(也许更好)的选择是使用“prepend”而不是“supersede”:这样,如果 8.8.8.8 未解析名称,则请求会回退到另一台服务器上。事实上, nm-tool 说
DNS:             8.8.8.8    
DNS:             208.67.222.222
DNS:             208.67.220.220
Run Code Online (Sandbox Code Playgroud)
        Seá*_*yes 73
我发现您可以dnsmasq通过将以下行添加到以下行来更改使用的名称服务器/etc/dnsmasq.conf:
server=8.8.8.8
server=8.8.4.4
Run Code Online (Sandbox Code Playgroud)
我没有/etc/dnsmasq.conf文件,因为它是由 dnsmasq 包安装的,但 Ubuntu 只带有 dnsmasq-base。我跑sudo apt-get install dnsmasq,然后编辑/etc/dnsmasq.conf,然后sudo service dnsmasq restart和sudo service network-manager restart。
我跑去sudo tail -n 200 /var/log/syslog检查我的 syslog 并验证它dnsmasq正在使用我指定的名称服务器:
Oct 21 23:00:54 mylaptop dnsmasq[8611]: using nameserver 8.8.8.8#53
Oct 21 23:00:54 mylaptop dnsmasq[8611]: using nameserver 8.8.4.4#53
Run Code Online (Sandbox Code Playgroud)
        小智 23
对于静态 IP 情况,Ubuntu Server Guide 说要更改文件 /etc/network/interfaces,它可能如下所示:
iface eth0 inet static
address 192.168.3.3
netmask 255.255.255.0
gateway 192.168.3.1
dns-search example.com
dns-nameservers 192.168.3.45 192.168.8.10
Run Code Online (Sandbox Code Playgroud)
您将 IP 192.168.3.45 192.168.8.10 更改为您想要的 IP,例如 8.8.8.8
https://help.ubuntu.com/14.04/serverguide/serverguide.pdf 第 38 页
小智 20
搜索“网络连接”
打开它
                    
然后选择 WiFi 或以太网,或您使用的任何东西,然后单击编辑。你会得到这个:
              
在选项卡中选择 ipv4
仅在方法中选择地址
在下面输入您的 DNS 名称并保存
你完成了
You*_*lah 18
一个尚未提及的快速而肮脏的解决方法是resolv.conf在编辑文件后立即在文件上设置不可变标志。
$ sudo nano /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)
添加这个并保存:
nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
然后:
$ sudo chattr +i /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)
这应该够了吧。我也在我的系统上这样做。
小智 14
我的问题有点不同,我想覆盖我的路由器 DNS 服务器。我从 Ubuntu 找到了这个链接:https : //wiki.ubuntu.com/OverrideDNSServers
它说:如果您想覆盖 DHCP 服务器提供给您的 DNS 设置,请打开
/etc/dhcp3/dhclient.conf
Run Code Online (Sandbox Code Playgroud)
并添加以下行:
supersede domain-name-servers <dns_ip_address1>,<dns_ip_address2>;
Run Code Online (Sandbox Code Playgroud)
用<dns_ip_address*>适当的内容替换项目。
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1019449 次  |  
        
|   最近记录:  |