How can I force a nameserver resolution using the second nameserver on an ubuntu server

Ahmad asked:

I try to download something from nvidia on a remote server via ssh. Iran is banned by the nvidia website. When I check the server dns, that is:

IP4.DNS[1]:                             192.168.20.14
IP4.DNS[2]:                             8.8.8.8

I know if I could set the dns to google dns (8.8.4.4 or 8.8.8.8) then I was able to surf the website and download from it. I tried to change the dns on the server but whatever I do it’s the same as above.

Its the content of /etc/network/interfaces

uto lo
iface lo inet loopback

#auto enth0
iface eth0 inet static
        address 172.16.143.8
        netmask 255.255.255.224
        gateway 172.16.143.1
dns-nameservers 8.8.8.8 8.8.4.4

This is the output of ifconfig

eno1      Link encap:Ethernet  HWaddr 34:97:f6:dc:9f:ff  
          inet addr:172.16.143.8  Bcast:172.16.143.31  Mask:255.255.255.224
          inet6 addr: fe80::c8cd:597a:b384:a22b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2101 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1298 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:891719 (891.7 KB)  TX bytes:237702 (237.7 KB)
          Interrupt:20 Memory:fb200000-fb220000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host

I wonder why network id is eno1?! it’s the output of sudo nmcli c

NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  532cfa3a-d61b-4bc4-b516-1dc31a5baead  802-3-ethernet  eno1

Once I changed eth0 to eno1 but then I couldn’t access the server until the file was set back to eth0

I also installed resolvconf and followed instruction of this website

https://www.tecmint.com/set-permanent-dns-nameservers-in-ubuntu-debian/

the content of /etc/resolv.conf is preserved but the dns doesn’t change

Yet, I might be able to use the secondary dns to connect a website (using wget or other solutions)

Is it possible, what could I do?

My answer:


It looks like your system is using NetworkManager to manage its connection to the network. This is helpful, because what you want to do needs to be done in NM, and cannot be done in the interfaces file.

You need to modify a NetworkManager setting for your connection to tell it to ignore the DNS servers provided by DHCP so that it will only use your chosen DNS servers:

nmcli c mod "Wired connection 1" ipv4.ignore-auto-dns true

You can then restart the network or the computer. All of your DNS queries should now use your chosen nameservers.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.