Skip to content
daniel@cosenza:~/blog
FreeBSDHow-To October 16, 2025 3 min read

How to Configure Static Networking on FreeBSD from Scratch

A complete walkthrough for assigning a static IP, default route, and DNS resolution on FreeBSD, persisted correctly across reboots.

This walkthrough configures a FreeBSD machine with a static IP address, gateway, and DNS resolution — the standard setup for a server that shouldn’t rely on DHCP.

Step 1: identify your network interface

ifconfig -a

Note the interface name (em0, igb0, vtnet0 depending on your hardware or virtualization platform) — you’ll need it for every step below.

Step 2: decide on your addressing

You’ll need four pieces of information before starting: the static IP address to assign, the subnet mask (or CIDR prefix), the default gateway address, and at least one DNS server. For this walkthrough: IP 192.168.1.50/24, gateway 192.168.1.1, DNS 1.1.1.1 and 9.9.9.9.

Step 3: set the address persistently in rc.conf

# /etc/rc.conf
ifconfig_em0="inet 192.168.1.50/24"
defaultrouter="192.168.1.1"

Editing /etc/rc.conf directly (rather than only running ifconfig interactively) is what makes this survive a reboot — ifconfig alone only affects the currently-running system.

Step 4: configure DNS resolution

# /etc/resolv.conf
nameserver 1.1.1.1
nameserver 9.9.9.9

Step 5: apply the configuration without rebooting

service netif restart
service routing restart

Step 6: verify the address and route took effect

ifconfig em0
netstat -rn

Confirm the interface shows your assigned address, and that netstat -rn lists a default route pointing at your specified gateway.

Step 7: verify actual connectivity

ping -c3 192.168.1.1
ping -c3 1.1.1.1
ping -c3 google.com

Testing in this order — gateway, then a known external IP, then a hostname — isolates where connectivity breaks if something’s wrong: failure at the gateway ping means a local network/cabling issue; success there but failure pinging an external IP means a routing or firewall issue upstream; success with the IP but failure resolving the hostname means DNS specifically is misconfigured.

Step 8: add a secondary static route, if needed

If you need to reach a specific additional subnet through a different gateway (a common requirement in segmented networks), add it as a named static route:

# /etc/rc.conf
static_routes="internal"
route_internal="-net 10.0.0.0/24 192.168.1.254"
service routing restart
netstat -rn | grep 10.0.0.0

Step 9: lock in the configuration with a firewall, if this is a server

If this machine is a server rather than a workstation, pair this static addressing with a pf ruleset (covered in more detail elsewhere on this blog) rather than leaving it unfiltered — a static, predictable address is exactly what makes writing precise firewall rules practical in the first place.

Why rc.conf, not just ifconfig

The distinction that trips up newcomers most often is that ifconfig commands run interactively only affect the live, running system — they’re gone after a reboot unless the same configuration is also present in /etc/rc.conf, which FreeBSD’s netif startup script reads and applies automatically at every boot. Testing with ifconfig interactively first, then committing the working configuration to /etc/rc.conf once confirmed, is the safest order of operations — it avoids locking in a broken configuration that survives a reboot before you’ve verified it actually works.