具有桥接适配器的虚拟机到 Centos 不接受来自主机的 ssh

具有桥接适配器的虚拟机到 Centos 不接受来自主机的 ssh

我在 VirtualBox 上建立了从 os/x 10.8.5 主机到 Centos 5.8 客户端的桥接连接。

但我怀疑这是一个普遍问题,而不是特定于主机和 Linux 的精确版本的问题。

下面显示的是 VirtualBox 和客户机内的网络信息

sshd 在端口 22 上运行:

[root@oracle-linux ~]# ps -ef | grep sshd | grep -v grep
root      3103     1  0 20:22 ?        00:00:00 /usr/sbin/sshd
root     14994  3103  0 21:23 ?        00:00:00 sshd: root@pts/1 

网络状态:

[root@oracle-linux ~]# netstat -an |  grep tcp | grep LIST
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:954                 0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      

防火墙已禁用:

[root@oracle-linux init.d]# service iptables status
Firewall is stopped.

以下是 GUEST 的 IP 地址(更改为 BRIDGE 之后):

[root@oracle-linux ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:B9:E5:79  
          inet addr:10.0.15.100  Bcast:10.0.15.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:feb9:e579/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:6754 (6.5 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:B4:86:8A  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1064 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1064 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1799516 (1.7 MiB)  TX bytes:1799516 (1.7 MiB)

主持人:

c1166313@ma2-gbip-lap105's password: 
06:46:37/shared:7 $ifconfig -a
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether b8:f6:b1:15:dd:bf 
    inet6 fe80::baf6:b1ff:fe15:ddbf%en0 prefixlen 64 scopeid 0x4 
    inet 10.0.0.7 netmask 0xffffff00 broadcast 10.0.0.255
    media: autoselect
    status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
    ether 0a:f6:b1:15:dd:bf 
    media: autoselect
    status: inactive
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 0a:00:27:00:00:00 
    inet 192.168.7.1 netmask 0xffffff00 broadcast 192.168.7.255

我可以从客户机 ssh 到客户机:

root@oracle-linux ~]# ssh 10.0.3.15
The authenticity of host '10.0.3.15 (10.0.3.15)' can't be established.
RSA key fingerprint is ef:08:19:72:95:4d:e5:28:af:f3:6f:54:07:84:ba:04.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.3.15' (RSA) to the list of known hosts.
[email protected]'s password: 
Last login: Mon Oct 21 21:24:12 2013 from 10.0.15.100

但无法从主机 ssh 到客户机:

18:27:04/shared:11 $ssh  [email protected]
ssh: connect to host 10.0.15.100 port 22: Operation timed out
lost connection

这是桥接连接信息;

在此处输入图片描述

适配器 2 是 NAT,如下所示

在此处输入图片描述

如果 NAT 导致任何问题,我会将其关闭并重新启动网络。

[root@oracle-linux ~]# /etc/init.d/network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:  

还是没有快乐..

18:27:04/shared:11 $ssh  [email protected]
ssh: connect to host 10.0.15.100 port 22: Operation timed out
lost connection

顺便说一句:作为故障排除的一部分,我启动了另一个 Centos VM(版本 6.2)。这个 VM 来自不同的供应商(cloudera),但我也将其配置为桥接适配器。第二台 VM 运行良好。

07:03:23/shared:12 $ping  10.0.0.9
PING 10.0.0.9 (10.0.0.9): 56 data bytes
64 bytes from 10.0.0.9: icmp_seq=0 ttl=64 time=0.350 ms
64 bytes from 10.0.0.9: icmp_seq=1 ttl=64 time=0.337 ms
64 bytes from 10.0.0.9: icmp_seq=2 ttl=64 time=0.339 ms

答案1

问题是 /etc/network-scripts/ifcfg-eth0 设置了静态 IP 地址:

BOOTPROTO=static
BROADCAST=10.0.15.255

解决方案是删除这些并设置 dhcp:

BOOTPROTO=dhcp

注意:用户 CIA 开始在这里通过提及错误的访客子网来指引方向。

答案2

您可以为您的虚拟机指定主机到主机网络,并且您应该能够从主机 ssh 到客户机。

相关内容