10

I'm wondering if it is possible to specify, that all connections (even future, like when using wifi at some other place (=different SSID)) will be using pre-defined DNS server

When I have some (concrete) connections, I could go to IPv4 settings, and specify DNS server there (however, in case of new connection I would have to do it (and not forget it))

This may be particularly useful for some safe/filtering dns (such as opendns's 208.67.222.123 & 208.67.220.123)

2 Answers 2

5

The way I do this is to set supersede domain-name-servers in /etc/dhcp/dhclient.conf. I've tried variety of options, including head or tail files, under /etc/resolvconf/resolv.conf.d/ folder, but only dhclient.conf does the trick for me. I've done it in 13.04, 14.04, and 15.04 versions of Ubuntu – always works.

Basic idea is that when you connect to a wifi access point, you receive certain information from dhcp server. The supersede option tells Ubuntu to replace whatever dhcp server sends you, with your own. In this case we supersede dns server. So no matter what wifi you connect to, your ubuntu will replace wifi-given dns with its own.

Bellow is the sample of my own dhclient.conf file, notice the line supersede domain-name-servers 208.67.220.220;:

$ cat /etc/dhcp/dhclient.conf                                                  
# Configuration file for /sbin/dhclient, which is included in Debian's
#   dhcp3-client package.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#   man page for more information about the syntax of this file
#   and a more comprehensive list of the parameters understood by
#   dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#   not leave anything out (like the domain name, for example), then
#   few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

#send host-name "andare.fugue.com";
send host-name = gethostname();
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
supersede domain-name-servers 208.67.220.220;
#prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search, host-name,
    dhcp6.name-servers, dhcp6.domain-search,
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers,
    dhcp6.fqdn, dhcp6.sntp-servers;

Now, if you'd like you can use prepend option to use both wifi-given and your own server. In case wifi-given server fails, your request will be routed to the prepended dns.

3
  • I've also written a script to do manually set DNS for all connections stored in /etc/NetworkManager/system-connections , however it seems that it doesn't work in 15.04. Let me know if you want it, and I'll link the answer to another, similar question where i posted it here Jul 4, 2015 at 17:05
  • Hi @Sergiy Kolodyazhnyy, I've found your solution works well for IPv4 DNS servers, but I can't get it to work for IPv6. I added these lines to /etc/dhcp/dhclient.conf to set both IPv4 and IPv6 DNS servers: supersede domain-name-servers 84.200.69.80, 84.200.70.40; supersede dhcp6.name-servers 2001:1608:10:25::1c04:b12f, 2001:1608:10:25::9249:d69b; When I query the use of DNS servers afterwards(nmcli dev show | grep DNS), only the IPv4 DNS servers are affected. The system still seems to adopt a suggestion from upstream for IPv6. Any idea how to fix this?
    – django
    Jun 18, 2019 at 6:36
  • Hi @django , I don't have that much experience using IPv6 settings, so can't say how to fix this. According to a few bug reports on Debian bug tracker suggest this option didn't exist in dhclient prior to 4.0 , but I don't think that's the case here. I've also found your question , askubuntu.com/q/1151913/295286, hopefully it can be answered. I've already +1'ed it. If I find something, I'll post an answer, but so far I've nothing to suggest Jun 18, 2019 at 7:36
0

/etc/resolvconf is the package that handles this. It dynamically builds your /etc/resolv.conf file based on all sorts of rules.

You could set your preferred dns server in /etc/resolvconf/resolv.conf.d/head

All other dns servers would come after that for all interfaces.

There are plenty of more advanced ways to get resolvconf to suit your particular requirements, have a read of the docs or howto's.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .