Solved

Add multiple alias Ethernet interfaces

Posted on 2004-09-24
6
1,007 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

17 Experts available now in Live!

Get 1:1 Help Now