centos虚拟机,今天在这个虚拟机中用curl查看http消息:
$curl -I http://www.baidu.com
结果提示
curl: (6) Could not resolve host
尝试ping一下 www.baidu.com ,出现提示:ping: www.baidu.com: Name or service not known,查阅资料,原来是该虚拟机未配置DNS服务器的原因。继而又去查询资料,看看DNS服务器如何配置,下面是配置DNS服务器的方法:
1、首先查看当前的网络连接
nmcli connection show
结果显示网络设备为enp0s3 2、设置DNS服务器
nmcli con mod enp0s3 ipv4.dns "114.114.114.114 8.8.8.8"
3、使DNS配置生效
nmcli con up enp0s3
4、查看/etc/resolv.conf文件,看看是否有DNS服务器的配置(原先该文件没有任何信息)
遇到这种情况用,UUID
[root@bogon ~]# nmcli con mod enp0s3 ipv4.dns "114.114.114.114 8.8.8.8"
Error: unknown connection 'enp0s3'.
[root@bogon ~]# nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 3 0f10d725-4d90-32ad-bf1b-d8af80a491fe ethernet enp0s3
Wired connection 4 94e80a45-432f-3c9a-ae7a-daeb2f98d6d6 ethernet enp0s8
virbr0 44e956a7-4820-4f61-aab5-ac65a95f39af bridge virbr0
virbr0 6acb7da7-2cca-428e-86cf-9a5888da908c bridge --
Wired connection 1 cda2ea6f-ffa5-3225-a662-53daf72a3462 ethernet --
Wired connection 2 820bb71d-12e9-4cd9-80f6-3b87361367b0 ethernet --
[root@bogon ~]# nmcli con mod Wired ipv4.dns "114.114.114.114 8.8.8.8"
Error: unknown connection 'Wired'.
[root@bogon ~]# nmcli con mod 3 ipv4.dns "114.114.114.114 8.8.8.8"
Error: unknown connection '3'.
[root@bogon ~]# nmcli con mod 0f10d725-4d90-32ad-bf1b-d8af80a491fe ipv4.dns "114.114.114.114 8.8.8.8"
[root@bogon ~]# nmcli con up 0f10d725-4d90-32ad-bf1b-d8af80a491fe
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@bogon ~]# ping docs.zshu.tech
PING docs.zshu.tech (10.15.1.11) 56(84) bytes of data.
64 bytes from bogon (10.15.1.11): icmp_seq=1 ttl=61 time=9.99 ms
64 bytes from bogon (10.15.1.11): icmp_seq=2 ttl=61 time=10.4 ms
64 bytes from bogon (10.15.1.11): icmp_seq=3 ttl=61 time=13.7 ms
64 bytes from bogon (10.15.1.11): icmp_seq=4 ttl=61 time=10.3 ms
64 bytes from bogon (10.15.1.11): icmp_seq=5 ttl=61 time=10.9 ms
64 bytes from bogon (10.15.1.11): icmp_seq=6 ttl=61 time=10.7 ms
64 bytes from bogon (10.15.1.11): icmp_seq=7 ttl=61 time=8.02 ms