一、修改文件/etc/netplan/xx-network-manager-all.yaml文件
刚安装的ubuntu操作系统,xx-network-manager-all.yaml文件名是不同的,进入到/etc/netplan/这个目录去查看具体是什么名称。
可以看到刚安装的ubuntu的network-manager-all.yaml是如下默认内容:
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: true
version: 2
这个缺省配置是动态IP的配置方式,考虑到这缺省配置的信息是安装操作系统阶段自动获得的,为了避免不知道怎么填具体参数,可以使用其他命令行查询网络配置信息。
root@server:~# ifconfig
ens33: flags=4163
inet 192.168.88.133 netmask 255.255.255.0 broadcast 192.168.88.255
inet6 fe80::20c:29ff:fe8a:262d prefixlen 64 scopeid 0x20
ether 00:0c:29:8a:26:2d txqueuelen 1000 (Ethernet)
RX packets 227 bytes 25410 (25.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 142 bytes 16724 (16.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 96 bytes 7288 (7.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 7288 (7.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@server:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.88.2 0.0.0.0 UG 100 0 0 ens33
192.168.88.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
192.168.88.2 0.0.0.0 255.255.255.255 UH 100 0 0 ens33
root@server:~#
根据上面查询的信息修改xx-network-manager-all.yaml内容
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: no
addresses: [192.168.88.133/24]
optional: true
gateway4: 192.168.88.2
nameservers:
addresses: [223.5.5.5,223.6.6.6]
version: 2



