Setting a Static IP In OpenBSD


Notes:

  • The headings used below contain links to the relevant manual pages.
  • These links are for the arm64 architecture and OpenBSD v 6.7, which is the architecture I’m interested in and the current OpenBSD release at the time of writing.

/etc/hostname.if

This is the file to add your:

  • static ip address.
  • subnet mask.
  • broadcast ip address.

If you opted to use dhcp at install, then you’ll see your hostname.if file will contain the single line:

dhcp

Comment this line out or delete it. Replace it with the following:

inet s.s.s.s m.m.m.m b.b.b.b

where:

  • s.s.s.s is your desired ip address, eg. 192.168.0.7
  • m.m.m.m is your subnet mast, eg. 255.255.255.0
  • b.b.b.b is the broadcast ip address, eg. 192.168.0.255

/etc/mygate

This the file to add your:

  • gateway ip address, eg. 192.168.0.1

If you have only one active interface on your machine, you will need an /etc/mygate file. From the man page:

  • If any hostname.if(5) files contain “dhcp” directives, IPv4 entries in /etc/mygate will be ignored.
  • /etc/mygate is processed after all interfaces have been configured.
  • If /etc/mygate does not exist, no default gateway is added to the routing table.

So, if you’re configuring your sole ethernet interface and you don’t have a wifi interface using dhcp, you’ll need an /etc/mygate file so that a default route is added to the routing table. I learnt this the hard way. I spent a whole weekend trying to figure out why my httpd daemon was not accepting requests forwarded through my modem/router. I didn’t have this file. Once I created it and restarted my network, everything worked.

/etc/netstart

Once you’ve configured your hostname.if and mygate files, you’re ready to restart your network:

# sh /etc/netstart

Categories:OpenBSD

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: