How to Configure Network Interfaces on OpenBSD
- Last updated: Nov 1, 2024
Intro
I'm going to gather here my notes on setting up network interfaces under OpenBSD.
Network Configuration
Preamble
- Get interface name:
openbsd# ifconfig
- we need to create a
/etc/hostname."interface_name"
file for each interface, containing this information:dhcp
: sets interface to dhcp modeaddress_family
:inet
forIPv4
address
: IP addressnetmask
: network maskNONE
: no broadcast address
address_family address netmask broadcast [other options]
- Here with static addressing:
openbsd# ifconfig
lo0: flags=2008049<UP,LOOPBACK,RUNNING,MULTICAST,LRO> mtu 32768
index 5 priority 0 llprio 3
groups: lo
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
inet 127.0.0.1 netmask 0xff000000
vmx0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:50:56:1a:b0:11
index 1 priority 0 llprio 3
groups: egress
media: Ethernet autoselect (10GbaseT)
status: active
inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255
openbsd# cat /etc/hostname.vmx0
inet 192.168.1.10 255.255.255.0 NONE
Some examples of configurations
- Set the gateway:
openbsd# echo "192.168.1.1" > /etc/mygate
- Set the
em0
interface to DHCP:
openbsd# echo "dhcp" > /etc/hostname.em0
- Set the
em1
interface with a static address (/etc/hostname.em1
file):
inet 192.168.1.2 255.255.255.0 NONE
- Set up a
vlan10
interface on theem1
interface (/etc/hostname.vlan10
file):
inet 172.21.0.31 255.255.255.0 NONE vlan 10 vlandev em1
- Set host name:
openbsd# echo "gateway.std.rocks" > /etc/myname
- Set DNS:
openbsd# echo "nameserver 192.168.1.254" > /etc/resolv.conf
- Complete DNS configuration (edit
/etc/resolv.conf
):
search example.com
nameserver 125.2.3.4
nameserver 125.2.3.5
#file will look for entries in /etc/hosts
#bind will request them from the name servers.
#In this case, the order would be: search in /etc/hosts, then request to DNS servers.
lookup file bind
- To take these changes into account, we need to run the following command:
openbsd# sh /etc/netstart