Wednesday, 2 October 2013

Introducing the concept of IP Aliasing in one of my previous articles - How To : Create an Alias for a Network Interface Card in Ubuntu/Linux Mint I have written : "The process in which multiple addresses are created on a single network interface, is known as "IP Aliasing". IP Aliasing will be very much useful when you need multiple IP addresses to set up multiple virtual sites on Apache making the use of only one network adapter. The most important advantage of IP Aliasing is that you do not need one hardware per IP Address, rather you can generate a pool of virtual network interfaces (i.e. Aliases) on a single device."

We have seen, in the said article, how aliases can be created using the 'ifconfig' command. Creating a few aliases may not be difficult, but as the number of aliases rises, the job becomes more and more tiresome and time consuming. As a solution for this, we may make use of BASH Scripts to create desired number of aliases using single network interface card. BASH Scripts are efficient and can be executed on every system reboot.

In this article, we will assign a pool of IP addresses to a network interface card using a BASH Script. If you are new to Shell Scripting, please read my article - Getting Started : Linux Shell Scripting Language and then go through this one.

Let's create a Script!

First of all, you need to create an empty file with .sh as an extension.

touch Aliases.sh

Edit the file with your favorite text editor.

sudo gedit Aliases.sh

Now, Scripting Time! Let us consider, we have to create 30 aliases. Of course, you can create as many aliases as you want.

For the script to be executed on every system reboot, you should edit the /etc/rc.local file and add a line mentioning the path to the script (say /home/user/Desktop/Aliases.sh) to the end of that file. One thing should be noted that, this file might be missing in various distributions, you are advised to consult with distribution's docs to find it's location.