Linux对网卡配置多个虚拟IP地址
一、临时增加ip
#ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
#ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
#ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up
......
eth0:x //虚拟网络接口,建立在eth0上,取值范围0-255
192.168.6.xxx //增加ip别名,想加多少就加多少~~
#ifconfig
设置完我们if一下看看,如图所示,增加的ip都已经生效了
#ping 192.168.6.100
#ping 173.173.173.173
#ping 119.110.120.1
然后在本机分别ping一下这几个ip,如果此时不再用的话,那么可以通过down的方式来实现对配置网卡的重启,命令如下:
#ifconfg eth0:0 down
#ifconfg eth0:1 down
#ifconfg eth0:2 down
一、永久增加ip
1 编辑ifcfg-eth0:0
配置文件在/etc/sysconfig/network-scripts/
路径下。
cd /etc/sysconfig/network-scripts/
# more ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.99.159
NETMASK=255.255.255.0
# more ifcfg-eth0:0
DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.159
NETMASK=255.255.255.0
如果还想添加IP地址,可以同理编辑ifcfg-eth0:1
文件.
2 重启网卡生效配置
service network restart
或者
ifconfig eth0 down
ifconfig eth0 up
ifconfig
查看eth0
的网卡信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32989071 errors:0 dropped:0 overruns:0 frame:0
TX packets:3800770 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15974202540 (14.8 GiB) TX bytes:11315842294 (10.5 GiB)
Interrupt:247
eth0:0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.10.10.159 Bcast:10.10.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247
eth0:1 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.11.11.159 Bcast:10.11.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247
还没有评论,来说两句吧...