永久修改静态IP、DHCP自动获取IP
1. 修改 /etc/network/interfaces 配置文件:
$ sudo vi /etc/network/interfaces
静态配置IP方式:
#静态ip设置方式
auto lo
iface lo inet loopback
#ens33为网卡名,ifconfig可查看网卡名
auto ens33
iface ens33 inet static
address 192.168.11.111
netmask 255.255.255.0
gateway 192.168.11.1
#设置dns服务器
dns-nameservers 119.29.29.29
DHCP方式:
#dhcp方式获取ip配置
auto lo
iface lo inet loopback
#ens33为网卡名,ifconfig可查看网卡名
auto ens33
iface ens33 inet dhcp
2. 重启网卡,使之配置生效
$ sudo /etc/init.d/networking restart
或者
$ ifdown eth0 //关闭网卡
$ ifup eth0 //启动网卡
还不行的话重启Ubuntu,再次查看IP已经修改
临时修改IP:
$ ifconfig erh0 192.168.1.28 255.255.255.0