我有点困惑,不知道应该在哪个位置为使用 DHCP 的服务器添加自定义 DNS 条目。此实例位于 AWS 中,但我有一个自定义 DNS 服务器,需要将其用作主名称服务器。我应该将其添加到接口文件中吗?如果是,语法应该是什么样的?
答案1
您应该做两件事:是的,将您想要的 DNS 添加到您的/etc/network/interfaces
文件中;并且更改您的/etc/dhcp/dhclient.conf
文件以在获取或更新其 IP 租约时不通过它来请求它。
这些示例来自我的主要 16.04 服务器:首先,/etc/network/interfaces
文件(在我的情况下,DNS 就是这个服务器本身):
doug@DOUG-64:~/config/etc/network$ cat interfaces
# interfaces file for smythies.com 2016.01.30
# attempt to set local DNS herein, as the method
# used with the old 12.04 server no longer works.
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
pre-up /home/doug/init/doug_firewall
dns-nameservers 127.0.0.1
# The primary interface (d-link PCI card)
auto enp4s0
iface enp4s0 inet dhcp
# Local network interface (uses built in ethernet port)
auto enp2s0
iface enp2s0 inet static
address 192.168.111.1
network 192.168.111.0
netmask 255.255.255.0
broadcast 192.168.111.255
和,etc/dhcp/dhclient.conf
:
doug@DOUG-64:~/config/etc/dhcp$ cat dhclient.conf
# Smythies.com 2016.02.02
# For 16.04, in terms of DNS, this stuff isn't working.
# Try deleting the domain-name-servers from the request.
# See also /resolvconf/resolv.conf.d/base.
#
...[snip]...
#request subnet-mask, broadcast-address, time-offset, routers,
# domain-name, domain-name-servers, domain-search, host-name,
# netbios-name-servers, netbios-scope, interface-mtu,
# rfc3442-classless-static-routes, ntp-servers;
request subnet-mask, broadcast-address, time-offset, routers;
答案2
您可以在下面指定的配置文件中指定要使用的 DNS 服务器。在文件中添加要使用的 DNS 服务器/etc/network/interfaces
。示例
dns-nameservers 8.8.8.8
之后,编辑/etc/dhcp/dhclient.conf
文件并添加以下行:
request subnet-mask, broadcast-address, time-offset, routers;
然后保存这两个文件。