How to modify dns in linux

WBOY
WBOYOriginal
2022-01-27 15:19:1435756browse

Method: 1. Use the "vi /etc/resolv.conf" command to modify the dns; 2. Use the "vi /etc/sysconfig/network-scripts/ifcfg-eth0" command to modify the dns entry content in the file , restart the network card after modification to take effect.

How to modify dns in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to modify dns in Linux

Method 1. Modify /etc/resolv.conf (recommended)

[root@bin ~]# vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

The modification will take effect immediately, no need Do any additional processing! Therefore, this method is more recommended.

Method 2. Modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file

[root@bin ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
DNS2=8.8.4.4
TYPE=Ethernet
DNS1=8.8.8.8
IPV6INIT=no
USERCTL=no
PEERDNS=yes

This method requires restarting the network card to take effect. Restarting the network card can be used. The following command:

service network restart

How to check the local DNS

1. Check the /etc/resolv.con file

[oboth@localhost ~]$ cat /etc/resolv.conf 
nameserver 114.114.114.114
nameserver 8.8.8.8

2. Use the nslookup command View DNS information

[oboth@localhost ~]$ nslookup qq.com
Server:        114.114.114.114
Address:    114.114.114.114#53
Name:    qq.com
Address: 123.151.137.18
Name:    qq.com
Address: 61.129.7.47
Name:    qq.com
Address: 183.3.226.35

3. Use the dig command to view DNS information

[oboth@localhost ~]$ dig
; <<>> DiG 9.11.25-RedHat-9.11.25-2.fc33 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27276
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;.    IN    NS
;; ANSWER SECTION:
.    3359    IN    NS    l.root-servers.net.
.    3359    IN    NS    j.root-servers.net.
.    3359    IN    NS    g.root-servers.net.
.    3359    IN    NS    a.root-servers.net.
.    3359    IN    NS    i.root-servers.net.
.    3359    IN    NS    f.root-servers.net.
.    3359    IN    NS    k.root-servers.net.
.    3359    IN    NS    h.root-servers.net.
.    3359    IN    NS    e.root-servers.net.
.    3359    IN    NS    b.root-servers.net.
.    3359    IN    NS    d.root-servers.net.
.    3359    IN    NS    m.root-servers.net.
.    3359    IN    NS    c.root-servers.net.
;; Query time: 59 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: 一 2月 01 18:02:15 CST 2021
;; MSG SIZE rcvd: 239

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to modify dns in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn