阅读量:0
一.前言
ping某个域名提示Name or service not known的错误,或者是curl 域名提示Could not resolve host的错误。这种问题通常是由于域名解析或网络连接问题引起的。
二.问题原因
这个问题可能有几种原因导致。
1.DNS 配置问题:确保计算机或网络设备的DNS配置正确
2.检查域名拼写:确保输入的域名没有拼写错误。
3.网络连接问题:检查服务器的网络连接,确保网络正常工作,尝试访问其他网站来确认网络连接是否正常。
4.防火墙设置:有时候防火墙设置可能会阻止 ping 命令的访问。可以检查服务器的防火墙设置,确保 ICMP 协议被允许。这块请注意,在开放 ICMP 流量之前,请确保了解潜在的安全风险,并采取适当的安全措施。这块建议联系网络专业人员处理。
三.解决方法
这边讲解下dns配置的问题。本机访问不了域名,其他机子能访问域名的话。那就是本机dns配置有问题导致。
1.我们先确认下,相关网络的配置
[root@zhangke network-scripts]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:06:98:07 brd ff:ff:ff:ff:ff:ff inet 192.168.87.100/24 brd 192.168.87.255 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe06:9807/64 scope link valid_lft forever preferred_lft forever 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:f0:96:3b brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:f0:96:3b brd ff:ff:ff:ff:ff:ff
2.调整ifcfg-ens33 的配置文件,添加dns
[root@zhangke network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="fa0fd218-d068-423e-a01c-eaa4994667a9" DEVICE="ens33" ONBOOT="yes" IPADDR=192.168.87.100 NETMASK=255.255.255.0 GATEWAY=192.168.87.2 DNS1=192.168.87.2 DNS2=8.8.8.8
3.重启网络
[root@zhangke network-scripts]# service network restart
4.效果
[root@zhangke network-scripts]# ping www.baidu.com ping: www.baidu.com: 未知的名称或服务 [root@zhangke network-scripts]# vim ifcfg-ens33 [root@zhangke network-scripts]# service network restart Restarting network (via systemctl): [ 确定 ] [root@zhangke network-scripts]# ping www.baidu.com PING www.a.shifen.com (36.155.132.3) 56(84) bytes of data. 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=1 ttl=128 time=19.6 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=2 ttl=128 time=22.9 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=3 ttl=128 time=23.7 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=4 ttl=128 time=21.3 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=5 ttl=128 time=23.9 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=6 ttl=128 time=21.9 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=7 ttl=128 time=23.3 ms 64 bytes from 36.155.132.3 (36.155.132.3): icmp_seq=8 ttl=128 time=24.0 ms ^C --- www.a.shifen.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7012ms