CentOS6下4网口绑定双IP
1. 基础信息介绍
4个物理网口分别是:eth0,eth1(集成网卡),eth2,eth3(外置网卡)
其中,
内置网卡eth0和eth1绑定到bond0(192.168.224.201),模式bond0
新增网卡eth2和eth3绑定到bond1(192.168.214.118),模式bond0
2. 内置网卡设置
2.1. 配置设定文件
2.2.1. 配置bond0
# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 BOOTPROTO=none #static ONBOOT=yes IPADDR=192.168.224.201 NETMASK=255.255.255.0 NETWORK=192.168.224.254 USERCTL=no
2.1.2. 配置eth0
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none #static ONBOOT=yes MASTER=bond0 SLAVE=yes USERCTL=no
2.1.3. 配置eth1
# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 BOOTPROTO=none #static ONBOOT=yes MASTER=bond0 SLAVE=yes USERCTL=no
2.2. 修改modprobe相关设定文件,并加载模块
2.2.1. 修改文件
#vi /etc/modprobe.d/modprobe.conf alias bond0 bonding options bonding mode=0 miimon=200
2.2.2. 加载模块
modprobe bonding
2.2.3. 确认模块是否加载成功
# lsmod | grep bonding bonding 100065 0
2.3. 重启网络,确认状态
# /etc/init.d/network restart
# cat /proc/net/bonding/bond0
查看那个网卡已经有网线接入(不论网络是否已通)
注:2根网线同时插入时,先插入的生效,后插入的不生效
2.4. 网络测试
使用同网段的终端设备访问bond0地址。
3. 新增网卡设置
3.1. 网卡检查
1) 请关闭服务器插入网卡
2) 重启服务器后连接网线到192.168.214.0段的交换机上
3) 检查网卡指示灯
4) 如果网卡指示灯亮了,进行以下操作
3.2. 配置设定文件
3.2.1. 配置bond1
如果没有bond1文件请拷贝bond0进行修改
# vi /etc/sysconfig/network-scripts/ifcfg-bond1 DEVICE=bond1 BOOTPROTO=none #static ONBOOT=yes IPADDR=192.168.214.118 NETMASK=255.255.255.0 NETWORK=192.168.214.254 USERCTL=no
3.2.2. 配置eth2
如果没有eth2文件请拷贝eth0进行修改
# vi /etc/sysconfig/network-scripts/ifcfg-eth2 DEVICE=eth2 BOOTPROTO=none ONBOOT=yes MASTER=bond1 SLAVE=yes USERCTL=no
3.2.3. 配置eth3
如果没有eth3文件请拷贝eth00进行修改
# vi /etc/sysconfig/network-scripts/ifcfg-eth3 DEVICE=eth3 BOOTPROTO=none ONBOOT=yes MASTER=bond1 SLAVE=yes USERCTL=no
3.3. 加载模块
3.3.1. 修改文件
# vi /etc/modprobe.d/modprobe.conf alias bond0 bonding #options bonding mode=0 miimon=200 alias bond1 bonding options bonding max_bonds=2 miimon=200 mode=0
注:红色字体表示变动的部分
3.3.2. 加载模块
# modprobe bonding
3.3.3. 确认模块是否加载成功
# lsmod | grep bonding bonding 100065 0
3.4. 重启网络,确认状态
# /etc/init.d/network restart # cat /proc/net/bonding/bond0 # cat /proc/net/bonding/bond1
查看那个网卡已经有网线接入(不论网络是否已通)
注:2根网线同时插入时,先插入的生效,后插入的不生效
3.5. 检查/添加路由
检查新增网段192.168.214.*段的路由是否存在
# route
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.224.0 * 255.255.255.0 U 0 0 0 bond0 link-local * 255.255.0.0 U 1006 0 0 bond0 default bogon 0.0.0.0 UG 0 0 0 bond0
经检查上述路由新增网段192.168.214.*段的路由不存在,执行以下命令增加路由
# route add 192.168.214.118 mask 255.255.255.0 192.168.214.254
再次检查,路由添加是否成功
# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.224.0 * 255.255.255.0 U 0 0 0 bond0 192.168.214.0 * 255.255.255.0 U 0 0 0 bond1 link-local * 255.255.0.0 U 1006 0 0 bond0 link-local * 255.255.0.0 U 1007 0 0 bond1 default bogon 0.0.0.0 UG 0 0 0 bond0
检查到黄色背景的2行,确认路由已经添加成功
3.6. 地址测试
# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP qlen 1000 link/ether 1c:87:2c:cb:36:c6 brd ff:ff:ff:ff:ff:ff 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc mq master bond0 state DOWN qlen 1000 link/ether 1c:87:2c:cb:36:c6 brd ff:ff:ff:ff:ff:ff 4: eth2: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc mq master bond1 state DOWN qlen 1000 link/ether 58:53:c0:34:0f:e8 brd ff:ff:ff:ff:ff:ff 5: eth3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond1 state UP qlen 1000 link/ether 58:53:c0:34:0f:e8 brd ff:ff:ff:ff:ff:ff 6: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 1c:87:2c:cb:36:c6 brd ff:ff:ff:ff:ff:ff inet 192.168.224.201/24 brd 192.168.224.255 scope global bond0 inet6 fe80::1e87:2cff:fecb:36c6/64 scope link valid_lft forever preferred_lft forever 7: bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 58:53:c0:34:0f:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.214.118/24 brd 192.168.214.255 scope global bond1 inet6 fe80::5a53:c0ff:fe34:fe8/64 scope link valid_lft forever preferred_lft forever
可见,eth0和eth3网口已经连接,bond0和bond1均已经可用状态,接下来可以测试网络是否可达。
3.7. IP访问测试
在192.168.224.0网段测试192.168.224.201地址是否可达:
在192.168.214.0网段测试192.168.214.118地址是否可达:
4. 常见问题
4.1. route 没有那个进程
问题分析:
1、可能是命令有错误,需检查route命令
2、可能是网络设置未生效,请重启网络或者重启服务器