CentOS assigns IP script--The first shell script written

Source: Internet
Author: User

IDC small rookie one, non-trained. There are often customers with CentOS servers that need to allocate 15 IPs or even 30 IPs. Each time a manual assignment was cumbersome, it took a day to learn the shell script and write the script.

#!/bin/bash

Read-p "The IP numbers:" num

while [[$num-GT 0]]

Do

Read-p "Please enter IP address:" IPAddr

Touch/etc/sysconfig/network-scripts/ifcfg-eth0: $num

Ncf=/etc/sysconfig/network-scripts/ifcfg-eth0: $num

echo Device=eth0: $num > $NCF

echo type=ethernet >> $NCF

echo bootproto=static >> $NCF

echo ipaddr= $ipaddr >> $NCF

echo netmask=255.255.255.192 >> $NCF

echo Onboot=yes >> $NCF

num= ' expr $num-1 '

Done

Service Network restart

As the company's mask is 255.255.255.192 so direct use, as long as the input needs to allocate the number of IP and IP address.

After writing this script will come in handy immediately, but still think the manual input IP is too troublesome, next time to write a direct from another file to extract the IP address of the script bar.

Write the first script yourself. Full of accomplishment < () >

CentOS assigns IP script--The first shell script written

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.