OpenBSD: Static Routing Configuration

I know how to setup static routing under Linux and FreeBSD operating systems. But, how do you setup static routing under OpenBSD operating systems? OpenBSD uses various text files in /etc for setting up hostname, ip address, default route and static routing.

route Command

The route command is used used to manually view and manipulate the network routing tables.

OpenBSD Persistence Static Routing

The drawback of route command is that, when OpenBSD reboots it will forget your static routes. So store them in configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator. You need to edit your interface configuration file. If your interface name is em0, than config file name is /etc/hostname.em0. Edit /etc/hostname.em0, enter:# vi /etc/hostname.em0 Append static routes as follows:

!route add -net 192.168.1.0/24 192.168.1.254

Save and close the file. You can additional routes also (make sure each route is added on a new line as follows):

A Note About Default Route (Default Gateway)

The default gateway is defined in the file called /etc/mygate. This will allow for your gateway to be set upon boot. This file consists of one line, with just the address of this machine’s gateway address:

DNS configuration

How Do I Restart Network Service?

Simply type the following command:# sh /etc/netstart However, I recommend rebooting the server to make sure it works as described. Now, you should able to connect to both the Internet and LAN systems:# ping 192.168.1.254 # ping 202.54.1.19 # ping cyberciti.biz # dig google.com