Configuring Network on FreeBSD

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

In this short article, I am going to cover how to configure a network interface on FreeBSD.

Introduction

One thing I love about FreeBSD is the feeling of completeness I get when using it. On FreeBSD, the kernel and the core utilities that come installed as base are all maintained by the FreeBSD team. Consequently, if the kernel requires or deprecates certain features, then the base utilities can adjust accordingly. For this reason, the sysadmins don’t have to worry about any compatibility issues.

On Linux, it was almost a standard to use ifconfig for managing network interfaces. Nevertheless, development of the Linux kernel continued. And, ifconfig couldn’t provide enough features and flexibility. Predictably, this made a new utility called ip to replace the old ifconfig command. Now, the system admins have to learn yet another tool (as if we hadn’t learned enough).

On the other hand, there has been ifconfig and always ifconfig on FreeBSD.

So, the agenda of this article is to quickly go over the ifconfig command. We’ll use it to configure a network interface assigned to my FreeBSD VM.

Assigning an IP

Firstly, we can view the network interfaces by simply running ifconfig.

Viewing network interfaces

As highlighted above, we wish to configure the vtnet1 interface. I attached this to the VM after the FreeBSD installer completed. As a result, the installer didn’t configure it automatically.

Let’s give vtnet1 some life by assigning it an IP. The general syntax is (# denotes root):

# ifconfig <interface-name> <IP> <netmask>


# ifconfig vtnet1 192.168.1.6/24

As you might have noticed, we can use the CIDR notation as well.

Assigning an IP

It’s important to realize that, this will not persist across reboots. In order to do so, we have to tell the FreeBSD init system about it.
Let’s add an entry to /etc/rc.conf telling the system to configure that network at boot:

ifconfig_vtnet1="inet 192.168.1.6/24"
or,
ifconfig_vtnet1="DHCP"

Setting Aliases

Let’s consider that I decide to remove the interface. However, I still want FreeBSD to respond to the two IPs I was using before . It has to do this while only having one interface, namely vtnet0. This is where I will have to use aliases. Fortunately, this couldn’t be any easier.

# ifconfig vtnet0 alias 192.168.1.6/24

Note that, if the aliased IP needs to communicate in another network, then we can set the netmask accordingly. Nonetheless, I am just going to use that IP in the same network hence the same netmask.

Setting aliases

Once again, we need this to persist across reboots. Therefore, I add the following to /etc/rc.conf:

ifconfig_vtnet0_alias0="inet 192.168.1.6/24"

I have rebooted the machine and now I can ssh into it using two different IPs.

SSH using different IPs

Conclusion

Although I haven’t covered much, this should hopefully make you familiar with configuring your network interfaces on FreeBSD.
As always, the best place to look for would be the ifconfig(8) manual page. Additionally, the FreeBSD Handbook is also a great resource.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Pratik Devkota
Pratik Devkota
Software engineering student interested in UNIX (GNU/Linux, *BSD, etc.), security as well as free and open-source software.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook