FreeBSD lets us easily override names for network interfaces with names that give us more context during sysadmin tasks.
In FreeBSD, we can configure most of the operating system using one file:
/etc/rc.conf. The OS also comes with a handy utility program that makes it a breeze to edit the configuration file straight from the command line:
We will use the knowledge to make this:
[root@freebsd12 ~]# ifconfig vtnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500 ...
look like this:
[root@freebsd12 ~]# ifconfig public: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500 ...
First, let's have a look at the entire
/etc/rc.conf on a freshly installed FreeBSD 12.2 virtual machine.
clear_tmp_enable="YES" syslogd_flags="-ss" sendmail_enable="NONE" hostname="freebsd12" ifconfig_vtnet0="DHCP" sshd_enable="YES" # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable dumpdev="NO"
I prefer to bring some order into this file, even though it isn't required and does not affect the functioning at all.
# System clear_tmp_enable="YES" dumpdev="NO" hostname="freebsd12" # Services syslogd_flags="-ss" sendmail_enable="NONE" sshd_enable="YES" # Network ifconfig_vtnet0="DHCP"
There! We can glance through the logical blocks of configuration and quickly arrive at the setting we care about:
The network interface available inside Bhyve Hypervisor is called
vtnet. We can run
man vtnet to explore, such as the name is short for "VirtIO Ethernet" and much more.
We have one instance of the virtual ethernet port available to this virtual machine, hence the
0, as counting starts from zero.
You may see
igb1 and other incarnations based on which driver is used to run the network interface card (NIC) an how many ethernet ports are available through one or more cards with the same driver.
If you manage more than one machine, and if they have different NICs, it can become tricky to remember every name. Sharing configuration for firewall, utility scripts etc. becomes riddled with gotchas. Unless you go all the way and fully automate configuration management and never log into the shell to manage anything by hand.
I prefer to automate as much as possible while keeping the system in a state that can be debugged by a human. Therefore, even in my salt-stack managed configuration, I set up names that convey more meaning to the operator than just the driver and port number.
Take for example this server that's delivering you the blog, it has one interface that connects it to the public Internet (
em0) and one software bridge that's isolated and used for services running in jails and virtual machines (
bridge0). The hosts on the bridge get private IP addresses and are selectively allowed to access the Internet through Network Address Translation (NAT).
The obvious names for these two interfaces are:
Similarly, we can name the
vtnet0 on our VM to
public, assuming it is connected to the Internet and has a public IP adddress.
We can edit this in place by opening the file in a text editor, or we can query and edit it from the command line. Let's try the latter.
sysrc with the name of the configuration setting outputs the associated value.
But we haven't named the interface yet. It's still
To do that, the format for the configuration is:
The response from the command tells us that the previous value was empty and that it is now set to "public".
This is the first step. Next we remove the interface configuration with old name. To remove a configuration, we pass the
-x option along with configuration name to
Here no output indicates that the operation was successful.
Finally, let us configure the newly named interface:
Here is the
/etc/rc.conf once again, with updates:
# System clear_tmp_enable="YES" dumpdev="NO" hostname="freebsd12" # Services syslogd_flags="-ss" sendmail_enable="NONE" sshd_enable="YES" # Network ifconfig_vtnet0_name="public" ifconfig_public="DHCP"
And done! At this point we can reboot the VM and it'll come up with the interface named
public instead of
Or, we can simply restart the network interfaces service and skip the reboot entirely.
[root@freebsd12 ~]# service netif restart Stopping Network: lo0 vtnet0. ... Starting Network: lo0 public. ... public: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500 ...
Now we can access the interface everywhere in the system as
Do this across all FreeBSD machines and muscle memory builds up over time as we know the name of the public/private/vpn interfaces and don't have to think or look up this information every time.