直接在/etc/profile文件末尾添加ifconfig ens33 192.168.1.177也可以
一、终端输入
ifconfig
查看当前使用的网卡,如图所示,网卡为ens33,当前IP为192.168.1.115.
二、终端输入
sudo vim /etc/network/interfaces
在文件中添加如下内容,保存文件,最终内容如下图所示:
auto ens33
iface ens33 inet static
address 192.168.1.116
gateway 192.168.1.1
netmask 255.255.255.0
dns-nameserver 8.8.8.8
重启网络
sudo /etc/init.d/networking restart
三、验证
重启ubuntu,打开终端输入ifconfig,查看IP是否和自己设置的IP一致