calos@ubuntu-focal-fossa:~$ ls -al /etc/netplan
total 12
drwxr-xr-x 2 root root 4096 May 3 08:50 ./
drwxr-xr-x 95 root root 4096 May 29 00:15 ../
-rw-r--r-- 1 root root 116 May 3 08:50 00-installer-config.yam
確認一下內容,通常在安裝時沒有特別設定的話會產生一個 DHCP 的設定檔,其內容如下:
1
2
3
4
5
6
7
calos@ubuntu-focal-fossa:~$ cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: true
version: 2
直接以新的內容取代它,要設定的固定 IP 為 192.168.1.220,閘道 (分享器、路由器、小烏龜等) 為 192.168.1.1,DNS 直接套用閘道的設定,因此給相同的 IP。
執行 sudo netplan try 套用設定,這時候通常會斷線個幾秒鐘,之後終端機上就會出現一個倒數計時,代表設定正確。這時候再按下 Enter 就會保存設定。
1
2
3
4
5
6
7
8
9
10
11
12
calos@ubuntu-focal-fossa:~$ sudo netplan try
Warning: Stopping systemd-networkd.service, but it can still be activated by:
systemd-networkd.socket
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 118 seconds
Configuration accepted.
calos@ubuntu-focal-fossa:~$