Adding IP aliases in FreeBSD

One question I hear quite often is "how do I add IP aliases in FreeBSD?" It's not terribly intuitive, but you can follow these steps:

Example:
Server's primary IP: 192.168.1.5
Additional IP's to add: 192.168.1.10, 192.168.1.15, and 192.168.1.20

Boot-time configuration:
Add it to /etc/rc.conf first (so you don't forget). In this example, we have a Realtek card called rl0:
ifconfig_rl0="inet 192.168.1.5 netmask 255.255.255.0"
ifconfig_rl0_alias0="inet 192.168.1.10 netmask 255.255.255.0"
ifconfig_rl0_alias1="inet 192.168.1.15 netmask 255.255.255.0"
ifconfig_rl0_alias2="inet 192.168.1.20 netmask 255.255.255.0"

UBER-IMPORTANT NOTE: Start with the number 0 (zero) any time that you make IP alias configurations in /etc/rc.conf.
This is BAD form:

ifconfig_rl0="inet 192.168.1.5 netmask 255.255.255.0"
ifconfig_rl0_alias1="inet 192.168.1.10 netmask 255.255.255.0"
ifconfig_rl0_alias2="inet 192.168.1.15 netmask 255.255.255.0"
ifconfig_rl0_alias3="inet 192.168.1.20 netmask 255.255.255.0"

If you do it the wrong way (which means starting alias with anything but alias0), only the primary comes up. Keep that in mind.

Bringing up the new IP's:
You can do things the extraordinarily dangerous way:
# /etc/rc.network restart

Or, you can follow the recommended steps:
# ifconfig rl0 alias 192.168.1.10 netmask 255.255.255.0
# ifconfig rl0 alias 192.168.1.15 netmask 255.255.255.0
# ifconfig rl0 alias 192.168.1.20 netmask 255.255.255.0

Test your work:
Any good system administrator knows to test things once their configured. Make sure to ping your new IP's from a source on your network and outside your network (if possible/applicable).

Printed from: http://rackerhacker.com/2007/08/08/adding-ip-aliases-in-freebsd/ .
© Major Hayden 2012.

2 Comments   »

  • hhash says:

    Just FYI:

    http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/configtuning-virtual-hosts.html

    says to make sure that any alias addresses that are in the same subnet as an already set IP must have a netmask of 255.255.255.255

    Things will work without doing this (and doing as you have done above), and I'm not yet sure why this is the case.

  • Bakhtiyor Mazgarov says:

    How about adding alias to a vlan?
    Does this work?

    cloned_interfaces="vlan1010 vlan1020"
    ifconfig_vlan1010="inet 1.1.1.2 netmask 255.255.255.252 vlan 1010 vlandev de1 name Test-Vlan1010"
    ifconfig_vlan1020="inet 2.2.2.2 netmask 255.255.255.252 vlan 1020 vlandev de1 name Test-Vlan1020"
    ifconfig_vlan1020_alias0="inet 3.3.3.2 netmask 255.255.255.252"

    It does not work in my case.

    And if you know, will you tell me how to restart rc.conf script without rebooting and remotely.

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this