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
浙公网安备 33010602011771号