Wednesday, May 7, 2008

Multiple IP addresses on FreeBSD on the same NIC

Sometimes you need more than one address aliased to a network interface on a server. for instance if you want to use ssl pages in apache
each ssl certificate should have its own IP address and each VirtualHost that runs on port 443 should have a unique IP address.
You can get around thins by changing the port from 443 to something like

VirtualHost:4430

vhost info

VirtualHost:4431

vhost info

VirtualHost:4432

But you are not using default ports and it might be a problem out in the real world sure you could do the above in side your own network

Anyway thats not what this is about this is to Alias other IP's to your NIC on your FreeBSD server





all you have to do is edit the /etc/rc.conf file
defaultrouter="10.10.10.1"
hostname="mysrv.mydom.com"
ifconfig_em0="inet 10.10.10.4 media 100baseTX mediaopt full-duplex netmask 255.255.255.0"
ifconfig_em0_alias0="10.10.10.7 netmask 0xffffffff"
ifconfig_em0_alias1="10.10.10.8 netmask 0xffffffff"
ifconfig_em0_alias2="10.10.10.9 netmask 0xffffffff"
ifconfig_em0_alias3="10.10.10.10 netmask 0xffffffff"

Thats it.
The Netmask of 0xffffffff is fine you can use it as per the example

Now all you have to do is run /etc/netstart
and all the IP's and the server will respond.

This way you can also get your web server to Listen on one IP and if you have other services running like Mail and FTP they can all have their own IP address.

No comments:

Joe's Store