從17.10開始引入指令來設置ip地址,現在有兩種方式設置中.04的靜態ip地址:
1.像以前一樣在/etc// 中添加如下,然后重啟 服務
root@ubuntu180402:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 192.168.63.147
netmask 255.255.255.0
gateway 192.168.63.2
dns-nameservers 192.168.63.2
root@ubuntu180402:~#
2. 在/etc//xxx.yaml文件配置ip地址如下,注意每行空格不能少,否則 apply的時候會報錯。
root@ubuntu180402:~# cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: yes
dhcp6: no
addresses: [192.168.63.146/24, ]
gateway4: 192.168.63.2
nameservers:
addresses: [192.168.63.2]
root@ubuntu180402:~#
另外tp設置向導靜態ip全是0,當和都有配置且ip不同時,開機后會按照中的ip進行啟動,但可以用 apply來生效中的iptp設置向導靜態ip全是0,有時候 會報錯,應該與配置有沖突。