/etc/network/interfaces
NetworkManager
1. 查詢連線名稱
輸出結果:
1
2
3
|
NAME UUID TYPE DEVICE
Wired connection 1 81bfe9ba-56fb-42ca-8c68-fca9b4a8c45f ethernet eth0
lo ed59c3e3-10e5-421e-b80f-bd9b5fc6a09b loopback lo
|
記下 NAME 欄位內容Wired connection 1,稍後設定IP會用到
2. 設定固定 IP、gateway與 DNS
- IP:
192.168.1.100/24
- Gateway:
192.168.1.1
- DNS:
8.8.8.8 1.1.1.1
1
2
3
4
|
sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24
sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli con mod "Wired connection 1" ipv4.method manual
|
3. 重新套用連線
1
|
sudo nmcli con up "Wired connection 1"
|
systemd-networkd
參考資料Debian Wiki
- 停用現有網路設定
1
|
sudo mv /etc/network/interfaces /etc/network/interfaces.save
|
1
|
sudo mv /etc/network/interfaces.d /etc/network/interfaces.d.save
|
- 啟用 systemd-networkd
1
|
sudo systemctl enable systemd-networkd
|
- 於
/etc/systemd/network_新增**.network** 檔
命名規則 <網路卡名稱>.network,例:10-enp1s0.network
DHCP取得IP
1
2
3
4
5
6
|
[Match]
Name=enp1s0
Type=ether
[Network]
DHCP=ipv4
|
固定IP
1
2
3
4
5
6
7
|
[Match]
Name=enp1s0
[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=192.168.1.1
|
- 重啟systemd-networkd後生效
1
|
sudo systemctl restart systemd-networkd
|