与Ubuntu16的对比
ubuntu16.04TLS的网络配置文件为/etc/network/interfaces,我们通过在该文件中写入配置对网卡进行IP设置。并且然后通过网卡的重启来加载该配置
ubuntu18.04TLS中,其引入了一个新的工具netplan来进行网络设备的管理,对其进行设置。
netplan的配置文件位于/etc/netplan文件夹下面
对Ubuntu 18.04的网络配置
cuda@cuda1:~$ cd /etc/netplan/
cuda@cuda1:/etc/netplan$ ls
50-cloud-init.yaml
cuda@cuda1:/etc/netplan$
可以看到在/etc/netplan
下有个yaml文件
cuda@cuda1:~$ 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.
# 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: #配置的网卡名称,使用ifconfig -a查看得到,且必须是空格缩进,netplan只认空格
eno1:
addresses: []
dhcp4: true dhcp4开启
optional: true
eno2:
addresses: []
dhcp4: true
optional: true
version: 2
如果没有*.yaml后缀的文件,就运行如下命令创建一个(netplan会读取该目录下所有该后缀的文件):
sudo netplan generate
netplan
这里我开启了两张网卡
通过netplan更新配置
sudo netplan apply
通过ifconfig查看配置是否生效
ifconfig
分配成功