我在网络上有一台运行 Ubuntu 的 VM 服务器192.168.1.0/24
。我试图添加一个 vlan 标记的子接口,该子接口将用于位于我网络上 DMZ 中的 VM。我首先添加了子接口,然后在配置中添加了sudo vconfig add enp2s0 30
以下内容/etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo br0
auto enp1s0
iface lo inet loopback
###bridge interfae for vm's
iface br0 inet dhcp
bridge_ports enp2s0
bridge_stp off
bridge_maxwait 0
bridge_fd 0
dns-nameservers 192.168.1.1
dns-nameservers 8.8.8.8
gateway 192.168.1.1
###power-fail backup NIC
iface enp1s0 inet static
address 192.168.40.2
network 192.168.40.0
netmask 255.255.255.0
#suberinterface for VLAN segregated VM's
auto enp2s0.30
iface enp2s0.30 inet dhcp
vlan-raw-device enp2s0
###network shim for dockers
auto macvlan0
iface macvlan0 inet static
pre-up ip link add link br0 name macvlan0 type macvlan mode bridge
address 192.168.1.42
network 192.168.1.0
netmask 255.255.255.0
###routes for dockers
post-up route add -host 192.168.1.16 dev macvlan0
post-up route add -host 192.168.1.43 dev macvlan0
这是我的ip route
:
default via 192.168.1.1 dev br0
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.41
192.168.1.0/24 dev macvlan0 proto kernel scope link src 192.168.1.42
192.168.1.16 dev macvlan0 scope link
192.168.1.43 dev macvlan0 scope link
192.168.30.0/24 dev enp2s0.30 proto kernel scope link src 192.168.30.2
192.168.40.0/24 dev enp1s0 proto kernel scope link src 192.168.40.2
这是我现有的ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 34:e8:94:f0:55:3f brd ff:ff:ff:ff:ff:ff
inet 192.168.40.2/24 brd 192.168.40.255 scope global enp1s0
valid_lft forever preferred_lft forever
inet6 fe80::36e8:94ff:fef0:553f/64 scope link
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
link/ether 1c:1b:0d:12:aa:73 brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 1c:1b:0d:12:aa:73 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.41/24 brd 192.168.1.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::1e1b:dff:fe12:aa73/64 scope link
valid_lft forever preferred_lft forever
5: enp1s0.30@enp1s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 34:e8:94:f0:55:3f brd ff:ff:ff:ff:ff:ff
6: enp2s0.30@enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 1c:1b:0d:12:aa:73 brd ff:ff:ff:ff:ff:ff
inet 192.168.30.2/24 brd 192.168.30.255 scope global enp2s0.30
valid_lft forever preferred_lft forever
inet6 fe80::1e1b:dff:fe12:aa73/64 scope link
valid_lft forever preferred_lft forever
7: macvlan0@br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 32:8e:07:8f:0f:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.42/24 brd 192.168.1.255 scope global macvlan0
valid_lft forever preferred_lft forever
inet6 fe80::308e:7ff:fe8f:f61/64 scope link
valid_lft forever preferred_lft forever
重置网络服务后,接口会启动并获取 IP 地址。但是,现在我无法访问在父接口上运行的任何虚拟机enp2s0
。我需要向父接口添加一些路由吗enp2s0
?此服务器有两个 NIC。主 NIC 是enp2s0
。Enp1s0
用作备用 NIC,以便在断电时与 UPS 通信。