我有一个FreeBSD 8.2虚拟机(Virtual Box 4.1.4),有两个networking接口,一个连接到我的以太网卡,另一个连接到主机操作系统(Mac OSX Lion 10.7.2)上的WiFi。 在VM中,我将前两个networking接口( em0和em1 )分配给静态IP地址,并将默认路由器IP设置为路由器的IP,如下面的configuration中所示:
/etc/rc.conf :
inetd_enable="NO" sshd_enable="YES" ifconfig_em0="inet 192.168.1.109 netmask 255.255.255.0" ifconfig_em1="inet 192.168.1.129 netmask 255.255.255.0" defaultrouter="192.168.1.1"
netstat -r :
Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 192.168.1.1 UGS 2 71 em0 127.0.0.1 link#3 UH 0 0 lo0 192.168.1.0/24 link#1 U 2 78 em0 192.168.1.109 link#1 UHS 0 0 lo0 192.168.1.129 link#2 UHS 0 0 lo0
使用上面的configuration,我可以从主机操作系统ssh到em0或em1 ,但是如果我拿下em0 :
sudo ifconfig em0 down
… em1失去了networking访问权限,好像它也被取消了一样。 也就是说,主机操作系统不能SSH到em1 ; 客户操作系统无法ping google.com或ping 192.168.1.130 (主机操作系统的IP)。
我在Ubuntu Server 11.10中没有这个问题:我可以为我的WiFi网桥设置一个静态IP,为我的以太网网桥设置一个dynamicIP; 并把他们中的任何一个都不影响对方。
在em0下来之前
$ ifconfig -a em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:16:4d:32 inet 192.168.1.109 netmask 0xffffff00 broadcast 192.168.1.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:3f:a7:44 inet 192.168.1.129 netmask 0xffffff00 broadcast 192.168.1.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=3<RXCSUM,TXCSUM> inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet6 ::1 prefixlen 128 inet 127.0.0.1 netmask 0xff000000 nd6 options=3<PERFORMNUD,ACCEPT_RTADV> $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ? (192.168.1.130) at c4:2c:03:2b:73:d1 on em0 expires in 314 seconds [ethernet]
在em0下来之后
$ ifconfig -a em0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:16:4d:32 inet 192.168.1.109 netmask 0xffffff00 broadcast 192.168.1.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 08:00:27:3f:a7:44 inet 192.168.1.129 netmask 0xffffff00 broadcast 192.168.1.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=3<RXCSUM,TXCSUM> inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet6 ::1 prefixlen 128 inet 127.0.0.1 netmask 0xff000000 nd6 options=3<PERFORMNUD,ACCEPT_RTADV> $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ? (192.168.1.130) at c4:2c:03:2b:73:d1 on em0 expires in 190 seconds [ethernet]
输出(按要求):
@host : ~/tmp $ 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=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=2b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4> ether c4:2c:03:2b:73:d1 inet6 fe80::c62c:3ff:fe2b:73d1%en0 prefixlen 64 scopeid 0x4 inet 192.168.1.130 netmask 0xffffff00 broadcast 192.168.1.255 media: autoselect (100baseTX <full-duplex,flow-control>) status: active fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078 lladdr d8:a2:5e:ff:fe:f2:f9:d4 media: autoselect <full-duplex> status: inactive en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether d8:30:62:58:93:7d inet6 fe80::da30:62ff:fe58:937d%en1 prefixlen 64 scopeid 0x6 inet 192.168.1.146 netmask 0xffffff00 broadcast 192.168.1.255 media: autoselect status: active p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304 ether 0a:30:62:58:93:7d media: autoselect status: active vboxnet0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 0a:00:27:00:00:00 @host : ~/tmp $ sudo arp -ad 192.168.1.1 (192.168.1.1) deleted 192.168.1.109 (192.168.1.109) deleted @host : ~/tmp $ arp -an ? (192.168.1.1) at 0:1d:7e:f8:1c:dd on en0 ifscope [ethernet] @host : ~/tmp $ ping -c3 192.168.1.109 PING 192.168.1.109 (192.168.1.109): 56 data bytes 64 bytes from 192.168.1.109: icmp_seq=0 ttl=64 time=0.418 ms 64 bytes from 192.168.1.109: icmp_seq=1 ttl=64 time=0.457 ms 64 bytes from 192.168.1.109: icmp_seq=2 ttl=64 time=0.468 ms --- 192.168.1.109 ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.418/0.448/0.468/0.021 ms @host : ~/tmp $ ping -c3 192.168.1.129 PING 192.168.1.129 (192.168.1.129): 56 data bytes 64 bytes from 192.168.1.129: icmp_seq=0 ttl=64 time=104.138 ms 64 bytes from 192.168.1.129: icmp_seq=1 ttl=64 time=22.004 ms 64 bytes from 192.168.1.129: icmp_seq=2 ttl=64 time=44.780 ms --- 192.168.1.129 ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 22.004/56.974/104.138/34.622 ms @host : ~/tmp $ arp -an ? (192.168.1.1) at 0:1d:7e:f8:1c:dd on en0 ifscope [ethernet] ? (192.168.1.109) at 8:0:27:16:4d:32 on en0 ifscope [ethernet] ? (192.168.1.129) at d8:30:62:58:93:7d on en0 ifscope [ethernet] ############################# # GUEST em0 down here ############################# @host : ~/tmp $ arp -an ? (192.168.1.1) at 0:1d:7e:f8:1c:dd on en0 ifscope [ethernet] ? (192.168.1.109) at 8:0:27:16:4d:32 on en0 ifscope [ethernet] ? (192.168.1.129) at d8:30:62:58:93:7d on en0 ifscope [ethernet] @host : ~/tmp $ sudo arp -ad 192.168.1.1 (192.168.1.1) deleted 192.168.1.109 (192.168.1.109) deleted 192.168.1.129 (192.168.1.129) deleted @host : ~/tmp $ ping -c3 192.168.1.129 PING 192.168.1.129 (192.168.1.129): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 --- 192.168.1.129 ping statistics --- 3 packets transmitted, 0 packets received, 100.0% packet loss @host : ~/tmp $ arp -an ? (192.168.1.1) at 0:1d:7e:f8:1c:dd on en0 ifscope [ethernet] ? (192.168.1.129) at d8:30:62:58:93:7d on en0 ifscope [ethernet] ################### GUEST OS @guest : ~/tmp $ sudo arp -ad 192.168.1.129 (192.168.1.129) deleted @guest : ~/tmp $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ############################# # HOST pings .109 and .129 here ############################# @guest : ~/tmp $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ? (192.168.1.130) at c4:2c:03:2b:73:d1 on em0 expires in 1188 seconds [ethernet] @guest : ~/tmp $ sudo ifconfig em0 down @guest : ~/tmp $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ? (192.168.1.130) at c4:2c:03:2b:73:d1 on em0 expires in 1170 seconds [ethernet] @guest : ~/tmp $ sudo arp -ad 192.168.1.129 (192.168.1.129) deleted delete: cannot locate 192.168.1.130 ############################# # HOST pings .129 here ############################# @guest : ~/tmp $ arp -an ? (192.168.1.129) at 08:00:27:3f:a7:44 on em1 permanent [ethernet] ? (192.168.1.130) at c4:2c:03:2b:73:d1 on em0 expires in 1095 seconds [ethernet]
你在做什么是很奇怪的:
1)你有不同的接口可以访问同一个子网,这将使你的生活有点困难的某些types的服务器软件
2)当你放192.168.1.0/24的接口时,你应该修改路由:
sudo route add -net 192.168.1.0/24 -iface em1
你的问题的一个非常简单的解决scheme是使用链接聚合技术。
有lagg(4)设备与故障转移模式。 从我的笔记本configuration,始终停留在最快的可用链接:
ifconfig_em0="ether 00:26:c7:xx:xx:xx" ifconfig_wlan0="WPA" cloned_interfaces="lagg0" ifconfig_lagg0="laggproto failover laggport em0 laggport wlan0 DHCP"
在你的情况下,你应该与em0和em1 。 另外请注意,我设置em0 MAC与我的无线网卡相同。
作为另一种解决scheme,您可以在主机和来宾操作系统(例如OSPF)之间build立一个IGP。