将 Ubuntu 18.04 VM 连接到 Virtual Box Nat 网络

将 Ubuntu 18.04 VM 连接到 Virtual Box Nat 网络

我正在尝试使用 VirtualBox Nat 网络设置虚拟机网络。一些虚拟机,特别是 coreos 盒子和 metasploitable 的集群,连接得很好。其他的,特别是我自己设置的任何 Ubuntu 虚拟机则没有。

nat网络设置如下

$ VBoxManage natnetwork list fabian
NAT Networks:

Name:        fabian
Network:     172.17.8.0/24
Gateway:     172.17.8.1
IPv6:        No
Enabled:     Yes

我尝试过编辑 Ubuntu vms/etc/network/interfaces文件以进行读取

# interface(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

# network interface
auto enp0s3
iface enp0s3 inet dhcp

(这部分基于/etc/network/interfaces来自metasploitable的文件,这是一个基于ubuntu的虚拟机,似乎可以很好地连接到网络)

但是,当我尝试运行时,$ sudo systemctl restart networking它会挂起并超时。我已经包含了下面的输出$ journalctl -xe。我之前包含过一些条目,但它们似乎是相同的消息,但间隔不同。

在连接设置网络接口时我缺少什么吗?

Oct 23 10:22:49 burp-vm systemd-resolved[290]: Using degraded feature set (UDP) for DNS server 8.8.8.8.
Oct 23 10:22:52 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 20 (xid=0x6914771e)
Oct 23 10:22:52 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 20 (xid=0x6914771e)
Oct 23 10:22:54 burp-vm systemd-resolved[290]: Using degraded feature set (UDP) for DNS server 8.8.4.4.
Oct 23 10:23:12 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 9 (xid=0x6914771e)
Oct 23 10:23:12 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 9 (xid=0x6914771e)
Oct 23 10:23:21 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 9 (xid=0x6914771e)
Oct 23 10:23:21 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 9 (xid=0x6914771e)
Oct 23 10:23:30 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:23:30 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:23:42 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:23:42 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:23:54 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 11 (xid=0x6914771e)
Oct 23 10:23:54 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 11 (xid=0x6914771e)
Oct 23 10:24:05 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 15 (xid=0x6914771e)
Oct 23 10:24:05 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 15 (xid=0x6914771e)
Oct 23 10:24:20 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 21 (xid=0x6914771e)
Oct 23 10:24:20 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 21 (xid=0x6914771e)
Oct 23 10:24:39 burp-vm systemd-resolved[290]: Using degraded feature set (TCP) for DNS server 8.8.8.8.
Oct 23 10:24:39 burp-vm systemd-resolved[290]: Using degraded feature set (TCP) for DNS server 8.8.4.4.
Oct 23 10:24:41 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 7 (xid=0x6914771e)
Oct 23 10:24:41 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 7 (xid=0x6914771e)
Oct 23 10:24:48 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:24:48 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:25:00 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 10 (xid=0x6914771e)
Oct 23 10:25:00 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 10 (xid=0x6914771e)
Oct 23 10:25:10 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:25:10 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 12 (xid=0x6914771e)
Oct 23 10:25:22 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 11 (xid=0x6914771e)
Oct 23 10:25:22 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 11 (xid=0x6914771e)
Oct 23 10:25:33 burp-vm dhclient[1889]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x6914771e)
Oct 23 10:25:33 burp-vm ifup[1867]: DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0x6914771e)
Oct 23 10:25:35 burp-vm systemd[1]: networking.service: Start operation timed out. Terminating.
Oct 23 10:25:35 burp-vm systemd[1]: networking.service: Main process exited, code=killed, status=15/TERM
Oct 23 10:25:35 burp-vm systemd[1]: networking.service: Failed with result 'timeout'.
Oct 23 10:25:35 burp-vm systemd[1]: Failed to start Raise network interfaces.

答案1

从 Ubuntu 17.10 开始,该ifupdown工具被视为已弃用的工具并由netplan.要使用该软件包,应安装/etc/network/interfaces该软件包。ifupdown

在您的情况下,您应该使用以下工具配置网络netplan

配置文件可以在 下找到/etc/netplan/。创建/编辑文件*.yaml如下:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true

如果您安装了网络管理器,则可以替换renderer: networkdrenderer: NetworkManager

然后运行:

sudo netplan generate
sudo netplan apply

看:

Netplan配置示例

迁移到 Netplan

相关内容