将桥接的 eth0 与静态 IP 从 /etc/network/interfaces 迁移到 networkd

将桥接的 eth0 与静态 IP 从 /etc/network/interfaces 迁移到 networkd

在 Ubuntu 16.04 下,我的/etc/network/interfaces文件如下所示:

auto lo
iface lo inet loopback

auto br0
iface br0 inet static
  address 144.76.AAA.BBB
  netmask 255.255.255.224
  gateway 144.76.CCC.DDD
  bridge_ports eth0

这如何转化为networkdUbuntu 18.04 中的配置?这是我尝试过的,但没有成功(重新启动后,我无法再访问该机器):

/etc/systemd/network/01-br0.netdev

[NetDev]
Name=br0
Kind=bridge

/etc/systemd/network/01-br0.network

[Match]
Name=br0

[Network]
Address=144.76.AAA.BBB/29
Gateway=144.76.CCC.DDD

/etc/systemd/network/10-enp4s0.network

[Match]
Name=enp4s0

[Network]
Bridge=br0

这是输出/var/log/syslog

Jun  2 13:30:51 master systemd-networkd[616]: br0: netdev ready
Jun  2 13:30:51 master systemd-networkd[616]: Enumeration completed
Jun  2 13:30:51 master systemd-networkd[616]: lo: Link is not managed by us
Jun  2 13:30:51 master systemd-networkd[616]: enp4s0: Link is not managed by us
Jun  2 13:30:51 master systemd-networkd[616]: br0: IPv6 successfully enabled
Jun  2 13:30:51 master systemd-networkd[616]: lo: Link is not managed by us
Jun  2 13:30:51 master systemd-networkd[616]: enp4s0: IPv6 successfully disabled
Jun  2 13:30:51 master systemd[1]: Starting Dispatcher daemon for systemd-networkd...
Jun  2 13:30:52 master networkd-dispatcher[749]: No valid path found for iwconfig
Jun  2 13:30:52 master systemd[1]: Started Dispatcher daemon for systemd-networkd.
Jun  2 13:30:53 master systemd-networkd[616]: enp4s0: Gained carrier
Jun  2 13:30:53 master systemd-networkd[616]: enp4s0: Configured
Jun  2 13:30:53 master systemd-networkd[616]: br0: Gained carrier
Jun  2 13:30:53 master systemd-networkd[616]: br0: Gained IPv6LL
Jun  2 13:30:53 master systemd-networkd[616]: br0: Configured
Jun  2 13:30:53 master systemd-networkd-wait-online[661]: managing: br0
Jun  2 13:30:53 master systemd-networkd-wait-online[661]: managing: enp4s0
Jun  2 13:30:53 master systemd-networkd-wait-online[661]: ignoring: lo

答案1

以下答案是从尚未发布的更新中复制粘贴的Ubuntu 服务器指南

通过编辑 /etc/netplan/ 中的 netplan 配置来配置桥接器:

network:
  version: 2
  renderer: networkd
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp3s0

输入物理接口和网络的适当值。现在应用配置以启用桥接:

sudo netplan apply

新的桥接接口现在应该已启动并运行。brctl 提供有关桥接状态的有用信息,控制哪些接口是桥接的一部分等。有关更多信息,请参阅 man brctl。

有一个静态示例这里

相关内容