set DNS server terminal

Asked by Andreas Weller

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

  Andreas Weller

Question information

English Edit question
Ubuntu Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Aanjhan Ranganathan (aanjhan) said :


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 :

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

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 :

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 :

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 & echo nameserver | 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.