Thursday, December 23, 2010

Add multiple IP addresses on one NIC network card in FreeBSD

IP aliasing is the process of assigning more than one IP address to a network interface. This is useful for Apache web server virtual hosting or other network servers such as ftp server.

# vi /etc/rc.conf
ifconfig_[card_type]="inet [primary ip address] netmask [your netmask]"
ifconfig_[card_type]_alias0="[secondary ip address] netmask 255.255.255.255"
ifconfig_[card_type]_alias1="[secondary ip address] netmask 255.255.255.255"

Note: the netmask of alias must be 255.255.255.255

Restart FreeBSD network service using network restart script:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

Sample:

hostname="sun.nixcraft.in"
# default vsnl router interface
defaultrouter="202.54.1.200"
# Force 10Mbps for both public and private LAN interace
ifconfig_em0="inet 10.20.110.2 netmask 255.255.255.192 media 10baseT/UTP mediaopt full-duplex"
ifconfig_em1="inet 202.52.1.2 netmask 255.255.255.248 media 10baseT/UTP mediaopt full-duplex"
ifconfig_em0_alias0="inet 10.20.1.226 netmask 255.255.255.255"
ifconfig_em0_alias1="inet 10.20.1.227 netmask 255.255.255.255"
ifconfig_em0_alias2="inet 10.20.1.228 netmask 255.255.255.255"
ifconfig_em0_alias3="inet 10.20.1.229 netmask 255.255.255.255"
ifconfig_em0_alias4="inet 10.20.1.230 netmask 255.255.255.255"
# static routing configuration
static_routes="lan0"
route_lan0="-net 10.0.0.0/8 10.20.110.1"

Reference: http://www.cyberciti.biz/tips/freebsd-how-to-setup-2-ip-address-on-one-nic.html

No comments: