How to Set Up DNS Lookup in Linux

Q. How do I setup DNS Lookup under any Linux distribution ?

A. When an application (such as mail client or browser) makes a request which requires a DNS lookup, such programs send a resolution request to the local DNS resolver in the local operating system, which in turn handles the communications required. Under Linux resolver is configured via /etc/resolv.conf file. Open this file as a root user, enter:
# vi /etc/resolv.conf
Append or modify as follows into the file:
search nixcraft.com
nameserver 4.2.1.1
nameserver 4.2.1.2
nameserver 4.2.1.3

Save and close the file. Replace nixcraft.com with your actual domain name. 4.2.1.1 is first name server address. Save and close the file. Test setup, enter:
$ host cyberciti.com
$ host -t ns cyberciti.com

Sample output:

ADVERTISEMENTS

cyberciti.com name server ns2.nixcraft.net.
cyberciti.com name server ns1.nixcraft.net.
cyberciti.com name server ns3.nixcraft.net.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • Known Jun 8, 2010 @ 12:00

    A better setup is

    nameserver 4.2.1.1
    nameserver 4.2.1.2
    nameserver 4.2.1.3
    option rotate
    option timeout:1

    ‘rotate’ sets RES_ROTATE in _res.options, which causes round robin selection of nameservers from among those listed.
    ‘timeout’ sets the amount of time the resolver will wait for a response from a remote name server before retrying the query via a different name server.

  • Jeffrey L. Roberts Dec 8, 2014 @ 22:38

    +1 to Known, this just saved my ass

  • Jimmy Mar 9, 2015 @ 15:07

    A better setup is

    nameserver 4.2.2.1
    nameserver 4.2.2.2
    nameserver 4.2.2.3
    option rotate
    option timeout:1

    (With a good dns server lol !)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.