set DNS server terminal

Asked by Andreas Weller

Hi!
I connect to the internet using WLAN and a router.
Due to troubles with my provider's DNS server I would like to use another one.
How do I temporarily change the DNS server used with the terminal?
I don't want to change my /etc/resolv.conf...

Regards,
  Andreas Weller

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Aanjhan Ranganathan (aanjhan) said :
#1

Hi,

You can change the DNS server through the System -> Administration -> network option if you do not like to use the command line interface.

Hope that helps.

Revision history for this message
Andreas Weller (weller-andreas-weller) said :
#2

Thanks - but I'm looking for the command to use on the terminal for setting the DNS server

for examle you can use nslookup for querying a server: nslookup www.example.com [server ip]

You can use ifconfig for changing your IP

But what command to use for setting the DNS server (until next reboot)?

Revision history for this message
Alex Nehaichik (nab) said :
#3

There is no such command. You can set default nameserver via /etc/init.d/rc.local:

echo "nameserver a.b.c.d
namesever e.f.g.h" > /etc/resolv.conf

Revision history for this message
I Gede Bagus Kosha (kosha) said :
#4

i think it's ok to change /etc/resolv.conf with your secondary DNS, and change it back to your primary DNS while it needed.

AFAIK there is no such command to change DNS in /etc/resolv.conf temporarily

Revision history for this message
Stephen Parry (sgparry) said :
#5

Old question, but if you have resolvconf package installed (the default for at least 14.04+), the DNS server choices are then made by a combination of programs (e.g. DNSMasq), interfacing with the resolvconf program, which updates resolv.conf automatically for you. You can override this temporarily by issuing the following sort of command:

sudo sh -c "resolvconf -d eth0 && (echo nameserver 185.37.37.37 & echo nameserver 185.37.37.185) | resolvconf -a eth0"

which would switch to the two specified name servers. This should revert automatically when you reboot. Also, if you just have dnsmasq managing your dns then:

sudo resolvconf -d eth0

may suffice to revert the changes without a reboot.

Can you help with this problem?

Provide an answer of your own, or ask Andreas Weller for more information if necessary.

To post a message you must log in.