The shell script automatically configures dual Nic binding

Source: Internet
Author: User


The shell script automatically configures dual-nic binding configuration dual-nic binding is one of the basic operations of O & M. The first configuration will be very rare, and the tenth configuration will be felt like a roll, 30th configuration can be done in two minutes, but there will be a feeling of vomiting blood during the 100th configuration. What should I do? Decisive lazy principle, script writing, automatic configuration. Www.2cto.com #! /Bin/bash # double network cards bond # write by xiaojing. zhao #2012.11.19 cd/etc/sysconfig/network-scripts cp ifcfg-eth0/tmp/ifcfg-eth0.bak cp ifcfg-eth1/tmp/ifcfg-eth1.bak # cp ifcfg-eth0 ifcfg-bond0 # vim eth0 cat ifcfg-eth0 | grep-I hwaddr> ifcfg-eth0.txt # insert SLAVE = yes before HWADDR matches the row, similarly, echo input can also be used to complete www.2cto.com sed-I '/HWADDR/I SLAVE = yes 'ifcfg-eth0.txt sed-I'/SLAVE/I MASTER = bond0 'ifcfg -Eth0.txt sed-I '/MASTER/I BOOTPROTO = none' ifcfg-eth0.txt sed-I'/BOOTPROTO/I DEVICE = eth0 'ifcfg-eth0.txt sed-I'/HWADDR/a listen 6init = no' ifcfg-eth0.txt sed-I '/Listen 6init/a ONBOOT = yes' ifcfg-eth0.txt sed-I '/ONBOOT/a TYPE = Ethernet' ifcfg-eth0.txt sed-I '/TYPE/a PEERDNS = yes' ifcfg-eth0.txt sed -I '/PEERDNS/a USERCTL = no' ifcfg-eth0.txt cat ifcfg-eth0.txt> ifcfg-eth0 # vim eth1 # in matching DEVICE line, Replace (y indicates all) 0 with 1, replace eth0 with eth1 sed-I '/DEVICE/y/0/1/' ifcfg-eth0.txt # variable linehwaddr to retrieve the MAC address of eth1 ''as the wildcard linehwaddr = 'cat/etc/sysconfig/ network-scripts/ifcfg-eth1 | grep-I hwaddr # Replace the MAC address of eth0 with the MAC address sed-I of eth1 '/HWADDR/c \' "$ linehwaddr "'' ifcfg-eth0.txt cat ifcfg-eth0.txt> ifcfg-eth1 # vim bond0 # script universal, you only need to change the following five CIDR blocks, URLs, gateways, broadcast addresses, subnet masks, echo "DEVICE = bond0"> ifcfg-bond0 echo "BOOTPROTO = none"> ifcfg -Bond0 echo "4256init = no"> ifcfg-bond0 echo "ONBOOT = yes"> ifcfg-bond0 echo "TYPE = Ethernet"> ifcfg-bond0 echo "PEERDNS = yes"> ifcfg-bond0 echo" USERCTL = no "> ifcfg-bond0 echo" NETMASK = 255.255.255.0 "> ifcfg-bond0 echo" IPADDR = 10.1.1.250 "> ifcfg-bond0 echo" GATEWAY = 10.1.1.1 "> ifcfg-bond0 echo" BROADCAST = 10.1.1.255"> ifcfg-bond0 echo "NETWORK = 10.1.1.0"> ifcfg-bond0 # vim/etc/modprobe. Conf # append echo "alias bond0 bonding">/etc/modprobe. conf echo "options bond0 miimon = 100 mode = 1">/etc/modprobe. conf # vim/etc/rc. d/rc. local echo "ifenslave bond0 eth0 eth1">/etc/rc. d/rc. local rm-rf/etc/sysconfig/network-scripts/ifcfg-eth0.txt # restart the network ifconfig bond0 upservice network restart echo "double network cards bond complete! "Get it done. Give the execution permission chmod + x bond. sh and execute./bond. sh to check the effect.

✓ Gorgeous split line Listen [root @ nao tmp] # ifconfigbond0 Link encap: Ethernet HWaddr 08: 00: 27: 6E: 72: FE inet addr: 10.1.1.250 Bcast: 10.1.1.255 Mask: 255.255.255.0 inet6 addr: fe80: a00: 27ff: fe6e: 72fe/64 Scope: Link up broadcast running master multicast mtu: 1500 Metric: 1 RX packets: 10954 errors: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 488 errors: 0 dropped: 0 Overruns: 0 carrier: 0 collisions: 0 txqueuelen: 0 RX bytes: 944060 (921.9 KiB) TX bytes: 85171 (83.1 KiB) eth0 Link encap: Ethernet HWaddr 08: 00: 27: 6E: 72: fe up broadcast running slave multicast mtu: 1500 Metric: 1 RX packets: 5598 errors: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 422 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions: 0 txqueuelen: 1000 RX bytes: 487797 (476.3 KiB) TX bytes: 74268 (72.5 KiB) e Th1 Link encap: Ethernet HWaddr 08: 00: 27: 6E: 72: fe up broadcast running slave multicast mtu: 1500 Metric: 1 RX packets: 5361 errors: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 75 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions: 0 txqueuelen: 1000 RX bytes: 456563 (445.8 KiB) TX bytes: 12305 (12.0 KiB) lo Link encap: Local Loopback inet addr: 127.0.0.1 Mask: 255.0.0.0 inet6 addr: 1/128 Scope: Host UP LOOPBAC K running mtu: 16436 Metric: 1 RX packets: 1793 errors: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 1793 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions: 0 txqueuelen: 0 RX bytes: 2907560 (2.7 MiB) TX bytes: 2907560 (2.7 MiB) [root @ nao tmp] # cat/proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008) Bonding Mode: fault-tolerance (active-backup) primary Slave: NoneCurrently Activ E Slave: eth0MII Status: upMII Polling Interval (MS): 100Up Delay (MS): 0 Down Delay (MS): 0 Slave Interface: eth0MII Status: upLink Failure Count: 0 Permanent HW addr: 08: 00: 27: 6e: 72: fe Slave Interface: eth1MII Status: upLink Failure Count: 0 Permanent HW addr: 08: 00: 27: d2: f3: dcOK, the effect has been presented. It can be done in two minutes when you are the most skilled. Now it can be done in two seconds. This is the speed, and this is the efficiency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.