在虚拟化 Ubuntu 服务器上安装第二个网络接口

在虚拟化 Ubuntu 服务器上安装第二个网络接口

我刚刚Ubuntu 16.04在一台机器上安装了最新版本VirtualBox。我想拥有两个不同的网络接口:

  1. 第一个使用 ssh 从主机访问客户机;为此,我安装了适配器Host-only Adapter1
  2. 第二个能够从主机连接到互联网,所以我安装了一个基本的NAT适配器 2

但是,即使两个网络适配器都被正确识别,也只有第一个可以访问。

$ ls /sys/class/net/
enp0s3  enp0s8  lo

$ ifconfig
enp0s3    Link encap:Ethernet  HWaddr 08:00:27:47:52:7b  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe47:527b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:399 errors:0 dropped:0 overruns:0 frame:0
          TX packets:246 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:44031 (44.0 KB)  TX bytes:75269 (75.2 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:92 errors:0 dropped:0 overruns:0 frame:0
          TX packets:92 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:40721 (40.7 KB)  TX bytes:40721 (40.7 KB)

我怎样才能让系统也识别第二张卡?

答案1

我已经解决了添加的问题

# The secondary network interface
auto enp0s8
iface enp0s8 inet dhcp

/etc/network/interfaces

(使用 获取新接口名称ifconfig -a

并使用 重新启动网络sudo service networking restart

现在,这是结果

$ ifconfig enp0s3    Link encap:Ethernet  HWaddr 08:00:27:47:52:7b  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe47:527b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6334 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7656 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2741526 (2.7 MB)  TX bytes:10824219 (10.8 MB)

enp0s8    Link encap:Ethernet  HWaddr 08:00:27:3e:1e:bf  
          inet addr:10.0.3.15  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe3e:1ebf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1730 (1.7 KB)  TX bytes:1882 (1.8 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2143 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2143 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:443165 (443.1 KB)  TX bytes:443165 (443.1 KB)

答案2

Ubuntu Server 的新版本使用netplan而不是ifup

您必须编辑/etc/netplan/00-installer-config.yaml

network:
  ethernets:
     enp0s3:
        dhcp4: true
     enp0s8:
        dhcp4: true
version: 2

然后运行:

netplan apply

然后它就会弹出!

相关内容