How to Configure DNS on Linux: 3 Simple Methods for Reliable Internet
This guide explains three ways to set up DNS resolution on a Linux server—using the local hosts file, editing the system's resolv.conf, and configuring the network interface file—while also listing recommended domestic DNS servers and their priority order.
Overview
DNS (Domain Name System) translates domain names into IP addresses.
This article assumes a DNS server is already set up and shows how to configure DNS resolution on a Linux machine so users can access the Internet smoothly.
Three methods to configure DNS on Linux
1. Local hosts file
Edit /etc/hosts to map domain names to IP addresses.
vim /etc/hosts
123.123.123.123 www.baidu.com
124.123.123.123 www.qq.com2. System default DNS configuration
Edit the DNS client configuration file /etc/resolv.conf.
vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.83. Network interface configuration
Assuming the network interface is eth0, edit its configuration file to add DNS rules.
vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Add rules
DNS1=114.114.114.114
DNS2=8.8.8.8Restart the network to apply the changes:
service network restart # restart network to make configuration effectiveDNS resolution priority
Local hosts > Network interface configuration > System default DNS configuration
Recommended domestic DNS servers
114 DNS: 114.114.114.114 / 114.114.115.115
Google DNS: 8.8.8.8 / 8.8.4.4
Ali DNS: 223.5.5.5 / 223.6.6.6
OneDNS: 117.50.11.11 / 117.50.22.22
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
