我有两个 Debian 虚拟机,分别名为“服务器”和“客户端”。设置大致相同。
当我ping debian.org
在“服务器”上时,我没有遇到任何问题,但当我ping debian.org
在“客户端”上尝试时,我收到“名称解析暂时失败”错误。但是 ping IP 地址可以正常工作。
我在“客户端”上的设置:
hans@client:~$ ip a s enp1s0
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:2b:40:ab brd ff:ff:ff:ff:ff:ff
inet 192.168.122.76/24 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 3273sec preferred_lft 3273sec
inet6 fe80::5054:ff:fe2b:40ab/64 scope link
valid_lft forever preferred_lft forever
hans@client:~$ ip r
default via 192.168.122.1 dev enp1s0
192.168.122.0/24 dev enp1s0 proto kernel scope link src 192.168.122.76
hans@client:~$ cat /etc/resolv.conf
nameserver 192.168.122.1
hans@client:~$ ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 25 May 28 06:46 /etc/resolv.conf
hans@client:~$
我在“服务器”上的设置:
hans@server:~$ ip a s enp1s0
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:fa:5f:f7 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.153/24 brd 192.168.122.255 scope global dynamic enp1s0
valid_lft 2905sec preferred_lft 2905sec
inet6 fe80::5054:ff:fefa:5ff7/64 scope link
valid_lft forever preferred_lft forever
hans@server:~$ ip r
default via 192.168.122.1 dev enp1s0
192.168.122.0/24 dev enp1s0 proto kernel scope link src 192.168.122.153
hans@server:~$ cat /etc/resolv.conf
nameserver 192.168.122.1
hans@server:~$ ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 25 May 28 06:46 /etc/resolv.conf
hans@server:~$
正在 ping “客户端”:
hans@client:~$ ping debian.org
ping: debian.org: Temporary failure in name resolution
hans@client:~$ ping 149.20.4.15
PING 149.20.4.15 (149.20.4.15) 56(84) bytes of data.
64 bytes from 149.20.4.15: icmp_seq=1 ttl=52 time=263 ms
64 bytes from 149.20.4.15: icmp_seq=2 ttl=52 time=256 ms
64 bytes from 149.20.4.15: icmp_seq=3 ttl=52 time=257 ms
--- 149.20.4.15 ping statistics ---
^C3 packets transmitted, 3 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 256.464/258.557/262.566/2.835 ms
hans@client:~$
正在 Ping “服务器”:
hans@server:~$ ping debian.org
PING debian.org (149.20.4.15) 56(84) bytes of data.
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=1 ttl=52 time=258 ms
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=2 ttl=52 time=257 ms
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=3 ttl=52 time=257 ms
^C
--- debian.org ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 8ms
rtt min/avg/max/mdev = 256.509/257.156/257.560/0.746 ms
hans@server:~$
ping 网关也有效:
hans@client:~$ ping 192.168.122.1
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.995 ms
64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.837 ms
64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.782 ms
^C
--- 192.168.122.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 7ms
rtt min/avg/max/mdev = 0.782/0.871/0.995/0.093 ms
hans@client:~$
两台主机上的 /etc/nsswitch.conf 文件相同。
答案1
我检查了我的命令历史记录,发现我配置了防火墙规则。真是太傻了。