DNS(Domain Name System,域名系統),因特網上做爲域名和IP地址相互映射的一個分佈式數據庫,可以使用戶更方便的訪問互聯網,而不用去記住可以被機器直接讀取的IP數串。node
一臺主機的dns服務器的好壞會直接影響咱們上網的速度以及網站的訪問,今天咱們一塊兒來看一下如何爲Linux系統配置好用的公共DNS.linux
1. 查看服務器的DNS方法一,查看配置文件,輸入命令cat /etc/resolv.conf,從結構中能夠看到DNS是221.4.8.1,備用DNS是0.0.0.0數據庫
EC20 openLinux system
1 root@mdm9607-perf:/# cat /etc/resolv.conf 2 nameserver 221.4.8.1 3 nameserver 0.0.0.0 4 nameserver 221.4.8.1 5 nameserver 0.0.0.0 6 root@mdm9607-perf:/#
ubuntu system:ubuntu
1 open_linux@quectel-sz-server:/etc/systemd/system$ cat /etc/resolv.conf 2 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) 3 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN 4 nameserver 127.0.1.1 5 open_linux@quectel-sz-server:/etc/systemd/system$
2. 方法二,查看使用nslookup命令,輸入命令:nslookup www.yahoo.comvim
EC20 OpenLinux system:服務器
1 root@mdm9607-perf:/# nslookup www.yahoo.com 2 Server: 221.4.8.1 3 Address 1: 221.4.8.1 4 5 Name: www.yahoo.com 6 Address 1: 124.108.103.104 media-router-fp2.prod1.media.vip.tp2.yahoo.com 7 Address 2: 124.108.103.103 media-router-fp1.prod1.media.vip.tp2.yahoo.com 8 Address 3: 2406:2000:ec:815::4 media-router-fp2.prod1.media.vip.tp2.yahoo.com 9 Address 4: 2406:2000:ec:815::3 media-router-fp1.prod1.media.vip.tp2.yahoo.com
ubuntu system:dom
1 open_linux@quectel-sz-server:/etc/systemd/system$ nslookup www.yahoo.com 2 Server: 127.0.1.1 3 Address: 127.0.1.1#53 4 5 Non-authoritative answer: 6 www.yahoo.com canonical name = atsv2-fp-shed.wg1.b.yahoo.com. 7 Name: atsv2-fp-shed.wg1.b.yahoo.com 8 Address: 124.108.103.104 9 Name: atsv2-fp-shed.wg1.b.yahoo.com 10 Address: 124.108.103.103
3. 方法三:dig命令查看dig |grep SERVER分佈式
EC20 OpenLinux system:oop
1 root@mdm9607-perf:/# dig | grep SERVER 2 -sh: dig: not found
Ubuntu system:網站
1 open_linux@quectel-sz-server:/etc/systemd/system$ dig | grep SERVER 2 ;; SERVER: 127.0.1.1#53(127.0.1.1)
4方法四:ip route show
1 /usrdata # ip route show 2 default via 10.228.16.250 dev rmnet_data2 3 default via 10.226.190.201 dev rmnet_data0 4 10.51.131.200/29 dev rmnet_data1 proto kernel scope link src 10.51.131.204 5 10.226.190.192/28 dev rmnet_data0 scope link 6 10.228.16.248/30 dev rmnet_data2 proto kernel scope link src 10.228.16.249 7 192.168.225.0/24 dev bridge0 proto kernel scope link src 192.168.225.1
5. 修改DNS服務器配置,vim編輯配置文件/etc/solve.conf
6. 將IP地址改成你想要的DNS服務器的IP,以下方我改的是首選是x.x.x.x,備選是x.x.x.x,修改後保存並退出
7. 使用nslookup 命令檢驗是否配置成功:
8. hosts主機表文件
跟Windows系統同樣,Linux系統也有主機表文件。一樣能夠經過設置主機表地址進行特定主機的解析,優先DNS服務器地址。配置文件,在/etc/hosts
ubuntu system:
1 open_linux@quectel-sz-server:/etc$ cat hosts 2 127.0.0.1 localhost 3 127.0.1.1 quectel-sz-server 4 5 # The following lines are desirable for IPv6 capable hosts 6 ::1 ip6-localhost ip6-loopback 7 fe00::0 ip6-localnet 8 ff00::0 ip6-mcastprefix 9 ff02::1 ip6-allnodes 10 ff02::2 ip6-allrouters
EC20 OpenLinux system:
1 root@mdm9607-perf:/# cat /etc/hosts 2 127.0.0.1 localhost.localdomain localhost 3 192.168.225.1 mobileap.qualcomm.com
9,總結:
Linux下設置DNS的位置主要是,
1). 系統默認DNS服務器地址設置。2). hosts文件指定
生效順序是:
1 hosts文件 ---- 2 /etc/resolv.conf
注意:
-
Linux修改dns是否是更加的簡單,只須要修改一下配置文件/etc/resolv.conf便可
-
修改好後須要重啓電腦系統嗎?答案是不須要的,配置好保存即生效