Operations 3 min read

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.

Open Source Linux
Open Source Linux
Open Source Linux
How to Configure DNS on Linux: 3 Simple Methods for Reliable Internet

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.com

2. 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.8

3. 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.8

Restart the network to apply the changes:

service network restart  # restart network to make configuration effective

DNS 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxNetwork Configurationhosts file
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.