• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

水底的小鱼鱼

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

bond

读取文件2块网卡自动做bond

#!/bin/bash
em1=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '1p'`
em2=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '2p'`
IP=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '3p'`
NT=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '4p'`
GW=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '5p'`
ifc="/etc/sysconfig/network-scripts/ifcfg-"
echo $em1,$em2,$IP,$NT,$GW
cat $ifc`echo $em1`
cat > /etc/sysconfig/network-scripts/ifcfg-bond0 <<EOF
TYPE=Bond
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
USERCTL=no
NM_CONTROLLED=no
BONDING_MASTER=yes
BONDING_OPTS="miimon=200 mode=1"
NAME=bond0
IPADDR=`echo $IP`
PREFIX=`echo $NT`
GATEWAY=`echo $GW`
DNS1=8.8.8.8
EOF
cat > $ifc`echo $em1` <<EOF
DEVICE=`echo $em1`
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=`echo $em1`
MASTER=bond0
SLAVE=yes
EOF
cat > $ifc`echo $em2` <<EOF
DEVICE=`echo $em2`
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=`echo $em2`
MASTER=bond0
SLAVE=yes
EOF
cat > /etc/modprobe.d/bond.conf <<EOF
alias bond0 bonding
options bond0 miimon=200 mode=1
EOF
 
cat > /etc/sysconfig/modules/bonding.modules <<EOF
#!/usr/bin/bash
/usr/sbin/modinfo -F filename bonding > /dev/null 2>&1
if [ $? -eq 0 ];then
/usr/sbin/modprobe bonding
fi
EOF
chmod 755 /etc/sysconfig/modules/bonding.modules
systemctl stop NetworkManager
systemctl disable NetworkManager

文件内容

bond 第一块网卡:eth0
bond 第二块网卡:eth1
bond 后的ip    :10.10.10.10
bond 后的掩码  :24
bond 后的网关  :192.1668.0.1

 2块网卡bond后桥架br0

#!/bin/bash
em1=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '1p'`
em2=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '2p'`
IP=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '3p'`
NT=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '4p'`
GW=`cat /root/bond.txt |awk -F ':' '{print $2}'|sed -n '5p'`
ifc="/etc/sysconfig/network-scripts/ifcfg-"
echo $em1,$em2,$IP,$NT,$GW
cat $ifc`echo $em1`
cat > $ifc`echo $em1` <<EOF
DEVICE=`echo $em1`
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=`echo $em1`
MASTER=bond0
SLAVE=yes
EOF
cat > $ifc`echo $em2` <<EOF
DEVICE=`echo $em2`
TYPE=Ethernet
BOOTPROTO=none
USERCTL=no
ONBOOT=yes
NAME=`echo $em2`
MASTER=bond0
SLAVE=yes
EOF
cat >/etc/sysconfig/network-scripts/ifcfg-bond0 << EOF
DEVICE=bond0
TYPE=Bond
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0
BONDING_MASTER=yes
BONDING_OPTS="mode=1 miimon=200"
EOF
cat >/etc/sysconfig/network-scripts/ifcfg-br0 <<EOF
TYPE=Bridge
BOOTPROTO=static
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=`echo $IP`
PREFIX=`echo $NT`
GATEWAY=`echo $GW`
DNS1=8.8.8.8
USERCTL=no
DEFROUTE=yes
EOF
cat > /etc/modprobe.d/bond.conf <<EOF
alias bond0 bonding
options bond0 miimon=200 mode=1
EOF

cat > /etc/sysconfig/modules/bonding.modules <<EOF
#!/usr/bin/bash
/usr/sbin/modinfo -F filename bonding > /dev/null 2>&1
if [ $? -eq 0 ];then
/usr/sbin/modprobe bonding
fi
EOF
chmod 755 /etc/sysconfig/modules/bonding.modules
systemctl stop NetworkManager
systemctl disable NetworkManager

 

posted on 2020-02-07 10:02  水底的小鱼鱼  阅读(323)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3