【Ubuntu server18.04 】使用netplan配置静态IP
1. 查看本机ip
$ ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:97:70:eb:98 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.193.131 netmask 255.255.255.0 broadcast 192.168.193.255 inet6 fe80::20c:29ff:fe6e:f773 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:6e:f7:73 txqueuelen 1000 (Ethernet) RX packets 740 bytes 71366 (71.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 440 bytes 57899 (57.8 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 92 bytes 7100 (7.1 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 92 bytes 7100 (7.1 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2. 查看本机网关
$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.193.2 0.0.0.0 UG 0 0 0 ens33 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 192.168.193.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
3. 编辑netplan默认配置文件
sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity' network: ethernets: ens33: dhcp4: no addresses: [192.168.193.131/24] gateway4: 192.168.193.2 nameservers: addresses: [192.168.193.2] version: 2
4. 应用配置
$ sudo netplan apply
5. 检查连通性
ping 192.168.193.131