Ubuntu 22.04 修改为静态IP
此处使用VM 自动获取IP后修改为静态IP
通常ens打头的为对应需要修改的网卡地址
tester@testerserver:~$ cat /etc/netplan/00-installer-config.yaml
将次文件的内容修改为
network:
ethernets:
# ip addr 默认 ens33
ens33:
dhcp4: false
# IP 地址
addresses: [192.168.79.8/24]
routes:
- to: default
# 网关 对应宿主机提供的IP
via: 192.168.79.2
nameservers:
# DNS 地址
addresses: [8.8.8.8,114.114.114.114]
dhcp6: false
version: 2
查看修改结果
tester@testerserver:~$ 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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:d3:9f:1e brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.79.8/24 brd 192.168.79.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fed3:9f1e/64 scope link
valid_lft forever preferred_lft forever
IP 生效
tester@testerserver:~$ sudo netplan apply