Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1062
  • Last Modified:

Add multiple alias Ethernet interfaces

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
MikaelEriksson
Asked:
MikaelEriksson
1 Solution
 
liddlerCommented:
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
 
paranoidcookieCommented:
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
 
MikaelErikssonAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
liddlerCommented:
hmm, proably need soft quotes
try
sed "s/XXX/$i"
0
 
MikaelErikssonAuthor Commented:
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
 
omphs_XXXXCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now