Solved

Add multiple alias Ethernet interfaces

Posted on 2004-09-24
6
1,026 Views
Last Modified: 2010-03-18
I need to create 126 alias interfaces of eth1 (eth1:1 - eth1:126).
I know how to do this in the GUI and manually by creating /etc/sysconfig/network-scripts/ifcfg-eth1:1, ifcfg-eth1:2.....

Created a shell script, very simple because I'm not a good at scripting.
---
#!/bin/bach
for ((i = 2 ; i <=126; i++ ))
do
  cp /etc/sysconfig/network-scripts/ifcfg-eth1:1 /etc/sysconfig/network-scripts/ifcfg-eth1:$i
done
---
The script works fine and creates all the files I need. But, I dont want to manually edit all the files to set the Interface name and IP.

Is there a quicker way of creating alias interfaces or could someone help me to create a script that changes the interface and IP automatically?

Also, I tried the use "ifconfig eth1:2 192.168.0.100 netmask 255.255.255.128 up"
Works fine until I restart the server, then all alias interfaces are gone.

Need a quick answer to this one!
0
Comment
Question by:MikaelEriksson
6 Comments
 
LVL 18

Expert Comment

by:liddler
ID: 12141351
create a template file somethink like
/tmp/template
containing the ip address info you need, put with the IP address 192.168.0.XXX
then instead of the copy, do something like:
sed 's/XXX/$i' /tmp/template > /etc/sysconfig/network-scripts/ifcfg-eth1:$i

haven't tested it, but that should do you
0
 
LVL 5

Expert Comment

by:paranoidcookie
ID: 12141622
What Linux are you using in debian there is a file /etc/network/interfaces which contains a list of all interfaces and whether or not to start them at boot I assume other Linux vendors will have similar files.
0
 
LVL 1

Author Comment

by:MikaelEriksson
ID: 12141925
Thanks for the input.
I can't get "sed 's/XXX/$i' /tmp/template > /etc/sysconfig/network-scripts/ifcfg-eth1:$i" to work from the script.
It will replace XXX but not with the number, it's replaced by $i instead.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 18

Accepted Solution

by:
liddler earned 250 total points
ID: 12142070
hmm, proably need soft quotes
try
sed "s/XXX/$i"
0
 
LVL 1

Author Comment

by:MikaelEriksson
ID: 12142948
I'm sure you are right. I have already done the job manually.
It was needed to be done really quick and instead of learning to script I was learning emacs :-)

Thanks anyway!

Ps. liddler, I'll use your tip next time and give you the credit for helping me.
0
 

Expert Comment

by:omphs_XXXX
ID: 12388101
try to add some script in your rc.local
$/sbin/ifconfig eth1:1 <ip address> netmask <your subnetmask> up
.
.
.
$/sbin.ifconfig eth1:n <ip address> netmask <your subnetmask> up

#then add route for each device syntax.
$route add -host <ip address> dev eth1:<youralias>
.
.
.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now