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 208.67.222.123 & 208.67.220.123)


Solution 1:

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.