Linux 雙網路卡繫結

Michael_DD發表於2015-02-06
Linux 雙網路卡繫結


指令碼:

點選(此處)摺疊或開啟

  1. #!/bin/bash

  2. GATEWAY=$(echo $1 | awk -F \".\" \'{print $1\".\"$2\".\"$3\".\"1}\')

  3. # this script must excute after stop service

  4. service NetworkManager stop
  5.  [ -z $1 ] && echo $\"Usage: $0 IPADDR\" && exit 2

  6. # backup ifcfgs & modprobe bond

  7. cp /etc/sysconfig/network-scripts/ifcfg-em1 /etc/sysconfig/network-scripts/ifcfg-em1.bak
  8. cp /etc/sysconfig/network-scripts/ifcfg-em2 /etc/sysconfig/network-scripts/ifcfg-em2.bak
  9. #cp /etc/sysconfig/network-scripts/ifcfg-em3 /etc/sysconfig/network-scripts/ifcfg-em3.bak
  10. #cp /etc/sysconfig/network-scripts/ifcfg-em4 /etc/sysconfig/network-scripts/ifcfg-em4.bak
  11. echo \"alias bond0 bonding\" >>/etc/modprobe.d/dist.conf
  12. #echo \"alias bond1 bonding\" >>/etc/modprobe.d/dist.conf

  13. # create new ifcfgs

  14. cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EOF
  15. DEVICE=bond0
  16. BOOTPROTO=none
  17. ONBOOT=yes
  18. NETMASK=255.255.255.0
  19. IPADDR=$1
  20. USERCTL=no
  21. GATEWAY=$GATEWAY
  22. TYPE=Ethernet
  23. BONDING_OPTS=\"mode=1 miimon=100\"
  24. EOF
  25. cat > /etc/sysconfig/network-scripts/ifcfg-em1 << EOF
  26. DEVICE=em1
  27. BOOTPROTO=none
  28. ONBOOT=yes
  29. MASTER=bond0
  30. SLAVE=yes
  31. USERCTL=no
  32. EOF
  33. cat > /etc/sysconfig/network-scripts/ifcfg-em2 << EOF
  34. DEVICE=em2
  35. BOOTPROTO=none
  36. ONBOOT=yes
  37. MASTER=bond0
  38. SLAVE=yes
  39. USERCTL=no
  40. EOF


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1428616/,如需轉載,請註明出處,否則將追究法律責任。

相關文章