Ubuntu23.04的静态ip的管理方式较之前的系统版本有很大的改变
1、管理文件
/etc/netplan/00-installer-config.yaml
2、操作之前先看默认网卡名字(我这里是ens3)
root@wanyan:/etc/zabbix# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:5c:5d:63 brd ff:ff:ff:ff:ff:ff
altname enp0s3
inet 192.168.20.36/24 metric 100 brd 192.168.20.255 scope global dynamic ens3
valid_lft 22137sec preferred_lft 22137sec
inet6 fe80::5054:ff:fe5c:5d63/64 scope link
valid_lft forever preferred_lft forever
3、管理文件配置格式
###设置固定ip的格式
network:
ethernets:
[network-interface-name]:
dhcp4: no
addresses: [ip-address/subnet-mask]
gateway4: [default-gateway]
nameservers:
addresses: [dns-server]
version: 2
###默认的dhcp的格式
# This is the network config written by 'subiquity'
network:
ethernets:
ens3:
dhcp4: true
version: 2
4、设置固定ip地址
# This is the network config written by 'subiquity'
network:
ethernets:
ens3:
dhcp4: no
addresses: [192.168.20.36/24]
gateway4: 192.168.20.254
nameservers:
addresses: [223.5.5.5,223.6.6.6]
version: 2
5、应用命令
root@wanyan:/etc/zabbix# netplan apply
** (generate:15677): WARNING **: 13:25:11.214: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.
** (generate:15677): WARNING **: 13:25:11.214: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
Cannot call openvswitch: ovsdb-server.service is not running.
** (process:15675): WARNING **: 13:25:11.516: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:15675): WARNING **: 13:25:11.516: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
** (process:15675): WARNING **: 13:25:11.572: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:15675): WARNING **: 13:25:11.572: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
** (process:15675): WARNING **: 13:25:11.572: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:15675): WARNING **: 13:25:11.572: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
根据上边的提示做如下修改(网卡的名字需要根据实际情况调整,比如的主机是ens3)
root@wanyan:/etc/zabbix# chmod 600 /etc/netplan/00-installer-config.yaml
root@wanyan:/etc/zabbix#apt install openvswitch-switch -y
root@wanyan:/etc/zabbix#systemctl start ovsdb-server
root@wanyan:/etc/zabbix#systemctl enable ovsdb-server
root@wanyan:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens3:
dhcp4: false
addresses: [192.168.20.36/24]
optional: true
routes:
- to: default
via: 192.168.20.254
nameservers:
addresses: [223.5.5.5,223.6.6.6]
version: 2
root@wanyan:~# netplan apply
root@wanyan:~# ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.20.36 netmask 255.255.255.0 broadcast 192.168.20.255
inet6 fe80::5054:ff:fe5c:5d63 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:5c:5d:63 txqueuelen 1000 (Ethernet)
RX packets 56671 bytes 84570573 (84.5 MB)
RX errors 0 dropped 3995 overruns 0 frame 0
TX packets 36475 bytes 3779428 (3.7 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 610 bytes 44650 (44.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 610 bytes 44650 (44.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0