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

Re: Please help with IP Aliasing

On 1 Jul 1998, Andy Spiegl wrote:

> I am currently setting up a Mail and Webserver (hamm, 2.0.33).  I have got
> a whole package of 256 IP addresses that I want to assign to this
> server.  In the NET-3-HOWTO I read that I have to set it up like this:

> # here I am trying to set up the IP-Aliasing for the whole
> # subnetwork XXX.231.206.x
> ifconfig eth0:1 XXX.231.206.1 netmask up
> route add -net XXX.231.206.0 netmask eth0:1
> # [...]
> # and so on, until:
> ifconfig eth0:254 XXX.231.206.254 netmask up
> route add -net XXX.231.206.254 netmask eth0:254

firstly, replace all those ifconfig & route commands with something like

while [ $i -le 254 ] ; do
	ifconfig eth0:$i XXX.231.206.$i netmask
	route add -host XXX.231.206.$i eth0:$i
	$i=$(( $i + 1 ))

secondly, the route command is optional.  and if you do use it, you should
use a host route, rather than a network route.

third: do you *really* need all those aliases configured right now? if
not, then only configure the ones you actually need, *when* you need

fourth: for a virtual hosting system, it's not terribly difficult to
set things up so that the configurations for virtual web, ftp, mail,
dns, and ip_aliasing are all controlled from one file. e.g. make a file
called /etc/virtual-hosts which contains the following info:

#IP-address		domain name		username
XXX.231.206.1	foo.com.au		foo
XXX.231.206.2	bar.com.au		bar

modify /etc/init.d/networks to use field 1 (cut or awk or perl can
extract the info for you - e.g. awk '{print $1}' prints field 1) for
configuring the ip aliases. write the script so that it ignores blank
lines and comments ('grep -v "^$\|^#"' is a good start).

for j in $( grep -v "^$\|^#" /etc/virtual-hosts | awk '{print $1}' ) ; do
	ifconfig eth0:$i $j netmask
	route add -host $j eth0:$i
	$i=$(( $i + 1 ))

then write scripts which generate config files for apache and proftpd
using all three fields (username being used to derive the public_html
and anon ftp dirs for the virtual host...subdirectories of ~username).

how you handle virtual mail depends on which mailer you use....if
you use sendmail, then adding a line like "@domain username" to
/etc/virtusertable and then running "makemap hash virtusertable
</etc/virtusertable" will do the job.

zone files for bind can be auto-generated too, using the first two
fields...most virtual hosts will be identical except for IP address and
domain name. write this so that it only generates a zone file if one
doesn't already exist.

finally, write a Makefile to tie it all together...so adding a new
virtual host is as simple as editing /etc/virtual-hosts and typing make.

you *can* do all this in sh/awk/sed/cut but doing it in perl will be
much easier, especially where you need to use more than one field from
/etc/virtual-hosts at a time. doing that in perl is trivial. in sh it is

BTW, you can add as many extra field to /etc/virtusertable as you
need...e.g. you could add a "type" field which defines whether a
particular virtual host is mail, web, ftp, or all three.

> What I want seems to work this way, but I can't imagine that this is
> the right way to do it.  And if I will ever get another subnetwork to
> add, how would I add it using the above method?  I found that eth0:255
> is the highest possible virtual network number.  So I couldn't add any
> more?
> All you network-gurus: Please give me a hint or any pointer as to
> where I can find more info on that.

you can increase this limit by modifying the kernel sources. or start
using 2.1 series kernels.

alternatively, stick another ethernet card in the machine and start using
eth1:0 - eth1:255 aliases.....the limit is per interface.

if you've got more than 255 virtual hosts then you probably want another
machine to host them on anyway. don't try to make one machine do too


craig sanders

Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null

Reply to: