Solved

Add multiple alias Ethernet interfaces

Posted on 2004-09-24
6
1,032 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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