永久设置Ubuntu的IP地址

1. 查看当前Ubuntu的IP地址是多少?
gec@ubuntu:~$ ifconfig
lo Link encap:Local Loopback -> 当前只有lo回环IP,没有以太网卡,需要主动激活网卡。
inet addr:127.0.0.1 Mask:255.0.0.0

2. 激活以太网
gec@ubuntu:~$ sudo ifconfig eth0 up

3. 再次查看
gec@ubuntu:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:5d:9c:76
inet6 addr: fe80::20c:29ff:fe5d:9c76/64 Scope:Link -> 已经激活以太网卡,但是还没设置IP地址。

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0

4. 打开设置IP地址的配置文件
gec@ubuntu:~$ sudo vi /etc/network/interfaces

auto lo
iface lo inet loopback

audo eth0 -> 修改: auto eth0
iface eth0 inet static
address 192.168.0.245 -> 修改:address 192.168.xx.xx      (这里我改的是192.168.90.15)
gateway 192.168.0.1    -> 修改:gateway 192.168.xx.1       (注意地址跟网关同网段)
netmask 255.255.255.0

保存退出!

5. 重启网络
gec@ubuntu:~$ sudo /etc/init.d/networking restart
* Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
* Reconfiguring network interfaces... [OK]

6. 重启虚拟机,再次查看IP地址
gec@ubuntu:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:5d:9c:76
inet addr:192.168.90.15 Bcast:192.168.90.255 Mask:255.255.255.0

猜你喜欢

转载自www.cnblogs.com/xdd-sdyp/p/11793953.html