CentOS 设置多个IP

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

debia单网卡配置多个IP

  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. # The loopback network interface
  5. auto lo
  6. iface lo inet loopback
  7. # The primary network interface
  8. allow-hotplug eth0
  9. iface eth0 inet static
  10. address 10.0.0.212
  11. netmask 255.255.255.0
  12. network 10.0.0.0
  13. broadcast 10.0.0.255
  14. gateway 10.0.0.1
  15. # dns-* options are implemented by the resolvconf package, if installed
  16. dns-nameservers 10.0.0.1
  17. allow-hotplug eth0:1
  18. iface eth0:1 inet static
  19. address 10.0.0.145
  20. netmask 255.255.255.0
  21. network 10.0.0.0
  22. broadcast 10.0.0.255
  23. 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. [root@localhost network-scripts]# cat ifcfg-eth0
  7. # Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
  8. DEVICE=eth0
  9. BOOTPROTO=none
  10. HWADDR=xx:xx:xx:xx:xx:xx
  11. ONBOOT=yes
  12. NETMASK=xxx.xxx.xxx.xxx
  13. IPADDR=xx.xx.xx.xx
  14. GATEWAY=xx.xx.xx.xx
  15. TYPE=Ethernet
  16. 直接cp旧的文件,然后改一下就可以了。
  17. 第一个IP是 eth0
  18. 第二个IP是 eth0:0 (创建文件ifcfg-eth0:0,并把DEVICE改为eth0:0)
  19. 第三个IP是 eth0:1 (创建文件ifcfg-eth0:1,并把DEVICE改为eth0:1)
  20. 以此类推
  21. [root@localhost network-scripts]# service network restart || ifup eth0
  22. Shutting down interface eth0: [ OK ]
  23. Shutting down loopback interface: [ OK ]
  24. Bringing up loopback interface: [ OK ]
  25. Bringing up interface eth0: [ OK ]
  26. Bringing up interface eth1: [ OK ]
  27. Bringing up interface eth2: [ OK ]
  28. Bringing up interface eth3: [ OK ]