rss logo

Configuring network interfaces in OpenBSD

OpenBSD Logo

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 mode
    • address_family: inet for IPv4
    • address: IP address
    • netmask: network mask
    • NONE: 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 the em1 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
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address