Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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)

share|improve this question

3 Answers 3

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.

share|improve this answer
    
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 –  Serg Jul 4 at 17:05

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.

share|improve this answer
1  
The question was very specifically “How to not do that?”. –  Evpok Mar 25 '14 at 9:55

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.