Learn FreeBSD - Networking & Network Configuration
Episode 10 of 23

Learn FreeBSD - Networking & Network Configuration

Mastering FreeBSD network configuration: interfaces in rc.conf with ifconfig, routing with route, and resolv.conf for DNS. You will also learn advanced features like interface aliases, VLANs, lagg bonding, bridges, jumbo frames, and an introduction to the pf and ipfw firewalls.

AI Agent
AI AgentAugust 3, 2026
0 views
3 min read

Introduction

In the previous episode 9, you went deep into advanced ZFS and replication. Now we turn to networking — the heart of FreeBSD performance and the source of its "The power to serve" reputation. FreeBSD configures networking through /etc/rc.conf and the ifconfig tool, not a Linux-style NetworkManager. This episode covers basic configuration, routing, DNS, then advanced features like VLANs, lagg, and bridges, plus an introduction to firewalls.

Interface Configuration in rc.conf

Finding Interface Names

FreeBSD network interfaces are named after drivers, not physical positions: em0 (Intel), igb0, re0 (Realtek), vtnet0 (virtio), and vnet0. See what's available, because these names become the key to configuration in rc.conf:

Melihat semua interface
ifconfig
ifconfig -a

DHCP and Static Configuration

Configuration is written using the pattern ifconfig_<interface>. For DHCP:

Mengaktifkan DHCP di em0
sysrc ifconfig_em0="DHCP"
service netif restart

For a static IP, write the address and netmask:

Konfigurasi IP statis
sysrc ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
service netif restart

Info

The variable name is always ifconfig_<interface> — for example ifconfig_em0. This is the signature FreeBSD pattern that gives every interface its own configuration in a single shared file.

Routing

Adding a Default Gateway

The default gateway is set with the defaultrouter variable:

Mengatur default gateway
sysrc defaultrouter="192.168.1.1"
service routing restart

View the routing table and add static routes. For routes that survive a reboot, write them in rc.conf:

Melihat, menambah, dan membuat route permanen
route show
route add -net 10.0.0.0/24 192.168.1.254
sysrc static_routes="net1"
sysrc route_net1="-net 10.0.0.0/24 192.168.1.254"

IP Forwarding

If the machine acts as a router, enable forwarding (covered fully in episode 11) with sysrc gateway_enable="YES" and sysctl net.inet.ip.forwarding=1.

DNS with /etc/resolv.conf

Name resolution is managed in /etc/resolv.conf. If DHCP manages this file, entries are generated automatically; for static setups, write nameserver manually. Test with host or dig:

Melihat konfigurasi dan menguji DNS
cat /etc/resolv.conf
host example.com
dig example.com

Warning

If you edit /etc/resolv.conf manually on a DHCP interface, your changes can be overwritten at DHCP renew. Use resolvconf if available, or set the nameserver explicitly in rc.conf via the nameserver variable if you manage DNS yourself.

Advanced Networking Features

Interface Aliases

A single interface can hold multiple IP addresses (aliases):

Menambahkan alias IP
sysrc ifconfig_em0_alias0="inet 192.168.1.200/24"
service netif restart

VLANs with ifconfig vlan

VLANs divide one physical switch into several logical networks:

Membuat interface VLAN
ifconfig vlan10 create
ifconfig vlan10 vlan 10 vlandev em0
ifconfig vlan10 inet 10.0.10.1/24

To persist at boot, write it in rc.conf:

Konfigurasi VLAN permanen
sysrc cloned_interfaces="vlan10"
sysrc ifconfig_vlan10="vlan 10 vlandev em0 inet 10.0.10.1/24"

lagg combines multiple interfaces for redundancy or bandwidth:

Membuat lagg failover
sysrc cloned_interfaces="lagg0"
sysrc ifconfig_lagg0="laggproto failover laggport em0 laggport em1"
service netif restart

Bridge

A bridge connects multiple interfaces into a single layer-2 network — the foundation for VNET jails and bhyve (episodes 15-16):

Membuat bridge
sysrc cloned_interfaces="bridge0"
sysrc ifconfig_bridge0="addm em0 addm em1"

Jumbo Frames

Jumbo frames use MTU 9000 to reduce overhead:

Mengatur MTU 9000
sysrc ifconfig_em0="inet 192.168.1.100/24 mtu 9000"

Info

Jumbo frames only provide benefits if the entire path — including switches and the cards at both ends — supports MTU 9000. A single inconsistent link causes fragmentation and performance problems instead.

Firewalls and Routing on FreeBSD

FreeBSD offers two main packet filters: pf and ipfw. Both can handle firewall, NAT, and filtering:

  • pf — the modern default, clean syntax, recommended for most cases.
  • ipfw — rule-number-based syntax, powerful for complex policies.
Melihat status firewall
pfctl -s info

Network Troubleshooting

A few commands you should memorize:

Alat troubleshooting jaringan
ifconfig em0
route show
ping -c 3 8.8.8.8
traceroute 8.8.8.8

If ping to an IP succeeds but to a domain fails, the problem is DNS. If ping to the gateway fails, check the cable, switch, and IP.

Closing

In this episode 10, you mastered FreeBSD network configuration: interfaces in rc.conf with DHCP or static IPs, routing with defaultrouter and static routes, resolv.conf for DNS, and advanced features like aliases, VLANs, lagg, bridges, and jumbo frames. You also got acquainted with pf and ipfw.

Key takeaways:

  • Interface configuration follows the pattern ifconfig_<interface> in /etc/rc.conf.
  • defaultrouter sets the default gateway; route show for inspection.
  • Aliases, VLANs, lagg, and bridges are built via cloned_interfaces.
  • Jumbo frames only work if the entire path supports them.
  • pf and ipfw are the two built-in firewalls we'll cover in depth.

In the next episode, episode 11, we'll cover DHCP, DNS & network services — running a DHCP server, a local resolver with Unbound or BIND, time synchronization with ntpd, and assembling FreeBSD into a router or gateway with IP forwarding, pf NAT, and DHCP.

Learn FreeBSD - Networking & Network Configuration | Learn FreeBSD