Linux双网卡绑定脚本的方法示例

2019-10-09 11:57:38刘景俊

linux运维及配置工作中,常常会用到双网卡绑定,少数几台服务器的配置还好,如果是需要配置几十甚至上百台,难免会枯燥乏味,易于出错,我编写了这个双网卡绑定的辅助脚本,可傻瓜式地完成linux双网卡绑定工作,当然,该脚本主要还是用于小批量的系统配置,如需配置大量的服务器,可提取脚本中的bonding函数,稍作修改即可,你值得一试!

1.适用范围

该shell脚本可在以下linux系统创建多个绑定网卡,用于生产环境没问题的:

Redhat 5.x CentOS 5.x Kylin 3.x KUX 2.x

2.脚本特点

----------------------------------------------
------ Network Configuration Assistant ------
----------------------------------------------

The information you have entered:

First NIC   :eth0
Second NIC  :eth1
bond name   :bond1
IP address  :192.168.56.11
netmask    :255.255.255.0
bonding_mode :mode=1
primary NIC  :none
----------------------------------------------

Pls make sure its OK[y/n]:y

如上,脚本在使用过程中,会依次提示输入需要绑定的子网卡名称、绑定网卡名称、IP地址和子网掩码、绑定模式、是否指定主网卡,并主动对系统中可用网卡进行识别并列出,供用户选择,同时会判断输入的各项信息的正确性,保障双网卡绑定顺利进行。

3.使用说明

首先将脚本上传至linux系统任意目录下,使用root用户执行:

[root@node1 tmp]# sh bonding_v2.0.sh 

----------------------------------------------
------ Network Configuration Assistant ------
----------------------------------------------

 
4 network cards available:
eth0 eth1 eth2 eth3
----------------------------------------------

Please enter the First NIC:_

首先脚本会列出系统中有多少可用网卡,并提示输入需要绑定的第一块子网卡的名称,这里输入eth2。

无需担心输入错误,输入重复等问题,脚本会自动判断你的输入信息是否正确。

----------------------------------------------
------ Network Configuration Assistant ------
----------------------------------------------

4 network cards available:
eth0 eth1 eth2 eth3

The information you have entered:
First NIC   : eth2
----------------------------------------------

Please select the second NIC:_

接着输入需要绑定的第二块网卡的名称eth3,如果输入错误会出现相应的提示,比如错输入为eth8,会提示需要重新输入:

----------------------------------------------
------ Network Configuration Assistant ------
----------------------------------------------

4 network cards available:
eth0 eth1 eth2 eth3

The information you have entered:
First NIC   : eth2
----------------------------------------------

eth8 is not available,Please enter another one.

Please select the second NIC:_