之前的版本是在/etc/network/interfaces中修改,新版本使用/etc/netplan/*.yaml
liyaoyi@ubuntu:~$ cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens32:
dhcp4: yes 编辑YAML文件配置IP信息
liyaoyi@ubuntu:~$ sudo vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens32:
dhcp4: no
dhcp6: no
addresses: [192.168.209.221/24]
gateway4: 192.168.209.2
nameservers:
addresses: [8.8.8.8, 114.114.114.114]
执行命令让配置生效:
liyaoyi@ubuntu:~$ sudo netplan apply
显示debug信息
liyaoyi@ubuntu:~$ sudo netplan --debug apply
** (generate:2842): DEBUG: Processing input file //etc/netplan/01-netcfg.yaml..
** (generate:2842): DEBUG: starting new processing pass
** (generate:2842): DEBUG: ens32: setting default backend to 1
** (generate:2842): DEBUG: Generating output files..
** (generate:2842): DEBUG: NetworkManager: definition ens32 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device ens32 operstate is up, not replugging
DEBUG:netplan triggering .link rules for ens32
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo