一台Linux
局域网服务器,突然发现不能访问外网,也许本来就不行,因为没有用到外网,所以只是没有注意到吧!经过测试外网无法访问,内网畅行无阻。如下:
[root@offline-200 services]# wget baidu.com
–2020-11-03 17:56:58– http://baidu.com/
正在解析主机 baidu.com (baidu.com)… 失败:未知的名称或服务。
wget: 无法解析主机地址 “baidu.com”
[root@offline-200 services]# ping 192.168.2.3
PING 192.168.2.3 (192.168.2.3) 56(84) bytes of data.
64 bytes from 192.168.2.3: icmp_seq=1 ttl=128 time=0.305 ms
64 bytes from 192.168.2.3: icmp_seq=2 ttl=128 time=0.245 ms
64 bytes from 192.168.2.3: icmp_seq=3 ttl=128 time=0.211 ms
64 bytes from 192.168.2.3: icmp_seq=4 ttl=128 time=0.255 ms
64 bytes from 192.168.2.3: icmp_seq=5 ttl=128 time=0.353 ms
— 192.168.2.3 ping statistics —
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.211/0.273/0.353/0.053 ms
[root@offline-200 services]# ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=255 time=1.39 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=255 time=1.47 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=255 time=1.43 ms
— 192.168.2.1 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.393/1.433/1.470/0.031 ms
首先,检查DNS
服务器是否设置且是否设置正确。
cat /etc/resolv.conf
如下所示,DNS
只是一个局域网的服务器。具体之前为什么这么设置,现在也搞不清楚。
[root@offline-200 services]# cat /etc/resolv.conf
Generated by NetworkManager
search host.com
nameserver 192.168.2.200
不管之前是什么原因,现在使用vi
进行编辑新加两个DNS
服务器。
cat /etc/resolv.conf
#阿里DNS服务器
nameserver 223.5.5.5
nameserver 223.6.6.6
[root@offline-200 services]# vi /etc/resolv.conf
[root@offline-200 services]# cat /etc/resolv.conf
Generated by NetworkManager
search host.com
nameserver 192.168.2.200
nameserver 223.5.5.5
nameserver 223.6.6.6
新加DNS
服务器之后保存,测试访问外网通过。
curl www.baidu.com