window中我们可以实现为一个网卡配置多个IP地址与利用本机上的多个网卡实现负载均衡与冗余现在我们来说说如何在Linux操作系统中实现

一 ,为一个网卡配置多个ip地址

 我们以网卡eth0为例说明

我们可以使用ifconfig命令来配置网卡别名来实现一个网卡配置多个ip地址

 Ifconfig eth00 192.168.0.1

Ifconfig eth01 192.168.0.2

Ifconfig eth02 192.168.0.3

Ifconfig eth03 192.168.0.4

结果如下

 

 

但是我们会发现在acl模式下配置的网卡别名只会临时马上生效,在下一次重启网卡或重启Linux系统时就会失效,那么我们怎么办才能使配置永久有效呢?我们可以使用修改配置文件/etc/ifconfig/network-scripts/ifcfg-ethox的方式来永久生效

如: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=eth00

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