Ubuntu 18.04 透過 netplan 設定網路卡 IP
Ubuntu 18.04 透過 netplan 設定網路卡 IP 照上面的說明看了一下 /etc/netplan 目錄,查閱一下 /etc/netplan/50-cloud-init.yaml,如下:
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: ens192: dhcp4: true ens224: dhcp4: true version: 2 看來可以關閉 cloud network,但是我其實也沒有要用 cloud-init,乾脆移除它,如下:
sudo apt-get remove cloud-init
然後把 /etc/netplan/50-cloud-init.yaml 改成下面這樣:
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: ens192: addresses: [192.168.32.231/24] gateway4: 192.168.32.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] dhcp4: no ens224: dhcp4: true version: 2 這幾年 yaml 深得大眾的心,設定檔就是要用 yaml 格式才是潮,解說一下上述幾個設定: