![VirtualBox 桥接网络:当我的笔记本电脑连接 Wifi 时无法工作](https://linux22.com/image/110624/VirtualBox%20%E6%A1%A5%E6%8E%A5%E7%BD%91%E7%BB%9C%EF%BC%9A%E5%BD%93%E6%88%91%E7%9A%84%E7%AC%94%E8%AE%B0%E6%9C%AC%E7%94%B5%E8%84%91%E8%BF%9E%E6%8E%A5%20Wifi%20%E6%97%B6%E6%97%A0%E6%B3%95%E5%B7%A5%E4%BD%9C.png)
在我的虚拟机中,我有两个网络接口(都是桥接模式,我需要桥接模式,因为我想创建服务器)。其中之一是以太网 ( eth0
),另一个是 WiFi ( wlan0
) - 在客户机 (CentOS) 中,它们表示为enp0s3
和enp0s8
。
我为它们设置了静态 IP,但只有当我的笔记本电脑连接到以太网电缆时该连接才有效。当我移除它并且笔记本电脑切换到 WiFi 时,即使有接口enp0s8
(在 VirtualBox 配置中为wlan0
),我也会遇到问题
主机:Ubuntu 14.04 客户机:CentOS
VirtualBox 网络设置:
* Adapter 1:
* Mode: Bridge
* eth0
* Network Card: Intel PRO/1000 MT Desktop (82540EM)
* MAC: 080027BAC610
* Adapter 2
* Mode: Bridge
* wlan0
* Network Card: Intel PRO/1000 MT Desktop (82540EM)
* MAC: 080027F97DAE
我已运行以下命令:
[root@localhost network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:ba:c6:10 brd ff:ff:ff:ff:ff:ff
inet 192.168.15.10/24 brd 192.168.15.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::99a9:d4a6:23c4:df9d/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:f9:7d:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.15.24/24 brd 192.168.15.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fef9:7dae/64 scope link
valid_lft forever preferred_lft forever
[root@localhost network-scripts]# tracepath 8.8.8.8
1?: [LOCALHOST] pmtu 1500
1: localhost.localdomain 3006.372ms !H
Resume: pmtu 1500
ifcfg-enp0s3
代表第一个适配器 ( eth0
)
[root@localhost network-scripts]# cat ifcfg-enp0s3
HWADDR=08:00:27:BA:C6:10
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.15.10
NETMASK=255.255.255.0
DEFROUTE=yes
PEERDNS=no
DNS1=8.8.8.8
DNS2=8.8.4.4
GATEWAY=192.168.15.1
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=no
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME="enp0s3"
UUID=6136f542-2b00-3fbd-a076-b80757d67316
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
ifcfg-enp0s8
代表第二个适配器 ( wlan0
)。
DEVICE=enp0s8
BOOTPRO=static
ONBOOT=yes
HWADDR=08:00:27:F9:7D:AE
IPADDR=192.168.15.24
NETMASK=255.255.255.0
GATEWAY=192.168.15.1
我们还有命令ip r
和结果/etc/resolv.conf
[root@localhost network-scripts]# ip r
default via 192.168.15.1 dev enp0s3 proto static metric 100
default via 192.168.15.1 dev enp0s8 proto static metric 101
192.168.15.0/24 dev enp0s3 proto kernel scope link src 192.168.15.10 metric 100
192.168.15.0/24 dev enp0s8 proto kernel scope link src 192.168.15.24 metric 101
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4
无论是否插入以太网电缆,如何才能使连接正常工作?
答案1
在同一网络上拥有两个连接需要小心(如果 eth 连接位于同一网络上,为什么系统会路由到/从 wifi 连接)。尝试将以太网移至与 WiFi 不同的网络。
如果您不控制网络,因此无法更改地址,请关闭 eth 接口,然后尝试路由:
sudo ip link set eth0 down