Ubuntu Server 18.04 LTS 版後網路設定變更為netplan
原本 /etc/network/interface 檔案:
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
上面說明改為 /etc/netplan 目錄下的 50-cloud-init.yaml
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
version: 2
編輯50-cloud-init.yaml改為靜態 IP如下:
# 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: [10.8.8.88/24]
gateway4: 10.8.8.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
dhcp4: no
version: 2
設定說明:
dhcp4: no 關閉DHCP
addresses: 靜態IP與子網路遮罩Subnet Mask
nameservers: DNS伺服器,多筆用 , 分隔
gateway4: IPv4的預設閘道Gateway
變更後儲存離開編輯。
測試配置
執行測試指令[ sudo netplan try ],如果設定正確就被接受,否則120 秒後自動還原設定。
測試沒有問題,可執行指令[ sudo netplan apply ]套用設定檔。
留言
張貼留言