Three Simple Ways to Configure DNS on a Linux Machine
This guide explains three practical methods for setting up DNS resolution on Linux—editing the local hosts file, modifying the system's resolv.conf, and configuring network interface files—along with the precedence order and necessary service restarts.
This article assumes you have already set up a DNS server and shows three ways to configure DNS resolution on a Linux machine.
IP addresses identify sites on a network; domain names are used for easier memorization, and DNS (Domain Name System) converts domain names to IP addresses.
There are three methods to configure DNS on Linux, after which automatic resolution works.
Local hosts
Edit the local /etc/hosts file (or C:\WINDOWS\system32\drivers\etc\hosts on Windows) to map domain names to IP addresses.
$ vim /etc/hosts
123.123.123.123 www.baidu.com
124.123.123.123 www.qq.comSystem default DNS configuration
Modify the /etc/resolv.conf file and add multiple nameserver entries, for example:
$ vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 123.123.123.123Network interface configuration file
Assuming the network interface is eth0, edit /etc/sysconfig/network-scripts/ifcfg-eth0 to add DNS rules:
$ vim /etc/sysconfig/network-scripts/ifcfg-eth0
# add rules, e.g.:
DNS1=114.114.114.114
DNS2=xxx.xxx.xxx.xxx
DNS3=xxx.xxx.xxx.xxxRestart the network service: $ service network restart After configuring DNS in /etc/sysconfig/network-scripts/ifcfg-eth0 and restarting the service, the same DNS entries will be automatically generated in /etc/resolv.conf.
System resolution priority
The resolution order is: Local hosts > Network interface configuration > System default DNS configuration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
