Linux Server batch bind ip script

Source: Internet
Author: User
Article Title: linux Server batch binding ip scripts. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In order to optimize the Google ranking of websites, it is certainly impossible for 200 or 300 websites on a server to use one Ip address. Therefore, we generally need around two hundred Ip addresses on our servers, after the server is purchased and delivered for use, in addition to the configuration optimization server, of course, you also need to buy more IP addresses and bind them to the server. Take softlayer as an example. After you pay for the IP address, they send the ip address to your registered email address, for example, the following email:

 
The ip address format is 1.1.1.1-1.1.1.20.
When you buy a lot, there will be many Ip addresses in this format, which is confusing to bind, so you have compiled the following script for batch binding. Hope to help readers
First, put all IP addresses in a file named allips, as shown below:

 
Create the bindips. sh script file.
The script is as follows:
#! /Bin/bash
Cat allips | awk '{print $1}', fips
Cat allips | awk '{print $3}', lips
Range = 1
Han = 1
Ban = 1
For fips in 'cat fips'
Do
Lips = 'sed-n "$ han" p lips'
Fipslast = 'echo $ fips | awk-F. '{print $4 }''
Lipslast = 'echo $ lips | awk-F. '{print $4 }''
Chashu = $ ($ lipslast-$ fipslast + 1 ))
Cat>/etc/sysconfig/network-scripts/ifcfg-eth1-range $ range EOF
IPADDR_START = $ fips
IPADDR_END = $ lips
NETMASK = 255.255.255.255.255
CLONENUM_START = $ ban
EOF
Ban = $ ($ ban + $ chashu ))
Han = $ ($ han + 1 ))
Range = $ ($ range + 1 ))
Done
Complete
Script explanation
Fips stores all the first IP addresses, that is, all left-side IP addresses
Lips stores all the last Ip addresses, that is, all the Ip addresses on the right.
#! /Bin/bash
Cat allips | awk '{print $1}', fips # import all the IP addresses on the left to the fips file.
Cat allips | awk '{print $3}', lips # import all the IP addresses on the right to the lips File
Range = 1 # Set the start value of range (about range, explained at the end of this article)
Han = 1 # Set the starting value for reading the lips row
Ban = 0 # Set the starting value of the virtual network card
For fips in 'cat fips '# Read all Ip addresses in fips
Do
Lips = 'sed-n "$ han" p lips' # Find the corresponding IP address in the lips File
Fipslast = 'echo $ fips | awk-F. '{print $4} ''# Find the value of the D segment of fips.
Lipslast = 'echo $ lips | awk-F. '{print $4} ''# Find the value of the D segment of lips.
Chashu = $ ($ lipslast-$ fipslast + 1) # Add 1 to the value of D segment of lips minus the value of D segment of lips, all available Ip addresses of this ip segment
Cat>/etc/sysconfig/network-scripts/ifcfg-eth1-range $ range EOF
IPADDR_START = $ fips
IPADDR_END = $ lips
NETMASK = 255.255.255.255.255
CLONENUM_START = $ ban
EOF
# Create/etc/sysconfig/network-scripts/ifcfg-eth1-range? File and import the content. The content is the starting ip address, ending ip address, and the starting value of the bound virtual Nic.
Ban = $ ($ ban + $ chashu) # The starting value of the virtual network card bound to the next IP segment is added to the NIC value bound after one loop.
Han = $ ($ han + 1) # Read the value of the next line of lips after one loop
Range = $ ($ range + 1) # write the next range after one loop
Done # End
Run the script file
Sh bindips. sh
Restart network
Service network restart (the remote server must be restart, otherwise it will be disconnected)
All the IP addresses can be bound. Now all the IP addresses have been completed. If you do not understand, contact me for technical exchange: QQ: 410018348
Range knowledge: (I personally understand)
The range in the linux Nic should be an ip address range, which contains many parameters. The most important parameters are the starting ip address, ending Ip address, starting value of the NIC, and subnet mask, whether to bind to the instance upon startup (enabled by default)
For example:
IPADDR_START = 192.126.1.1
IPADDR_END = 192.168.1.20
NETMASK = 255.255.255.255.255
CLONENUM_START = 1
In the preceding example, IPADDR_START is the starting ip address.
IPADDR_END: end IP Address
NETMASK: Subnet Mask

[1] [2] Next page

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.