ubuntu 从17.10开始,改成netplan方式配置IP,配置写在/etc/netplan/01-network-manager-all.yaml或者类似名称的yaml文件里。
1、查看你要设置静态IP的网卡名称
通过ifconfig命令,查看到网卡的名字为enp1s0
test@test:/etc/netplan$ ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.110 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::5054:ff:fe54:a819 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:54:a8:19 txqueuelen 1000 (Ethernet)
RX packets 352291 bytes 404510742 (404.5 MB)
RX errors 0 dropped 17674 overruns 0 frame 0
TX packets 172029 bytes 32435361 (32.4 MB)
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 7029 bytes 3959595 (3.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7029 bytes 3959595 (3.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3、通过netplan的yaml文件配置静态IP
使用vi打开/etc/netplan/00-installer-config.yaml或者类似名称的yaml文件配置文件后
test@test:/etc/netplan$ cd /etc/netplan/
test@test:/etc/netplan$ ls
00-installer-config.yaml
修改或增加如下图所示内容(第2到12行):
sudo vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp1s0:
dhcp4: no
addresses: [192.168.100.86/24]
routes:
- to: default
via: 192.168.100.1
nameservers:
addresses: [114.114.114.114,8.8.8.8]
search: [localhost,local]
version: 2
4、让静态IP生效
通过以下命令或者重启系统后,网卡enp1s0的静态IP地址就设置好了。
test@test:/etc/netplan$ sudo netplan apply