从Ubuntu中的DHCP服务器忽略DNS


16

DNS/etc/resolvconf/resolv.conf.d/base文件中设置了static :

nameserver 8.8.8.8
nameserver 8.8.4.4

但是我的电脑仍然从DHCP获取DNS,这是我的/etc/resolv.conf

nameserver 192.168.100.2 
nameserver 8.8.8.8
nameserver 8.8.4.4

如何忽略DNSDHCP服务器获得的信息?

Answers:


28

您可以将此行添加到您的/etc/dhcp/dhclient.conf

supersede domain-name-servers 8.8.8.8, 8.8.4.4;

然后重新启动网络或运行dhclient进行更改。

来自man dhclient.conf

The supersede statement

       supersede [ option declaration ];

       If for some option the client should always  use  a  locally-configured
       value  or  values rather than whatever is supplied by the server, these
       values can be defined in the supersede statement.

4
您也可以在注释掉/etc/dhcp/dhclient.confrequest参数,你不想请求,DNS也可以domain-name, domain-name-servers, domain-search
Alex

@Alex我注意到有些设备会使用您不需要的选项进行响应。尽管您认为如果不要求它会被忽略,但实际上相反的情况是正确的:未处理的返回选项实际上已被处理。配置对安全敏感的设备时要记住的一些事情(例如,发送CIDR路由并绕过网关的流量。)
gertvdijk
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.