ubuntu 20.04 修改静态IP和dhcp自动分配IP
一、静态分配固定IP
kuaibang@k8smaster:~$ sudo nano /etc/netplan/00-installer-config.yaml # This is the network config written by 'subiquity' network: ethernets: ens160: addresses: - 192.168.1.155/24 gateway4: 192.168.1.1 nameservers: addresses: - 192.168.1.1 search: - localhost version: 2
说明:
1、ens160 网卡名称(配置的网卡名称要和修改的一样)
2、addresses 固定IP
3、gateway4 网关
4、nameservers 设置DNS
二、dhcp自动分配IP
kuaibang@k8smaster:~$ sudo nano /etc/netplan/00-installer-config.yaml # This is the network config written by 'subiquity' network: ethernets: enp2s0: dhcp4: true version: 2
三、使其配置文件生效
sudo netplan apply
四、查看是否生效
ifconfig