如何在虚拟框中的 ubuntu 上配置网络接口?

Jos*_*osh 7 vmware networking virtualization virtualbox-networking

问题

如果您有多个适配器,如何配置 ubuntu 以便在启动时不会收到“正在等待网络配置...”消息

事实

  • 我在 Virtual Box 和 VM-Ware Workstation 中有一个未受影响的 Ubuntu。

  • 我的/etc/network/interfaces文件没有受到影响,我已经激活了一个 Nat 适配器来使用主机系统的真实网卡。

  • 此外,我还激活了一个仅限主机的适配器,以便能够使用单独的 IP 来连接 VM 和主机系统。

扣除

我发现接口文件只需要一个网关条目,这是通过

auto eth0

iface eth0 inet dhcp.

所以这是提供网关信息的第一个网络适配器的条目,因此第二个配置不需要名为

gateway 192.168.1.1.

对我来说,这意味着第二个条目必须如下所示:

address 192.168.217.131

取决于路由器告诉您作为通过 dcp 配置的接口的网络地址的内容,这里的第二行是网络掩码。在常见情况下,这是

netmask 255.255.255.

所以整个 `/etc/network/interfaces' 文件看起来像这样:

#This file describe the network interfaces available on your system
#and how to activate them. For more information see interfaces(5).

#The loopack network interface 

auto lo
iface lo inet loopback

#The primary network interface 

# ethernet 0
auto eth0 
iface eth0 inet dhcp

auto eth1
iface eth1 inet static

address 192.168.217.131
netmask 255.255.255

#No need for gateway here because this is already provided by the dhcp entry.
Run Code Online (Sandbox Code Playgroud)

在此示例中,我采用了 Ubuntu 的 ^server(基本 Ubuntu 服务器)包提供的 IP 地址,即 192.168.217.130 并将其增加了 1。

现在我重新启动 Ubuntu 并收到消息Waiting for network Configuration...,其中 Ubuntu 尝试等待网络连接大约 2 分钟。

我在 Virtual Box 上也遇到过同样的情况。

Jos*_*osh 6

有两件事要知道

  1. 如上所述,您的网络中不需要带有 dhcp 服务器的第二个网关,因为网关条目是从那里生成的。

  2. 添加主机专用适配器后,您必须从 Windows 主机复制 IP 地址。

迄今为止。

以下是与一个附加适配器的仅主机连接的示例配置:

auto eth1

iface eth1 inet static
address 192.168.253.128
netmask 255.255.255.0
network 192.168.253.1
broadcast 192.168.253.255
Run Code Online (Sandbox Code Playgroud)

网线的第三块取决于你的ip。主机和来宾之间的网络通信需要广播线。这是一个网络协议相关的东西。