ubuntu20.04配置静态IP
配置文件内容:
network:
ethernets:
enp0s3:
dhcp4: false
addresses: [10.16.0.194/16]
optional: true
gateway4: 10.16.255.254
version: 2
改好后使用命令
sudo netplan apply
配置文件位置
/etc/netplan/XXXX.yaml
DHCP 默认
配置文件内容如下
network:
ethernets:
ens33:
dhcp4: yes
addresses: []
version: 2
假设IP地址修改为192.168.1.100,子网掩码24位即255.255.255.0,网关设置为192.168.1.1,DNS1:223.5.5.5,DNS2:223.6.6.6
静态配置文件内容如下
network:
ethernets:
ens33:
dhcp4: no
addresses: [192.168.1.100/24]
optional: true
gateway4: 192.168.1.1
nameservers:
addresses: [223.5.5.5,223.6.6.6]
version: 2
应用新配置:sudo netplan apply
检查新地址: ip addr
测试网络连通性 ping 192.168.1.100 / ping www.google.com
Categories: Garfield's Diary