系統安裝完成以後默認是動態分配IPubuntu
liyaoyi@ubuntu:~$ ifconfig ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.209.221 netmask 255.255.255.0 broadcast 192.168.209.255 inet6 fe80::20c:29ff:fe9b:2437 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:9b:24:37 txqueuelen 1000 (Ethernet) RX packets 632 bytes 78029 (78.0 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 440 bytes 56139 (56.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 102 bytes 7728 (7.7 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 102 bytes 7728 (7.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
以前的版本是在/etc/network/interfaces中修改,新版本使用/etc/netplan/*.yaml vim
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信息bash
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]
執行命令讓配置生效:app
liyaoyi@ubuntu:~$ sudo netplan apply
顯示debug信息ide
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
netplan 其餘參數指令:oop
netplan generate: 執行後使用 /etc/netplan 生成/run/systemd/network/10-netplan-ens32.network.net
netplan ifupdown-migrate: 嘗試從/etc/network/interfaces轉換成netplan須要的yaml格式,若是轉換成功會禁止使用/etc/network/interfacesdebug