当我ping 8.8.8.8
说:connect: Network is unreachable
$vi /etc/resolv/.conf
nameserver 8.8.8.8
nameserver 192.168.0.5
$vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth1
iface eth1 inet dhcp
auth eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.o
$ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
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: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 08:00:27:ac:81:49 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:63:e1:93 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.101/24 brd 192.168.56.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe63:e193/64 scope link
valid_lft forever preferred_lft forever
答案1
从您的地址来看192.168.56.*
,您正在 VirtualBox 映像中运行,并且您想知道为什么当您的主机有连接时映像却没有连接。
您可能已将第一个 eth0 接口设置为“NAT”或“桥接”,并将其连接到主机的以太网接口。如果您通过 wifi 上网,但桥接/NAT 配置为使用以太网卡,则您将无法连接网络;反之亦然。
更改虚拟机的网络接口以使用正确的主机接口。