1. 查看网卡信息
当前IP 为 192.168.31.195
$ ip addr
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:1f:78:2e brd ff:ff:ff:ff:ff:ff
inet 192.168.31.195/24 metric 100 brd 192.168.31.255 scope global dynamic eth0
valid_lft 973sec preferred_lft 973sec
inet6 fe80::215:5dff:fe1f:782e/64 scope link
valid_lft forever preferred_lft forever
2. 修改yaml配置文件
sudo vim /etc/netplan/00-installer-config.yaml
配置模板如下
# This is the network config written by 'subiquity'
network:
ethernets:
eth0: # 网卡名称
dhcp4: no #关闭ipv4动态分配ip地址
dhcp6: no #关闭ipv6动态分配ip地址
addresses:
- 192.168.31.181/24 # 设置的子网IP和子网掩码,192.168.31.200代表IP /24代表掩码255.255.255.0
routes:
- to : default
via: 192.168.31.1 # 网关
nameservers:
addresses: # DNS服务器
- 192.168.31.1
- 114.114.114.114
version: 2
renderer: networkd
保存更改并关闭文件。
3.应用新的网络配置
修改好网卡配置文件后通过下面命令生效
sudo netplan apply
4.重新启动网络服务
sudo systemctl restart systemd-networkd