1.netplan介绍
Netplan是Ubuntu 17.10及更高版本中默认的网络配置工具。它是一个命令行工具,可以帮助用户轻松地配置网络接口,包括静态或动态IP地址、网关、DNS等等。
Netplan的配置文件使用YAML格式,这使得配置文件易于阅读和编辑,并且可以通过版本控制系统进行管理。此外,Netplan还支持基于渲染器的网络配置,这意味着它可以根据不同的网络配置需求,Netplan的一个主要优势是它可以帮助用户减少一些常见的网络配置问题,例如网络命名约定不一致、网络接口名称的变化等等。使用Netplan,用户可以轻松地配置多个网络接口,并可以指定其默认路由,从而提高网络性能和安全性。
2.netplan配置
ubuntu@ubuntu:~$ sudo su -
root@ubuntu:~$ vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: false #false表示配置静态地址,true为dhcp分配
addresses: [192.168.80.81/24] #注意,addresses是复数形式,且后面要有空格
routes:
- to: default #默认网关
via: 192.168.80.2
nameservers:
addresses: [223.6.6.6] #dns地址
eth1:
dhcp4: false
version: 2
3.修改网卡名称
ubuntu默认网卡名称为ens33,上述已将其改为eth0,所以此处要修改gurb文件
root@ubuntu:~$ vim /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0" #此处原来为空格,加上此文本
root@ubuntu:~$ update-gurb
root@ubuntu:~$ netplan apply