Ubuntu 16.04下配置IP的方法在Ubuntu 18.04上面已经行不通了,新的采用的是netplan作为网络配置管理工具,与16.04使用的 /etc/network/interfaces不一样。
Ubuntu 18.04下netplan的配置文件在 /etc/netplan/*.yaml ( 所有 yaml 结尾的文件 )
如某个VPS文件在 /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [ '209.141.1x.x/24', '209.141.4x.x/24', '2605:6400:0020:x/48' ]
gateway4: 209.141.1x.1
gateway6: 2605:6400:0020::1
nameservers:
addresses: [ '205.185.112.68', '205.185.112.69' ]
如果你的路由支持dhcp,可以将dhcp设置为true,否则设置为false,使用静态IP。
注意,dhcp分为IPV4和IPV6需要分别设置。
若使用静态IP,则需要设置:addresses、gateway、nameservers三项,即地址、网关和DNS。其中IP地址可以设置多个,用英文逗号加以分割,IP地址后要加子网掩码,IPV4和IPV6写在一起。网关的设置IPV4和IPV6要分开,DNS的设置IPV4和IPV6可写到一起,用英文逗号分开。
配置文件编写完成后,使用下面命令使其生效。
sudo netplan apply