17.10以前的配置方法
设置IP和掩码
ifconfig eth0 192.168.5.40 netmask 255.255.255.0
设置网关
route add default gw 192.168.5.1
ubuntu 18.04配置ip
据说从17.10开始,ip配置就已经从 (/etc/network/interfaces) 换到了/etc/netplan/*.yaml 。两个配置为NetworkManager 和 networkd。NetworkManager可以使用GUI配置,否则就要用networkd。
下面为dhcp动态ip配置:
>> network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: yes
dhcp6: yes
配置完以后,需要应用一下
> sudo netplan apply
下面为静态ip配置:
# This file describes the network interfaces available on your system# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
配置完以后,需要应用一下
> sudo netplan apply