About Linux FAQ

Browse More FAQs:

Linux / UNIX set the DNS from the command line

Posted by Vivek on Wednesday December 19, 07 @7:28 pm

Q. I just got Linux installed on my system. I'm able to connect to internet via IP address only. I'm not able to find out information about setting up new DNS sever ip under Linux. How do I configure primary and secondary DNS via terminal / shell prompt?

A. Under Linux / UNIX / BSD operating system, you need to edit the /etc/resolv.conf file and add the line:

nameserver {IP-OF-THE-DNS-1}
nameserver {IP-OF-THEISP-DNS-SERVER-2}

Login as the root, enter:
# vi /etc/resolv.conf
OR
$ sudo vi /etc/resolv.conf
Modify or enter nameserver as follows:
nameserver 208.67.222.222
nameserver 208.67.220.220

Save and close the file. To test DNS configuration type any one of the following command:
$ host google.com
$ dig google.com
$ ping google.com
$ nslookup your-domain.com

Output:

google.com has address 72.14.207.99
google.com has address 64.233.187.99
google.com has address 64.233.167.99
google.com mail is handled by 10 smtp4.google.com.
google.com mail is handled by 10 smtp1.google.com.
google.com mail is handled by 10 smtp2.google.com.
google.com mail is handled by 10 smtp3.google.com.

If you see valid output such as actual IP address or able to ping to remote server via hostname, it means that the dns is working for you. Also make sure you have valid default gateway setup, if you see the time out error.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Discussion on This FAQ

  1. me Says:

    you’re easily sliding to the point where your tutorials will be as complex as ‘how to start your computer? press the power button!’

    haha

  2. Ash Says:

    Typo:
    nslookup

  3. Robert de Bock Says:

    Ping is a tool to send ICMP echo requests to machines, not to check if resolving works. nslookup, dig and host can be used to check resolving, as you perfectly describe in this article.

  4. user Says:

    > http://www.google.com
    Server: 208.67.222.222
    Address: 208.67.222.222#53

    Non-authoritative answer:
    http://www.google.com canonical name = google.navigation.opendns.com.
    Name: google.navigation.opendns.com
    Address: 208.67.219.230
    Name: google.navigation.opendns.com
    Address: 208.67.219.231

  5. Phil Says:

    Using nslookup you can query different name servers.

    nslookup http://www.google.com XXX.XXX.XXX.XXX

    where XXX.XXX.XXX.XXX is the ip adress or name of the name server you are trying to query.

    Doing :
    nslookup http://www.google.com localhost
    will query your local dns server if you have one.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , ~ Last updated on: December 20, 2007

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.