將具有靜態 IP 的橋接 eth0 從 /etc/network/interfaces 遷移到 networkd

將具有靜態 IP 的橋接 eth0 從 /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 提供有關網橋狀態的有用信息,控制哪些接口是網橋的一部分等。

有一個靜態的例子這裡

相關內容