Multiple ip addresses with Ip aliasing on FreeBSD
One feature I really like is Ip aliasing, which makes it possible to assign a bunch of ip addresses to the same network interface. This comes in quite handy once you want to have separated ip addresses for virtual hosts on an Apache server or simply separated ip addresses for services you offer in your network. This feature is supported on both FreeBSD and Linux. In this article I would like to describe how this feature works on FreeBSD, a description for Linux will follow soon.
Aliases can be specified by two ways:
1. at runtime
ifconfig rl0 inet 192.168.5.23 netmask 255.255.255.255 alias up
This would use the first Realtek card with the specified ip address and bring the alias up immediately. Note, that 255.255.255.255 is intentionally chosen to avoid conflicts with the base ip address. If the address is no longer needed you would simply replace “up” with “down”:
ifconfig rl0 inet 192.168.5.23 netmask 255.255.255.255 alias down
While typing this on the console at runtime is suitable for testing purposes or as temporary measure (in case of an outage of the machine normally using the alias address), we’d certainly prefer to bring our aliases up…
2. on bootup
In this case /etc/rc.conf would be the location to add these aliases. Note, that there’s a pitfall, as the alias syntax is different from adding normal interfaces to.
ifconfig_rl0_alias0="inet 192.168.5.23 netmask 255.255.255.255"
The first alias gets number zero. So for each additional alias you’d like to have you needed to increment this value accordingly:
(still file /etc/rc.conf)
ifconfig_rl0_alias0="inet 192.168.5.23 netmask 255.255.255.255" ifconfig_rl0_alias1="inet 192.168.7.24 netmask 255.255.255.255"
A second note: Before adding aliases you must already have assigned a base address to this interface with a reasonable subnet mask:
ifconfig_rl0="inet 192.168.7.1 netmask 255.255.255.0"
When I set up a new box I usually group base addresses and aliases separated to avoid naming conflicts. Also note, that unlike Linux FreeBSD has a different naming convention: interface names are derived from the driver, therefore 3com or Intel cards have different names. Here’s an Intel card as example:
ifconfig_fxp0="inet 192.168.5.23 netmask 255.255.255.255"
If things went well, you should see the aliases after a reboot:
tabidachi# ifconfig rl0
rl0: flags=8843<up ,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=8<vlan_mtu>
inet6 fe80::200:e8ff:fe85:dbb0%rl0 prefixlen 64 scopeid 0x2
inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
inet 192.168.0.2 netmask 0xffffffff broadcast 192.168.0.2
inet 192.168.0.3 netmask 0xffffffff broadcast 192.168.0.3
inet 192.168.0.4 netmask 0xffffffff broadcast 192.168.0.4
inet 192.168.0.5 netmask 0xffffffff broadcast 192.168.0.5
inet 192.168.0.6 netmask 0xffffffff broadcast 192.168.0.6
inet 192.168.0.7 netmask 0xffffffff broadcast 192.168.0.7
inet 192.168.0.8 netmask 0xffffffff broadcast 192.168.0.8
inet 192.168.0.9 netmask 0xffffffff broadcast 192.168.0.9
inet 192.168.0.10 netmask 0xffffffff broadcast 192.168.0.10
ether 00:00:e8:85:db:b0
media: Ethernet autoselect (100baseTX <full -duplex>)
status: active
These addresses can now be used for any service or virtual host (Apache) running on that machine.
No Comments »
No comments yet.
Leave a comment
Posting comments requires Javascript to be turned on.