Linux: Setup as DNS Client / Name Server IP Address

Many new Linux user finds it difficult to setup / modify new name server address (NS1 / NS2).

Local name resolution is done via /etc/hosts file. If you have small network, use /etc/hosts file. DNS (domain name service is accountable for associating domain names with ip address, for example domain is easy to remember than IP address provides better name resolution. To configure Linux as DNS client you need to edit or modify /etc/resolv.conf file. This file defines which name servers to use. You want to setup Linux to browse net or run network services like www or smtp; then you need to point out to correct ISP DNS servers:

/etc/resolv.conf file

In Linux and Unix like computer operating systems, the /etc/resolv.conf configuration file contains information that allows a computer connected to the Internet to convert alpha-numeric names into the numeric IP addresses that are required for access to external network resources on the Internet. The process of converting domain names to IP addresses is called “resolving.”

The resolv.conf file typically contains the IP addresses of nameservers (DNS name resolvers) that attempt to translate names into addresses for any node available on the network.

Setup DNS Name resolution

Steps to configure Linux as DNS client, first login as a root user (use su command):

Step # 1: Open /etc/resolv.conf file:

# vi /etc/resolv.conf

Step #2: Add your ISP nameserver as follows:


Note Max. three nameserver can be used/defined at a time.

Step # 3:Test setup nslookup or dig command:

$ dig
$ nslookup

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 50 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
50 comments… add one
  • Anonymous Aug 27, 2005 @ 0:25

    Very precise brief & 100% helpful


  • Anonymous Aug 28, 2005 @ 0:07

    This is quite useful when you have DSL or dial up connection and would like to setup dns quickly under Linux. Or even when you can’t browse site on net using domain name but you can browse them (ping them) using the ip-address. This solved my problem as well as Temporary failure in name resolution (which can be caused by ssh, telnet or mail client etc) To browse Internet one need to configure the DNS properly. Thanks for this tiny post.

  • unamed Feb 19, 2008 @ 13:47

    Thnx helped me 🙂

  • sathish Feb 22, 2008 @ 4:08


    Im having problem with DNS where it unable to lookup the dns that i have setupd. i have configured my hosts file and resolve.conf but stil not solving my problem. i have statis dns ip from ISP and currently using fedora8. any1 having problem with dns with fc8. i cant surf the takes long time to resolve suspect that it getting dns from my router. where it not resolving it from what i have edited in the machine. request is tooo slow. anything that could help to solve? need help. i have checked all my setting everything is fine.

  • Ali durrani Mar 12, 2008 @ 11:21

    I need Dhcp ip router in Fc8
    anyone here experience of that?

  • ganesh Jun 11, 2008 @ 5:31

    I’ve setup the internet connection through PPP dial up and able to get the public IP assigned to me. Also I’ve configured the DNS server address in the /etc/resolv.conf file.
    The problem is, I’m able to ping to my ISP’s IP and also to any public IP addresses, but not to any domain names.
    ping, always fails saying unknown host, but at the same time nslookup and dig work fine(able to resove IP from domain name).
    What may be the problem?, please do help, Thanks in advance,


  • 🐧 nixCraft Jun 11, 2008 @ 7:20

    try ping

  • Pothi Kalimuthu Dec 12, 2008 @ 7:54

    Thanks a bunch!

    I was just looking for this.

  • pankaj sharma Feb 17, 2009 @ 11:07

    domain configer redhate server to clint pc

  • star May 10, 2009 @ 7:51

    thanks for the guides, was looking for this

  • bomy May 19, 2009 @ 8:28

    how i can config host file

  • A.Wadud Jun 20, 2009 @ 5:49

    i cant add GW address in eth0, how to i add it , plz give me command,

  • chisao Jul 16, 2009 @ 8:39

    for redhat linux, im able to ping the ip address from the client side but not the server name .. i type “neat” and under the tab hosts, i put my address as and hostname as but im unable to, mind helping out? thx

  • June Jul 26, 2009 @ 8:38

    hi! i m doing a project on redhat linux 5.3.. my project requires me to setup a dns master server on the server computer. and a client computer have to ping the server and itself by hostname. i m able to use the client computer to ping server computer by hostname and ip. but the client can’t ping itself by hostname. may i know wat is the problem? do i nid to install bind in the client computer as well?
    thanks and regards.

  • Ayie Sep 15, 2009 @ 0:24

    use this command to add a default gateway to your server,
    route add default gw dev eth0

  • sachin shinde Oct 11, 2009 @ 14:44

    It is very understandable information, And thanks for guiding me.

  • Anders Oct 29, 2009 @ 0:24

    You might want to consider adding OpenDNS servers too.

    And if you run any Debian based distribution, try to install the package resolveconf “aptitude install resloveconf” and this will be solved for most parts (dhcpclients) and you add your dns servers in network configuration file /etc/network/interfaces

  • mosin khan Jan 9, 2010 @ 9:22

    i’ve setup dns server on rhel5 and working. clinets are pinging by ip not by name. my server pinging itself by name.
    please help me

  • kumar Jan 10, 2010 @ 10:53

    good I was looking for such type of articals really.

  • ritzrash Mar 10, 2010 @ 16:53

    i know my proxy server ip and i put it in the resolve.conf file like explained above


    however when i do dig it gives me

    ; <> DiG 9.2.4 <>
    ;; global options: printcmd
    ;; connection timed out; no servers could be reached

    I even tried adding the to my yum.conf file

    Still getting the same error.. Please suggest

  • ozgur Mar 11, 2010 @ 12:15

    This solved the problem temporariliy, but everytime i reboot my system, resolv.conf is set back to its original state. How can i make this change permanent?

  • ozgur Mar 11, 2010 @ 18:28

    Thanks for the help..

  • Foxx Linux Mar 17, 2010 @ 2:51

    great instructions.. 100% accurate.

  • Lakshman Mar 23, 2010 @ 14:18

    Good Information. Helped me in resolving one of critical issue.

  • maggie May 11, 2010 @ 9:57

    i do appreciate for what your doing to us.
    i have problem with how to set up dns server using linux in my laptop

  • Omar, Riverside, California Jun 4, 2010 @ 2:59

    I am just wondering. Setting up my first web server to run my website.
    I got a domain name paid for and a dns thing from them.
    Do i just plug this in the resolv.conf file?
    I guess my question would be what does the resolve file look like when we are getting a domain name and dns from some company online in order to make our server public?

    • Omar, Riverside, California Jun 4, 2010 @ 3:01

      Sorry but wanted to add another question.
      What about IP address do I just pick one out of the air? or set it do Dynamic?
      Right now I got my server working in lan as a local server for testing but would like to connect it to the web for my website so hard finding help for this set up. Usually everything is for local server setup.

  • naresh.singh Jun 13, 2010 @ 10:22

    please submit more information about dns configuratio and aleternet dns

    • Omar Jun 14, 2010 @ 13:34

      I got it working thanks. with inadyn setup as the dns part.
      I decided to avoid the security issues I would have as a beginner with setting up my own dns server at home.
      Thank you for this site. I learned the most important lesson I think which is I am still a beginner and I should take it one step at a time.

  • Nhoel Jun 24, 2010 @ 3:41

    why cant i edit my resolv.conf file?

    • alva Jul 15, 2010 @ 3:13

      you might not have the write permission. issue this command ‘ls -lrt’ you should see at least something like this ‘-rw-r–r– ‘

  • kadam Aug 9, 2010 @ 7:16


    anyone can help me create dns server in redhat linux.

  • dinesh Dec 19, 2010 @ 8:17

    Dear sir,

    I have installed two linux (os) & on each OS oracle11g installed on the vmware and now configuring the server and client on linux, And also two databases are created on each OS.

    Now i want to configure the client/server but i am not able to connect due to proper ping,IP & host name, so kinly give me the proper steps with connection scripts.

    thanks & Regards

  • sanjay mahajan Jan 17, 2011 @ 6:05

    Dear Sir

    I am having problwm with Redhat Enterprise Linux 4 about Configuring it as a internet server
    I want to use RHEL 4 as a server and windows XP Systems as a clients for sharing internet among them ,

    Pls assist me about doing the same

    thanking you

    sanjay mahajan

  • hem kumar Apr 20, 2011 @ 5:51

    how do i install dns in linux?
    please leave da comment?

    thanks for helping…

  • bharat Apr 21, 2011 @ 2:58

    but over the selinux and firewall…

  • Hal Martin Jul 25, 2011 @ 19:44

    This does not work on Fedora 13. If you try to edit resolv.conf NetworkManager will overwrite it on restart.

  • Al Noma Sep 24, 2011 @ 20:27

    I configure DNS server by linux………….how i add or login from xp client

  • Brenzer Hummer Nov 3, 2011 @ 16:26

    Short and upto the mark. Appreciate it!!!

  • freak_kaps Apr 18, 2012 @ 17:56



    what should be instead of “” in
    “search” as according to my system.
    and what if i use
    “domain” instead of “search” in /etc/resolv.conf file

  • ashwani May 16, 2012 @ 7:44

    error in configuration file that is /etc/named.conf unknown option 1 {option}

  • ajas Dec 18, 2012 @ 8:44

    this site gave me a lot of informations…..very helpful one…..thanks a lot…..

  • l33zard Jan 18, 2013 @ 1:57

    Great info tnx to creators

  • Manhelp Mar 28, 2013 @ 18:15

    Could you please tell me what is Global DNS server? when is it used? And how is it configured in linux?
    Is it used when you dont define any DNS IP in resov.conf?Where can it be configured?

    Please guide.

  • ad Jun 6, 2013 @ 15:02

    This also works

    just cancal everything and edit vi /etc/resolv.conf

    add just this:


  • Pro Host Jun 8, 2013 @ 21:05

    Can you have more than one domain name?

    Also I am trying to find out what port is uses to send out the resolve connection?

    If you have any ideas for this please let me know!

  • Chris F Mar 13, 2014 @ 14:22

    This is a generated file though. Changes should be made in /etc/sysconfig/network with the following line added


  • Chris F Mar 13, 2014 @ 14:24

    Sorry, html left out the part with angle brackets after DNS1=. Here’s an example


  • Vannara Mao Mar 19, 2014 @ 6:50

    Nothing to say because it’s so simply and easy to understand. Thank you very much. 😉

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum