Centos7设置DNS

Posted by BenderFly on February 17, 2020

显示当前网络连接

nmcli connection show

修改当前网络连接对应的DNS服务器,这里的网络连接可以用名称或者UUID来标识,二个NDS根据需求修改,一般添加这二个就可以。

nmcli con mod ens160 ipv4.dns "114.114.114.114 8.8.8.8"

将dns配置生效

nmcli con up ens160
[root@auto-test2 network-scripts]# nmcli connection show
NAME    UUID                                  TYPE            DEVICE 
ens160  0bd6ac7c-a5aa-4aef-ad6d-2a62949be537  802-3-ethernet  ens160 

[root@auto-test2 network-scripts]# nmcli con mod ens160 ipv4.dns "114.114.114.114 8.8.8.8"


[root@auto-test2 network-scripts]# nmcli con up ens160
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

[root@auto-test2 network-scripts]# ping www.baidu.com
PING www.a.shifen.com (220.181.111.188) 56(84) bytes of data.
bytes from 220.181.111.188 (220.181.111.188): icmp_seq=1 ttl=52 time=2.13 ms
bytes from 220.181.111.188 (220.181.111.188): icmp_seq=2 ttl=52 time=2.04 ms
bytes from 220.181.111.188 (220.181.111.188): icmp_seq=3 ttl=52 time=2.01 ms
bytes from 220.181.111.188 (220.181.111.188): icmp_seq=4 ttl=52 time=3.38 ms
bytes from 220.181.111.188 (220.181.111.188): icmp_seq=5 ttl=52 time=2.58 ms

参考