hunkier

学习笔记,开源代码,技术分享

CentOS 7 设置DNS服务器

CentOS 7需要使用全新的命令行工具 nmcli 来设置

显示当前网络连接
1
2
3
4
5
6
[root@bogon ~]# nmcli connection show
NAME UUID TYPE DEVICE
cni0 b2b8f5f9-acd2-42fd-9ec9-a76282425cd9 bridge cni0
docker0 33ebd49e-fd1b-4a2c-8261-c0463f4f4146 bridge docker0
enp2s0 b6579214-0ba6-4bf0-9319-2e0e4f584afd ethernet enp2s0
virbr0 976717ae-c3ae-4582-aa09-039c26bef80d bridge virbr0
修改当前网络连接对应的DNS服务器,这里的网络连接可以用名称或者UUID来标识
1
2
[root@bogon ~]# nmcli con mod enp2s0  ipv4.dns "114.114.114.114 8.8.8.8"
[root@bogon ~]#
将dns配置生效
1
2
[root@bogon ~]# nmcli con up enp2s0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
测试网络
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@bogon ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=53 time=5.48 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=53 time=5.60 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=53 time=5.48 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=53 time=8.57 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=53 time=5.54 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 5.485/6.138/8.575/1.222 ms
[root@bogon ~]#

谢谢你请我喝牛奶

欢迎关注我的其它发布渠道