可以 ping 通除 localhost 之外的任何主机。怎么了?

可以 ping 通除 localhost 之外的任何主机。怎么了?

我在服务器上新安装了一个红帽盒子。

我可以使用 ip 和服务器名称 ping 网络上的另一台计算机,但无法 ping localhost、127.0.0.1 或 192.168.4.42(本地 ip)

[root@comp2 ~]# ping comp1
PING vcas1 (192.168.4.41) 56(84) bytes of data.
64 bytes from vcas1 (192.168.4.41): icmp_seq=1 ttl=64 time=0.104 ms
64 bytes from vcas1 (192.168.4.41): icmp_seq=2 ttl=64 time=0.100 ms

--- comp1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.100/0.102/0.104/0.002 ms
[root@comp2 ~]# 

[root@comp2 ~]# ping 192.168.4.41
PING 192.168.4.41 (192.168.4.41) 56(84) bytes of data.
64 bytes from 192.168.4.41: icmp_seq=1 ttl=64 time=0.119 ms
64 bytes from 192.168.4.41: icmp_seq=2 ttl=64 time=0.105 ms

--- 192.168.4.41 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.105/0.112/0.119/0.007 ms

但我无法 ping 本地主机或本地 IP 地址。

[root@comp2 ~]# ping 192.168.4.42
PING 192.168.4.42 (192.168.4.42) 56(84) bytes of data.

--- 192.168.4.42 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms
PING comp2 (192.168.4.42) 56(84) bytes of data.

--- comp2 ping statistics ---
17 packets transmitted, 0 received, 100% packet loss, time 15999ms

[root@comp2 ~]# ping 192.168.4.42
PING 192.168.4.42 (192.168.4.42) 56(84) bytes of data.

--- 192.168.4.42 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

[root@comp2 ~]# ping localhost
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.

--- localhost.localdomain ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

这是我的/etc/hosts

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.4.41    comp1
192.168.4.42    comp2

最后这是我的 ifconfig:

[root@comp2 ~]# /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:26:55:D4:4E:81  
          inet addr:10.0.0.14  Bcast:10.127.255.255  Mask:255.128.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:271591 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3079 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:16571921 (15.8 MiB)  TX bytes:228424 (223.0 KiB)
          Memory:fbfa0000-fbfc0000 

eth1      Link encap:Ethernet  HWaddr 00:26:55:D4:4E:80  
          inet addr:192.168.4.42  Bcast:192.168.4.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:174349 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34537 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12202232 (11.6 MiB)  TX bytes:3230241 (3.0 MiB)
          Memory:fbfe0000-fc000000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16398 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16398 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:829344 (809.9 KiB)  TX bytes:829344 (809.9 KiB)

这是怎么回事?

编辑:

[root@comp2 ~]# /sbin/iptables -F
[root@comp2 ~]# /etc/init.d/iptables stop
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
[root@comp2 ~]# ping localhost
PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.

--- localhost.localdomain ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 4999ms

依然没有。

[root@comp2 ~]#/sbin/ip route show
192.168.4.0/24 dev eth1  proto kernel  scope link  src 192.168.4.42 
169.254.0.0/16 dev eth1  scope link 
10.0.0.0/9 dev eth0  proto kernel  scope link  src 10.0.0.14 
default via 10.0.0.1 dev eth0 

[root@comp2 ~]# /sbin/route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.4.0     *               255.255.255.0   U     0      0        0 eth1
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
10.0.0.0        *               255.128.0.0     U     0      0        0 eth0
default         VideoGateway.Om 0.0.0.0         UG    0      0        0 eth0

新的:

这是我应该已经完成​​的事情,但同样从服务器 comp1 (192.168.4.41) 开始,我无法 ping comp2(192.168.4.42)

答案1

需要的是路由表重新配置。更新GATEWAY中的变量 /etc/sysconfig/networking-scripts/ifcfg-ethX/etc/sysconfig/networking-scripts/route-ethX还需要更新路线信息。更新文件中正确且正确的网络配置后,重新启动network/sbin/service network restart使新的网络配置在接口上生效。

答案2

检查以下命令的输出。

cat /proc/sys/net/ipv4/icmp_echo_ignore_all

如果是 1 则执行以下操作。

echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

要永久存储它,请执行以下操作。

echo "net.ipv4.icmp_echo_ignore_all=0" >> /etc/sysctl.conf

如果值为icmp_echo_ignore_all1,则内核会忽略 ICMP ECHO 请求。一些系统管理员禁用 ping 回复以避免 ping 洪水 ( ping -f)。

答案3

看来你的lo界面还没有调出来。请尝试以下命令:

ifup lo

或者

ifup -a

相关内容