Linux对网卡配置多个虚拟IP地址

╰半橙微兮° 2022-10-11 01:23 321阅读 0赞

一、临时增加ip

  1. #ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
  2. #ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
  3. #ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up
  4. ......

eth0:x //虚拟网络接口,建立在eth0上,取值范围0-255
192.168.6.xxx //增加ip别名,想加多少就加多少~~

  1. #ifconfig

设置完我们if一下看看,如图所示,增加的ip都已经生效了

  1. #ping 192.168.6.100
  2. #ping 173.173.173.173
  3. #ping 119.110.120.1

然后在本机分别ping一下这几个ip,如果此时不再用的话,那么可以通过down的方式来实现对配置网卡的重启,命令如下:

  1. #ifconfg eth0:0 down
  2. #ifconfg eth0:1 down
  3. #ifconfg eth0:2 down

一、永久增加ip

1 编辑ifcfg-eth0:0

配置文件在/etc/sysconfig/network-scripts/路径下。

  1. cd /etc/sysconfig/network-scripts/
  2. # more ifcfg-eth0
  3. DEVICE=eth0
  4. TYPE=Ethernet
  5. ONBOOT=yes
  6. NM_CONTROLLED=yes
  7. BOOTPROTO=static
  8. IPADDR=192.168.99.159
  9. NETMASK=255.255.255.0
  10. # more ifcfg-eth0:0
  11. DEVICE=eth0:0
  12. TYPE=Ethernet
  13. ONBOOT=yes
  14. NM_CONTROLLED=yes
  15. BOOTPROTO=static
  16. IPADDR=10.10.10.159
  17. NETMASK=255.255.255.0

如果还想添加IP地址,可以同理编辑ifcfg-eth0:1文件.

2 重启网卡生效配置

  1. service network restart

或者

  1. ifconfig eth0 down
  2. ifconfig eth0 up

ifconfig查看eth0的网卡信息:

  1. # ifconfig
  2. eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
  3. inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
  4. inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  6. RX packets:32989071 errors:0 dropped:0 overruns:0 frame:0
  7. TX packets:3800770 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:1000
  9. RX bytes:15974202540 (14.8 GiB) TX bytes:11315842294 (10.5 GiB)
  10. Interrupt:247
  11. eth0:0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
  12. inet addr:10.10.10.159 Bcast:10.10.10.255 Mask:255.255.255.0
  13. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  14. Interrupt:247
  15. eth0:1 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
  16. inet addr:10.11.11.159 Bcast:10.11.11.255 Mask:255.255.255.0
  17. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  18. Interrupt:247

发表评论

表情:
评论列表 (有 0 条评论,321人围观)

还没有评论,来说两句吧...

相关阅读