Tag Archives: freebsd add aliases

FreeBSd: Add IP aliases and Stop/Start/Restart networking and routing

Working on a Freebsd server can be difficult if you have no idea that it is not the same as a Linux server even if the architecture type of Freebsd is unix-like but yeah in the end is BSD.

Things are being done a bit differently on a Freebsd server when it comes to networking and routing.

For the start all the IPs are being setup in a file called /etc/rc.conf and also the IP aliases will be set in this file also.

Checking the rc.conf file you will see the line containing the IP as it is really obvious and will look like:

ifconfig_rl0="inet 192.168.0.2 netmask 255.255.255.0"

The IP, netmask and also the name of the interface(in our case rl0) can be different.

In order to add some more IPs to the same interface we will have to edit the rc.conf file and add the following under the already existing "ifconfig_rl0=" line:

ifconfig_rl0_alias0="inet 192.168.0.3 netmask 255.255.255.0"
ifconfig_rl0_alias1="inet 192.168.0.4 netmask 255.255.255.0"
ifconfig_rl0_alias2="inet 192.168.0.5 netmask 255.255.255.0"

Important Note:Start with alias0 and not with alias1 or other numbers in the alias line

Doing all this we ended up setting the three aliases(192.168.0.3,192.168.0.4,192.168.0.5) to the rl0 interface and the only thing left now to do is to restart the networking and routing if needed.

General commands on starting/stopping/restarting networking and routing in FreeBSD:

To start FreeBSD network service:
# /etc/rc.d/netif start

To stop FreeBSD network service:
# /etc/rc.d/netif stop

To restart FreeBSD network service:
# /etc/rc.d/netif restart

It is also necessary to update the routing table after restating networking service:
# /etc/rc.d/routing restart

If you have done all this modifications using a remote connection(ssh) you may want to use the following command to restart networking and routing at once:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

This should have covered the general networking part for Freebsd.

Share/Bookmark