How to Set Up Static IP on Freebsd

Perhaps some context

As a brand new user of FreeBSD I tried to install it on my laptop, that perhaps was a grave mistake because I managed to crash my system. I cannot fault FreeBSD or it's documentation because they are thorough. I shot my own foot when I ventured out and tried installing it thinking I can wing it. Was I wrong? Absolutely!

I had to eventually resort to familiarity of Ubuntu. I didn't give up on the idea on getting started on FreeBSD therefore this time I followed the documentation and installed it as a host on Virtualbox. When installing I chose the DHCP configuration for my network.

After getting familiar with how to get around the system, still in the first week of exploring I reached a point where I was tired of first finding out what the IP address of my host was which was assigned by my router and then login to it through the shell. Perhaps I reached this point of frustration because I have configured all my systems with Static IP and I know them.

So I started on my journey to setup my FreeBSD host with a static IP. This post is in noway a replacement of FreeBSD Handbook or any other official documentation(I am not aware of any other than the Handbook). It is my attempt at helping a newcomer in setting up a static IP. you could consider this a complimentary document to the Handbook. Though the Handbook is well writted it can be dauting for a newbie to find what he is looking for.

So how do you set up static IP on FreeBSD

The configuration to edit the network lives in a file call /etc/rc.conf

DHCP configuration looks as follows

hostname="name.example.com"
ifconfig_em0="DHCP"

For static IP change the configuration as follows

hostname="name.example.com"
ifconfig_em0="inet 192.168.1.12 netmask 255.255.255.0"
defaultrouter="192.168.1.1"

Here, in both DHCP and Static IP configuration the second line ifconfig_em0 can change according to your device. em0 in my system refers to a networking device. To find out which one is in use in your system run ifconfig and choose the device that is apt for you. Eventually the second line will look like this ifconfig_xyz, here xyz will be replaced by the device you are working with.

Conclusion

Though this post talks about how to setup static IP in FreeBSD in my opinion nothing can replace the FreeBSD Handbook. However like I said earlier it can be a daunting task for a newbie to find the information he or she is looking for. So you can find the static IP configuration information in the Handbook in section 11.5.2. Configuring the Network Card.

Do let me know if this helped you in anyway, it will only encourage me to write more such posts. If you have comments please do reach out to me. I would like to listen and improve.Perhaps some context

Comments (2)

Bolaji Ayodeji's photo

Love this Alwin Doss🤩