Heres a little program I just wrote... when you are adding alot of IP's
it REALLY speeds things up. Especially when the IP's are all different
and not in sequence. Thanks for the inspiration Swami. ;-) Read the notes.
PHP Code:
# Run the program from the shell prompt like this:
# Works on Redhat linux and Fedora.. and alot of others. :-)
# ./makeips.pl START_WITH_WHAT#
#
# Where START_WITH_WHAT# is the number of the first interface
# you wish to begin with. So for example, if you have already
# assigned ethernet 0, 0:0 and 0:1 then you will want to add
# interfaces beginning at 0:2 so you would enter 2 there to
# make sure the numbering is correct and your new interfaces
# are created correctly. If you are adding interfaces to
# a system with more than 1 ethernet card, then you must
# specify the card by changing the variable below.
#
# Props: Special thanks to Swami who inspired me to write
# this quick hack. Customers make the world go round.
# My scripts make it happen a bit faster. Thanks.
$interface = $ARGV[0];
$card = "0";
$directory = "/root/test";
#$directory = "/etc/sysconfig/network-scripts";
$iplist = "./iplist.txt";
open(DB,"$iplist");
while(<DB>) {
# Template of the ip configuration file
$template = <<__END_OF_FORMAT__;
DEVICE=eth<<CARD>>:<<INTERFACE>>
ONBOOT=yes
BOOTPROTO=static
IPADDR=<<IPADDRESS>>
NETMASK=255.255.255.0
GATEWAY=<<GATEWAY>>
__END_OF_FORMAT__
$ipaddress = $_;
chomp($ipaddress);
($oct1,$oct2,$oct3) = split(/\./,$ipaddress);
$gateway = "$oct1.$oct2.$oct3.1";
$template =~ s/<<IPADDRESS>>/$ipaddress/g;
$template =~ s/<<INTERFACE>>/$interface/g;
$template =~ s/<<GATEWAY>>/$gateway/g;
$template =~ s/<<CARD>>/$card/g;
open(FILE, ">$directory/ifcfg-eth$card:$interface");
print FILE $template;
close(FILE);
$shell .= "ifup ifcfg-eth$card:$interface\n";
$interface++;
}
print $shell;
print "\n\n\nCopy the above commands and paste into shell to bring the new interfaces up.\n";