Automatically generate Linux network adapter configuration script share _linux Shell

Source: Internet
Author: User

Add: This is valid for the first time to add a network card, if you need to repeat the addition and deletion of automatic configuration, you need to change the script, according to the IP a command information to modify.

Copy Code code as follows:

#!/bin/bash
#update: 2013-02-25
#author: Ihuotui
#version 0.1

cdate=$ (date ' +%y%m%d ')
num=$ (ifconfig-a | grep eth | wc-l)
echo "ethx=" $num >> ethx

For ((n=1;n<${num};n++))
Todo

If [-e/etc/sysconfig/network-scripts/ifcfg-eth${n}]; Then

Sed-i '/hwaddr/d '/etc/sysconfig/network-scripts/ifcfg-eth${n}
ifconfig-a | grep "Eth${n}" | awk ' {print ' hwaddr=\ ' $ ' \ '} ' >>/etc/sysconfig/network-scripts/ifcfg-eth${n}

Else

Touch/etc/sysconfig/network-scripts/ifcfg-eth${n}
ifconfig-a | grep "Eth${n}" | awk ' {print ' hwaddr=\ ' $ ' \ '} ' >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo nm_controlled= "\" yes\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo onboot= "\" yes\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo type= "\" Ethernet\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo bootproto= "\" Dhcp\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo uuid= "\" 2460e474-fad8-4b46-baba-da6f45ae158 "${n}" \ ">>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo device= "\" ETH "${n}" \ ">>/etc/sysconfig/network-scripts/ifcfg-eth${n}

Continue
Fi
Done

Related Article

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.