Linux
Debian/Ubuntu网卡IP配置
配置文件:/etc/network/interfaces
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet static
address 192.168.56.223
netmask 255.255.255.0
---------------------------------
1、allow-hotplug 与 auto 的理论区别
auto
auto
在系统启动的时候启动网络接口,无论网络接口有无连接 (插入网线)。
假如该接口配置了 DHCP,则无论有无网线,系统都会去获取 DHCP。
并且假如没有插入网线,则等该接口超时后才会继续 DHCP。
allow-hotplug
allow-hotplug
只有当内核从网络接口检测到热插拔事件后才会启动该接口。假如系统开机时该接口没有插入网线,则系统不会启动该接口。
系统启动后,假如插入网线,系统会自动启动该接口。也就是将网络接口设置为热插拔模式。
1. 以DHCP方式配置网卡
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
也可以在命令行下直接输入下面的命令来获取地址
sudo dhclient eth0
2. 为网卡配置静态IP地址
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
#network 192.168.3.0
#broadcast 192.168.3.255
将上面的ip地址等信息换成你自己即可以了.用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
3. 设定第二个IP地址(虚拟IP地址)
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
在该文件中增加如下的行:
auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x