首页 > 系统 > Linux > 正文

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

2024-08-28 00:02:13
字体:
来源:转载
供稿:网友

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   :eth0Second NIC  :eth1bond name   :bond1IP address  :192.168.56.11netmask    :255.255.255.0bonding_mode :mode=1primary 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 eth3The information you have entered:First NIC   : eth2----------------------------------------------Please select the second NIC:_

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

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------4 network cards available:eth0 eth1 eth2 eth3The information you have entered:First NIC   : eth2----------------------------------------------eth8 is not available,Please enter another one.Please select the second NIC:_

正确输入需要绑定的第二块网卡eth3后,如果linux系统中之前不存在绑定网卡,则默认第一个绑定网卡的名称为bond0,如果系统中存在绑定网卡,脚本会提示输入bondN(N为数字):

---------------------------------------------------- Network Configuration Assistant ----------------------------------------------------The information you have entered:First NIC   : eth2Second NIC  : eth3bond name   : bond0----------------------------------------------The default first bond name is -- bond0.Please enter an IP address:_
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表