I'm a bit confused as to the proper place to add custom DNS entries for a server that uses DHCP. This instance is in AWS but I have a custom DNS server that it needs to use as it's primary name server. Should I add that in to the interfaces file? If so, what should that syntax look like?
Asked
Active
Viewed 980 times
2 Answers
2
You should do two things: Yes, add the DNS that you want to your /etc/network/interfaces
file; And change your /etc/dhcp/dhclient.conf
file to not ask for it via when it is getting or renewing it's IP lease.
These examples are from my main 16.04 server: First, /etc/network/interfaces
file (in my case the DNS is this server itself):
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
And, 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;

Doug Smythies
- 15,448
- 5
- 44
- 61
-
Nice answer! Can multiple dns be used on the same line? such as: dns-nameservers 127.0.0.1 8.8.8.8 – Thaidog Nov 09 '18 at 21:59
-
Also wondering how to make this regenerate resolv without rebooting... do you know what service handles this? – Thaidog Nov 09 '18 at 22:10
-
Yes, I think you can specify multiple dns-nameservers. I'm not sure about your 2nd comment. – Doug Smythies Nov 10 '18 at 04:57
0
You can specify the DNS server which you want to use in the config file specified below. Add the DNS server that you want to use in /etc/network/interfaces
file. Example
dns-nameservers 8.8.8.8
After that, edit your /etc/dhcp/dhclient.conf
file and add the line below:
request subnet-mask, broadcast-address, time-offset, routers;
Then save both the files.

Tejas Lotlikar
- 2,945
- 5
- 17
- 26