debian与centos上单网卡配置多个IP

debian与contos单网卡绑定多个IP,如果是远程操作的话(如:ssh),切记要重启网卡的时候要 || ifup eth0
否则第二个IP或第二个配置文件有问题将导致网络中断,我的debian就断了….

  1. root@debian:/etc/network# cat interfaces
  2. # This file describes the network interfaces available on your system
  3. # and how to activate them. For more information, see interfaces(5).
  4.  
  5. # The loopback network interface
  6. auto lo
  7. iface lo inet loopback
  8.  
  9. # The primary network interface
  10. allow-hotplug eth0
  11. iface eth0 inet static
  12.         address 10.0.0.212
  13.         netmask 255.255.255.0
  14.         network 10.0.0.0
  15.         broadcast 10.0.0.255
  16.         gateway 10.0.0.1
  17.         # dns-* options are implemented by the resolvconf package, if installed
  18.         dns-nameservers 10.0.0.1
  19. allow-hotplug eth0:1
  20. iface eth0:1 inet static
  21.         address 10.0.0.145
  22.         netmask 255.255.255.0
  23.         network 10.0.0.0
  24.         broadcast 10.0.0.255
  25.         gateway 10.0.0.1

contos单网卡配置多个IP

  1. [root@localhost network-scripts]# ls |grep ifcfg-eth
  2. ifcfg-eth0
  3. ifcfg-eth1
  4. ifcfg-eth2
  5. ifcfg-eth3
  6.  
  7. [root@localhost network-scripts]# cat ifcfg-eth0
  8. # Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
  9. DEVICE=eth0
  10. BOOTPROTO=none
  11. HWADDR=xx:xx:xx:xx:xx:xx
  12. ONBOOT=yes
  13. NETMASK=xxx.xxx.xxx.xxx
  14. IPADDR=xx.xx.xx.xx
  15. GATEWAY=xx.xx.xx.xx
  16. TYPE=Ethernet
  17.  
  18. 直接cp旧的文件,然后改一下就可以了。
  19. 第一个IPeth0
  20. 第二个IPeth0:0
  21. 第三个IPeth0:1
  22. 以此类推
  23. [root@localhost network-scripts]# service network restart || ifup eth0
  24. Shutting down interface eth0:                              [  OK  ]
  25. Shutting down loopback interface:                          [  OK  ]
  26. Bringing up loopback interface:                            [  OK  ]
  27. Bringing up interface eth0:                                [  OK  ]
  28. Bringing up interface eth1:                                [  OK  ]
  29. Bringing up interface eth2:                                [  OK  ]
  30. Bringing up interface eth3:                                [  OK  ]

4 Comments

  1. 一个网卡绑定多个ip,其中一个配置文件出错,会影响整个连接,这个问题倒真是没考虑过。

  2. 感觉还不错,加油



    回复:谢谢海波~

  3. 沙发 这个还能看懂!



    回复:哈哈~方便点