Setting up network alias in BSD (openBSD / freeBSD)

FreeBSD

  1. Find the Interface
  2. Set a Temporary IP Alias
  3. Set a Permanent IP Alias
  4. Remove an IP Alias

OpenBSD

  1. Find the Interface
  2. Set an IP Alias
  3. Make the IP Alias Permanent
  4. Remove an IP Alias

FreeBSD

Find the Interface

If you want to put an IP alias on an interface under FreeBSD, first find the interface:

In our case the interface is called em0. We will use this name in all the examples. Replace it with the interface name you find on your system!

Set a Temporary IP Alias

Then set the alias with ifconfig

This sets an IP address 192.168.100.200 to em0. Check again with ifconfig:

Now we see two IP addresses on em0. If you want to set an IP address within the same network you would have to set a fake netmask of 255.255.255.255.

Set a Permanent IP Alias

The above alias will be lost after the next reboot. If you need a permanent alias, add the following line to /etc/rc.conf:

and restart the network:

Remove an IP Alias

To remove the alias (until next reboot, if you made it permanent), just remove the IP address from the interface you put on it earlier:

 


OpenBSD

Setting an IP alias to an interface with OpenBSD is straight forward:

Find the Interface

First find the interface you want to put an IP alias with ifconfig:

From the above output you see that your current IP address is put on vr0. We will use this name in all the examples. Replace it with the interface name you find on your system!

Set an IP Alias

To put a second IP address to the same interface, just enter on the commandline as root:

This sets an IP address 192.168.100.199 to vr0. Check again with ifconfig:

Now we see two IP addresses on vr0. If you want to set an IP address within the same network you would have to set a fake netmask of 255.255.255.255.

Make the IP Alias Permanent

If you use ifconfig to set an IP alias, the alias won’t be present after the next reboot. To make the setting permanent, add a line to /etc/hostname.<INTERFACE>:

Remove an IP Alias

You can remove an IP alias with a comand like this:

This deletes the second IP address from the interface keeping the first.

 

Source: UnixWerk

 

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.

This tutorial explains how to assign one or more IP address to a single network interface under FreeBSD operating system.

It is possible to create network alias or assign 2 ip address to a single NIC under FreeBSD operating system.

Our Sample Setup

  • Interface name: lnc0 – IP : 192.168.1.1/255.255.255.0
  • Interface name: lnc0 alias – IP : 192.168.1.5/255.255.255.255

Netmask must be different otherwise you will get an error ifconfig: ioctl (SIOCAIFADDR): File exists.

Set ip alias using ifconfig command line utility

Login as the root user.

Now, use ifconfig command as follows to set alias:

Persistent IP Alias Configuration

Edit file /etc/rc.conf to setup persistent ip aliasing option by appending following configuration, so that next time FreeBSD comes up (after restart/shutdown) it will create alias for you:

Finally, Restart FreeBSD network service using network restart script:

Display alias and real ip using ifconfig lnc0 command:

Sample output:

Sample /etc/rc.conf file with IP aliasing

Here is my /etc/rc.conf file with em0 and em1 interface with 5 aliases:

Further readings:

  • Read ifconfig man page.


Comments

comments

Leave a Reply