在Ubuntu18.04中,传统的配置/etc/network/interfaces已无用
新方法:修改如下文件
1 |
sudo vim /etc/netplan/50-cloud-init.yaml |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
siasjack@jack:~$ cat /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 reboot. 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: enp1s0: addresses: - 192.168.5.249/24 gateway4: 192.168.5.1 nameservers: addresses: - 114.114.114.114 version: 2 |
注意上面的语法是yaml,比较晦涩难懂的yaml。。。。跟json相比太不友好了!
语法中横线和IP地址之间是有空格的
想设置多个dns地址可以这样写:addresses: [114.114.114.114,180.76.76.76]
设置好后重启网关,命令如下,如果写的yaml配置文件有误,他会提示错误的地方的
1 |
sudo netplan apply |
也可以加–debug参数,看网络设置的过程
1 |
sudo netplan --debug apply |
然后就ok了。。。