FreeBSD Routing and Gateways Explained

Jul 19, 2023 • FreeBSDSoftware

In the world of FreeBSD, managing network traffic through routing and gateways is an important aspect of system administration. This blog explores the complex terrain of FreeBSD routing and gateways, providing a detailed walk-through of what they are, how they function, and the best practices for setting them up.

What are Routing and Gateways?

Fundamentally, routing is the process of selecting paths in a network along which to send network traffic. A gateway, on the other hand, is a node on a network that serves as an access point to another network. In FreeBSD, the routing and gateway configuration plays a significant role in the effective management of network traffic.

Setting up Network Gateways in FreeBSD

Setting up a gateway on FreeBSD starts with configuring the network interfaces. Check out our guide on configuring network interfaces if you are a beginner. Here is a high-level overview:

  1. First, identify your network interfaces by using the ifconfig command.

  2. Modify the /etc/rc.conf file to include your network interfaces, IP addresses and default gateway. Add the following lines:

     ifconfig_em0="inet netmask 0xffffff00"

    Replace em0 with your network interface name, and with your chosen static IP address. Replace with your default gateway.

  3. Reboot your system to enable the changes.

Understanding and Configuring Routing Tables

The routing table is the decision maker for the network packets’ direction. It consists of routes, with each route providing information for a subnet, destination IP, gateway, among other critical data. To view the routing table in FreeBSD, use netstat -r.

FreeBSD allows static and dynamic routing. Static routing involves manual configuration of the routing table, recommended for smaller networks. Dynamic routing, which is automated routing adjustment based on network traffic, is ideal for larger, complex networks.

For beginners, explore understanding basic commands in FreeBSD for a deeper insight.

Configuring Static Routes

Adding static routes in FreeBSD involves editing the /etc/rc.conf file:


Replace net1 with a unique identifier and with your network’s address. Replace with the next-hop router’s IP address.

Dynamic Routing

FreeBSD supports several dynamic routing protocols, such as RIP and OSPF. Installation of a routing daemon, like Quagga, is necessary for dynamic routing.

Advanced Routing Features

Talk of advanced features, FreeBSD’s PF (Packet Filter) firewall system offers gateway capabilities with advanced features like packet forwarding and network address translation (NAT). To learn how to implement firewalls and security on FreeBSD, visit this page.

Further, FreeBSD supports features like Gateway Groups for failover routing and policy-based routing which supplements the capabilities of the traditional FreeBSD routing table. For managing high availability and failover in FreeBSD, refer to this guide.


Routing and gateways lie at the heart of network traffic management in FreeBSD. While this guide introduces these concepts and provides a basic setup procedure, customization and optimization of your FreeBSD routing and gateways necessitate a good understanding of your network environment’s specifics. Feel sure to check out our other resources on FreeBSD topics, from system administration to kernel optimization and beyond.

Remember, practical knowledge over bookish knowledge always peeps out the best results. Happy FreeBSD routing and gateway management!

Checkout these related ports: