在netplan上配置仅主机的辅助接口

我有一个运行ubuntu 18.04服务器的virtualbox vm。

我设置了网卡1桥接器,以在我的网络和Internet上获得一个IP。

我将禁用dhcp的网卡2设置为仅主机,以在虚拟机之间具有基于ip的静态专用网络。

通过网络/接口在ubuntu 18桌面上执行此操作效果很好:

auto enp0s8
iface enp0s8 inet static#
      address 192.168.56.2
      netmask 255.255.255.0

通过netplan在ubuntu 18服务器上执行此操作无效。

首先,我禁用了cloud-init来执行50-cloud-int.yaml中的说明: 使用禁用设置在/etc/cloud/cloud.cg.d/99-disable-network-config.cfg中写入文件。

我在第一个网桥界面中保留了原始内容的文件:

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

然后,我在仅主机接口的同一netplan文件夹中创建了一个新文件夹:01-netconfig.yaml

network:
 ethernets:
  enp0s8:
   dhcp4: false
   addresses: [192.168.56.2/24]
   gateway4: 192.168.56.1
 version: 2

并经颂歌设置:

netplan generate
netplan apply 

如果我ping www.google.com,现在没有更多响应。 如果我禁用接口enp0s8(ifconfig enp0s8关闭),它将重新开始工作。

此处启用enp0s8的配置和路由:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.19  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::a00:27ff:feaf:103d  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:af:10:3d  txqueuelen 1000  (Ethernet)
        RX packets 487  bytes 46924 (46.9 KB)
        RX errors 0  dropped 71  overruns 0  frame 0
        TX packets 220  bytes 28849 (28.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.2  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fec3:e4b7  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:c3:e4:b7  txqueuelen 1000  (Ethernet)
        RX packets 60  bytes 5118 (5.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 89  bytes 6856 (6.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:af:10:3d brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.19/24 brd 192.168.0.255 scope global dynamic enp0s3
       valid_lft 84900sec preferred_lft 84900sec
    inet6 fe80::a00:27ff:feaf:103d/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:c3:e4:b7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.2/24 brd 192.168.56.255 scope global enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fec3:e4b7/64 scope link
       valid_lft forever preferred_lft forever

default via 192.168.56.1 dev enp0s8 proto static
default via 192.168.0.1 dev enp0s3 proto dhcp src 192.168.0.19 metric 100
192.168.0.0/24 dev enp0s3 proto kernel scope link src 192.168.0.19
192.168.0.1 dev enp0s3 proto dhcp scope link src 192.168.0.19 metric 100
192.168.56.0/24 dev enp0s8 proto kernel scope link src 192.168.56.2

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.1    0.0.0.0         UG    0      0        0 enp0s8
0.0.0.0         192.168.0.1     0.0.0.0         UG    100    0        0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 enp0s3
192.168.0.1     0.0.0.0         255.255.255.255 UH    100    0        0 enp0s3
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s8

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    0      0        0 enp0s8
default         _gateway        0.0.0.0         UG    100    0        0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 enp0s3
_gateway        0.0.0.0         255.255.255.255 UH    100    0        0 enp0s3
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 enp0s8

如果我跟踪路线www.google.com,我只会得到* * *超时。 我认为我在通往外部的网关上发生了一些冲突。 请帮助我了解我在哪里做得不好。

评论