这里的IP配置方法适用于Ubuntu18之前的版本,即修改/etc/network/interfaces配置文件。
手动配置
若要手动指定IP,需要对eth0网卡做如下配置:
auto eth0 #使用auto设置eth0在系统启动时自启
iface eth0 inet static #设置eth0为手动(静态)配置,而不是采用dhcp
address 192.168.x.x #设置IPv4地址
netmask 255.255.255.0 #设置子网掩码
gateway 192.168.1.1 #设置网关
使用DHCP自动配置
auto eth0
iface eth0 inet dhcp
生效
重启网络服务生效:
service networking restart
或者,重启系统:
reboot