Ubuntu: Use same dns server for all (future) connections


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 &


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;:

$ 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;  #prepend domain-name-servers;  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.


open the network control pannel for each network device you use. wireless/wired/vpn...on the ipv4 tabs set dhcp addresses only and specify your dns manually from there. do the same for ipv6 only if you use it.


/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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »