临时指定IP地址(重启机器后失效)
sudo ifconfig eth0 192.168.1.111 netmask 255.255.255.0 # 其中‘eth0是当前网卡的名称’
固定静态IP地址配置(重启机器仍有效)
编辑位于/etc/network/interfaces
的配置文件
sudo vim /etc/network/interfaces
vim:
1 # This file describes the network interfaces available on your system
2 # and how to activate them. For more information, see interfaces(5).
3
4 # The loopback network interface
5 auto lo
6 iface lo inet loopback
7
8 # The primary network interface
9 auto eth0 # 当前网卡为‘eth0’
10 iface eth0 inet static # 此处是由‘dhcp’更改为‘static’
11 address 192.168.1.11 # 新的静态IP地址
12 gateway 192.168.1.1 # 网关
13 netmask 255.255.255.0 # 掩码
14 broadcast 192.168.1.255 # 广播地址
修改完成之后不要忘了重启网卡服务,当然你可以选择重启机器:
sudo /etc/init.d/network restart