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.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 14 comments… read them below or add one }
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
Typo:
nslookup
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.
well that’s true, but it has to resolve the dns name before it can continue the ping. So ping works too.
> 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
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.
How can I specify something like for site say ‘www.mysite.com’ go to this ip say ’192.168.1.2′?
You need to set named or bind9 software to point to specific IP.
I WANT THE COMMAND ON LINUX TO CREATE DNS & DHCP SERVER.
i m very much crazy abt Linux
How does one set this permanently though? /etc/resolv.conf will erase changes upon reboot/shutdown.
From resolv.conf:
# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
THANK YOU!!!!!!!
fixed my network after visiting 8 sites. This one did it for me :)
Ubuntu 12 server, with KDE installed on top.
Good link.Luckily stumbled after visiting 1st 3 results on google search. Glad i checked it out .