[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: IP-aliasing




On Fri, 26 Jul 1996, Behan Webster wrote:

> I've also written the following simple script for one of the machines
> I manage that is used as a multi-homed web site (it has about 6 ip
> addresses right now.) Just give it a list of ip addresses on the
> command line. It's to be used once at boot time.
>
> >#!/usr/bin/perl
> > [...script deleted...]


> I hope this is helpful.

it's certainly a great idea.  Thanks, I can use something like that in my
wetware collection of useful tricks!


what i will never understand, though, is why people use perl for jobs that
sh is much better suited to.  

perl is great if you want awk/sed/grep/kitchen sink all rolled into one
scripting language. but there's a price - perl's slower and bigger and
takes longer to load.

here's the same thing in sh

---cut here---
#! /bin/sh

device=eth0             # aliased device
netmask=255.255.255.0   # your netmask

interface=0
for i in $@ ; do
    broadcast=`echo $i | sed -e 's/[^.]$/255/'`
    ifconfig $device:$interface $i netmask $netmask broadcast $broadcast
    route add -host $i dev $device:$interface
    interface=$[interface + 1]
done
---cut here---

(NB: this script should work BUT is untested)


actually, i can see problems in this (and in your perl implementation).

The netmask & broadcast address could be wrong in some (not uncommon)
circumstances...it should be possible, however, to make the script
generic by calculating the correct values for netmask and broadcast from
an arg like '203.16.167.50/24'.

it might also be worthwhile calculating the correct network address and
doing 'route add -net $netaddr $device:$interface'...would help when the
machine has ip alias addresses in multiple networks or subnets.

(of course, this extra stuff probably make it worth the overhead of
implementing it in perl :-)


Craig




Reply to: