Multiple ipaddresses on one device in FreeBSD

How To configure multiple ipaddresses on one ethernet device

FreeBSD (7.x, 8.x)

As it is possible to configure multiple host-/domain names for 1 ipaddress, it is also possible to configure multiple ipaddresses for one ethernet device.

Physical ethernet card configuration

Configuring manually with ethernet card em0

ifconfig em0 inet 89.18.182.10 netmask 255.255.255.0
ifconfig em0 alias 89.18.182.8 netmask 255.255.255.255
ifconfig em0 alias 89.18.182.9 netmask 255.255.255.255

Etc…Note that the netmask of the main ipaddress is different than the others. Your endresult will look somewhat like this:

[umask@umask:~]$ ifconfig
em0: flags=8843 metric 0 mtu 1500
options=19b
ether 00:30:48:d3:b0:7c
inet 89.18.182.10 netmask 0xffffffe0 broadcast 89.18.182.31
inet 89.18.182.8 netmask 0xffffffff broadcast 89.18.182.8
inet 89.18.182.9 netmask 0xffffffff broadcast 89.18.182.9
inet 89.18.182.11 netmask 0xffffffff broadcast 89.18.182.11
inet 89.18.182.12 netmask 0xffffffff broadcast 89.18.182.12
inet 89.18.182.13 netmask 0xffffffff broadcast 89.18.182.13
media: Ethernet autoselect (1000baseTX )
status: active

Now that you have manually configured this you will need to make it permanent in case the server has to reboot. You can do that by placing the following lines in /etc/rc.conf:

ifconfig_em0="inet 89.18.182.10  netmask 255.255.255.224"
ifconfig_em0_alias0="inet 89.18.182.8 netmask 0xffffffff"
ifconfig_em0_alias1="inet 89.18.182.9 netmask 0xffffffff"
ifconfig_em0_alias2="inet 89.18.182.11 netmask 0xffffffff"
ifconfig_em0_alias3="inet 89.18.182.12 netmask 0xffffffff"
ifconfig_em0_alias4="inet 89.18.182.13 netmask 0xffffffff"

And your done. Your ethernet card now has multiple ipaddresses.

How To configure multiple ipaddresses on a virtual ethernet device

In some setups there is need to bond ethernet devices together to obtain greater throughput or redundancy. Such a device is called a lagg device under FreeBSD. In this article is explained how to set up such a device. The configuration is also known as Link Aggregation or Failover devices. In the article it is not described how to set up multiple ipaddresses for such a setup. So, here is how to do it:

Manual configuration:

First set up the lagg device:

[umask@umask] $ ifconfig em0 up
[umask@umask] $ ifconfig em1 up
[umask@umask] $ ifconfig lagg0 create
[umask@umask] $ ifconfig lagg0 up laggproto lacp laggport em0 laggport em1

Then create the ipadresses:

[umask@umask] $ ifconfig lagg0 inet 192.168.1.70 netmask 255.255.255.0
[umask@umask] $ ifconfig lagg0 alias 192.168.1.71 netmask 255.255.255.255
[umask@umask] $ ifconfig lagg0 alias 192.168.1.72 netmask 255.255.255.255

Now put it all in /etc/rc.conf:

ifconfig_em0="up mtu 9000 polling"
ifconfig_em1="up mtu 9000 polling"
cloned_interfaces="lagg0"
ifconfig_lagg0="laggproto lacp laggport em1 laggport em0 up"
ifconfig_lagg1="laggproto lacp laggport em1 laggport em0 up"
ipv4_addrs_lagg0="192.168.1.70/24"
ifconfig_lagg0_alias0="192.168.1.71/24"
ifconfig_lagg0_alias1="192.168.1.72/24"

Now that you have configured your virtual device, and (probably have restarted your network), you should see something like this:

em0: flags=8843 metric 0 mtu 9000
    options=db
    ether 00:1b:21:53:b6:97
    media: Ethernet autoselect (1000baseT )
    status: active
em1: flags=8843 metric 0 mtu 9000
    options=db
    ether 00:1b:21:53:b6:97
    media: Ethernet autoselect (1000baseT )
    status: active
lagg0: flags=8843 metric 0 mtu 9000
    options=db
    ether 00:1b:21:53:b6:97
    inet 192.168.1.71 netmask 0xffffff00 broadcast 192.168.1.255
    inet 192.168.1.72 netmask 0xffffff00 broadcast 192.168.1.255
    inet 192.168.1.70 netmask 0xffffff00 broadcast 192.168.1.255
    media: Ethernet autoselect
    status: active
    laggproto lacp
    laggport: em0 flags=1c
    laggport: em1 flags=1c

And there you are, completely configured and up and running! Enjoy a better connection !

~ Rick

Share
Rick Wezenaar liked this post

About UmasK

Rick is a typical UNIX & Linux geek. He is specialised in hands-on UNIX and Windows system administration, maintenance, scripting, setting up servers, maintaining servers, 3rd line support for UNIX (and Windows), setting up new services and new implementations, migrations. Research and Development, internet (hosting). Rick works as a freelancer / contractor through his own company, Mitranet.
This entry was posted in Commandline, FreeBSD, How-To, Shell, Unix Tips and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

Comments are closed.