Ubuntu 从 17.10 开始,已放弃在
/etc/network/interfaces
里固定IP的配置,而是改成 netplan 方式,Ubuntu 20.04.3配置文件是/etc/netplan/00-installer-config.yaml
配置文件
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
addresses:
- 10.0.0.4/24
gateway4: 10.0.0.1
nameservers:
addresses: [114.114.114.114]
search: []
version: 2
配置完成后,使用 netplan apply
让其配置生效
ifconfig 配置临时 IP 和掩码
# 配置 IP 地址和掩码
$ ifconfig eth0 10.0.0.2 netmask 255.255.255.0
#设置网关
$ route add default gw 10.0.0.1