
我已經設定了 Ubuntu Server 18.04。沒有活動的網路管理器,因此配置在 /etc/network/interfaces 中完成。
網路中有一個 dhcp 伺服器處於活動狀態。
/etc/network/interfaces
內容:
auto enp1s0
iface enp1s0 inet dhcp
auto enp2s0
iface enp2s0 inet static
address 0.0.0.0
up sysctl -w net.ipv6.conf.enp2s0.disable_ipv6=1
auto enp3s0
iface enp3s0 inet static
address 0.0.0.0
up sysctl -w net.ipv6.conf.enp3s0.disable_ipv6=1
ubuntu 伺服器應該使用介面 enp1s0 來存取 LAN,並且應該自動取得位址。
介面 enp2s0 和 enp3s0 應該在線,但 Ubuntu 伺服器應該無法透過它們進行任何聯網。有一個虛擬機器作為 PfSense 的服務運行,它使用 enp2s0 作為 Lan 接口,使用 enp3s0 作為 Wan 接口。
我的實際問題:enp1s0 的自動配置僅在啟動後立即運作。如果我從 enp1s0 拔下乙太網路電纜並重新連接,Ubuntu 伺服器不會檢測到存在連結事件並再次聯繫 dhcp。它只是保留啟動後獲得的配置。
如何告訴我的伺服器在每次連結後重置並重新配置介面,就像預設在桌面安裝上一樣?
答案1
感謝@chili555,我研究了 netplan 並找到了一個可行的解決方案:
在/etc/netplan
我設定的介面中,我希望我的伺服器供其自己使用。
遺憾的是我無法在那裡配置所有內容,因為我希望僅啟用介面 2 和 3,但不啟用任何位址。因此,我將這兩個介面保留在 /etc/network/interfaces 檔案中。
=> 現在工作設定如下:
內容/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: yes
內容/etc/network/interfaces
:
auto enp2s0
iface enp2s0 inet static
address 0.0.0.0
up sysctl -w net.ipv6.conf.enp2s0.disable_ipv6=1
auto enp3s0
iface enp3s0 inet static
address 0.0.0.0
up sysctl -w net.ipv6.conf.enp3s0.disable_ipv6=1
現在我的設定按預期工作:enp1s0 完全自動進行管理,並且我在每次連結時都會發出新的 dhcp 請求。
enp2s0 和 enp3s0 都沒有 ipv4/6 位址,可以從我的 pfSense 虛擬機器使用