在window中我們可以實現為一個網卡配置多個IP地址與利用本機上的多個網卡實現負載均衡與冗余現在我們來說說如何在Linux操作系統中實現
一 ,為一個網卡配置多個ip地址
我們以網卡eth0為例說明
我們可以使用ifconfig命令來配置網卡別名來實現一個網卡配置多個ip地址
Ifconfig eth0:0 192.168.0.1
Ifconfig eth0:1 192.168.0.2
Ifconfig eth0:2 192.168.0.3
Ifconfig eth0:3 192.168.0.4
結果如下

但是我們會發現在acl模式下配置的網卡別名只會臨時馬上生效,在下一次重啟網卡或重啟Linux系統時就會失效,那麼我們怎麼辦才能使配置永久有效呢?我們可以使用修改配置文件/etc/ifconfig/network-scripts/ifcfg-etho:x的方式來永久生效
如:1, cd /etc/ifconfig/network-scripts 使用cd命令切換到network-scripts目錄下
2, mkdir ifcfg-eth0:0 ifcfg-eth0:1 ifcfg-eth0:2 ifcfg-eth0:3
3, vim ifcfg-eth0:0 用vim打開ifcfg-eth0:0文件並寫入如下
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.1
NETMASK=255.255.255.0
HWADDR=00:0c:29:18:6e:35
保存並退出
依照上述創建ifcfg-eth0:1 ,ifcfg-eth0:2 ,ifcfg-eth0:3 文件
重啟網卡
Ifdown eth0
Ifup eth0
二,用BOND實現網卡的負載均衡和冗余
在網絡服務中為了保持網絡的暢通有時需要利用多個網卡來實現網絡的負載均衡和冗余,在Linux中我們利用bond模塊來實現 網卡以eth0 和eth1為例
首先我們需要加載bond模塊
Vim /etc/modprobe.conf 打開/etc/modprobe.conf
在文件中輸入 alias bond0 bonging

並加載bonding模塊
Modprobe bonding
2,修改/etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-eth1
DEVICE=eth0
MASTER=bond0
SLAVE=yes
ONBOOT=yes
BOOTPROTO=none

3,創建 /etc/sysconfig/network-scripts/ifcfg-bond0
Device=bond0
Bootproto=none
Ipaddr=
Natmask=
Gateway=
Onboot=
Bonding_opyion=“mode=1 miion=50 primary=eth0”

其中mode=0表示實現冗余 primary=eth0表示默認網卡是eth0
Mode=1 表示實現負載均衡
重啟網絡服務 ifdown bond0
Ifup bond0