FreeBSD

Configure Hostname and Static IP Address on FreeBSD 15 / 14

FreeBSD identifies network interfaces by driver name followed by a number (vtnet0 for VirtIO, em0 for Intel, igb0 for Intel Gigabit). Hostname and network configuration live in /etc/rc.conf, and the cleanest way to manage them is through sysrc rather than editing the file by hand.

Original content from computingforgeeks.com - post 5236

This guide covers setting a hostname, configuring a static IPv4 address, setting DNS resolvers, and updating the hosts file on FreeBSD 15 / 14. Every command was tested on FreeBSD 15.0-RELEASE. For a full FreeBSD installation walkthrough, see our FreeBSD 15 installation guide.

Check Your Current Network Configuration

Before changing anything, check the current hostname and network interface:

hostname
ifconfig vtnet0

The output shows the interface name, MAC address, assigned IP, and link status:

vtnet0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
        options=ec07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS>
        ether bc:24:11:fa:e6:a8
        inet 192.168.1.123 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::be24:11ff:fefa:e6a8%vtnet0 prefixlen 64 scopeid 0x1
        media: Ethernet autoselect (10Gbase-T <full-duplex>)
        status: active

If you are unsure of your interface name, run ifconfig -a to list all interfaces.

Set the Hostname on FreeBSD

Set the hostname immediately and persist it across reboots with sysrc:

hostname freebsd-server.example.com
sysrc hostname=freebsd-server.example.com

The sysrc command safely updates /etc/rc.conf and shows the old and new values:

hostname: freebsd15  -> freebsd-server.example.com

Verify the change took effect:

hostname

This returns freebsd-server.example.com. If your server gets its hostname via DHCP, leave the hostname variable empty in rc.conf and the DHCP lease will set it automatically.

Configure a Static IP Address

To assign a static IP address to the vtnet0 interface, set the IP, netmask, and default gateway:

sysrc ifconfig_vtnet0="inet 192.168.1.123 netmask 255.255.255.0"
sysrc defaultrouter="192.168.1.1"

The output confirms the change:

ifconfig_vtnet0: DHCP -> inet 192.168.1.123 netmask 255.255.255.0
defaultrouter: NO -> 192.168.1.1

Replace vtnet0 with your actual interface name (em0, igb0, etc.) and use your own IP, netmask, and gateway values.

Apply the new configuration without rebooting:

service netif restart && service routing restart

If you are connected via SSH, this will drop your session. Reconnect using the new IP address.

Using CIDR Notation

FreeBSD also accepts CIDR notation instead of a full netmask:

sysrc ifconfig_vtnet0="inet 192.168.1.123/24"

Switch Back to DHCP

To revert to DHCP at any point:

sysrc ifconfig_vtnet0="DHCP"
sysrc -x defaultrouter
service netif restart

The sysrc -x flag removes the variable from rc.conf entirely.

Configure DNS Resolvers

Set DNS servers in /etc/resolv.conf:

vi /etc/resolv.conf

Add your preferred DNS servers:

nameserver 8.8.8.8
nameserver 8.8.4.4

If DHCP overwrites this file on renewal, prevent it by adding supersede domain-name-servers 8.8.8.8, 8.8.4.4; to /etc/dhclient.conf. With a static IP, DHCP is not running so /etc/resolv.conf stays as you set it.

Update the Hosts File

Add your server’s IP and FQDN to /etc/hosts for local name resolution:

vi /etc/hosts

Add a line mapping your static IP to the hostname:

::1             localhost localhost.my.domain
127.0.0.1       localhost localhost.my.domain
192.168.1.123   freebsd-server.example.com freebsd-server

Verify the hosts file resolves correctly:

getent hosts freebsd-server.example.com

This should return:

192.168.1.123     freebsd-server.example.com  freebsd-server

Configure IPv6

FreeBSD accepts IPv6 router advertisements by default. Check the current IPv6 setting:

sysrc ifconfig_vtnet0_ipv6

The default is:

ifconfig_vtnet0_ipv6: inet6 accept_rtadv

To assign a static IPv6 address instead:

sysrc ifconfig_vtnet0_ipv6="inet6 2001:db8::10 prefixlen 64"
sysrc ipv6_defaultrouter="2001:db8::1"

To disable IPv6 on an interface entirely:

sysrc ifconfig_vtnet0_ipv6="inet6 -ifdisabled"
sysrc -x ipv6_defaultrouter

Verify the Full Configuration

Review all network-related settings in rc.conf at once:

sysrc -a

On a properly configured server, you should see something like:

defaultrouter: 192.168.1.1
hostname: freebsd-server.example.com
ifconfig_vtnet0: inet 192.168.1.123 netmask 255.255.255.0
ifconfig_vtnet0_ipv6: inet6 accept_rtadv
sshd_enable: YES
zfs_enable: YES

For a complete reference on FreeBSD package and service management, including pkg commands and service usage, check our dedicated guide.

Conclusion

Hostname and static IP configuration on FreeBSD comes down to sysrc and /etc/rc.conf. Use sysrc for any rc.conf change instead of editing the file directly because it validates the syntax and shows you what changed. After modifying network settings, run service netif restart && service routing restart to apply without a full reboot. For additional FreeBSD setup steps, see our guide on installing MariaDB on FreeBSD.

Related Articles

FreeBSD Manage Packages and Services in FreeBSD / OpenBSD / NetBSD Desktop TrueOS – Best FreeBSD Distribution for Desktop Users FreeBSD How To Import FreeBSD 14 Qcow2 Image on Proxmox FreeBSD Install and Configure XigmaNAS NAS (Network-Attached Storage) Solution

Leave a Comment

Press ESC to close