Configuring the network in OpenBSD is done during the installation and can later be changed by modifying the configuration files in /etc/. The information on this page will allow you to retrieve and change the network connfiguration on an OpenBSD system.
Networking Hardware Identification #
In OpenBSD, network interfaces are named by taking the shorthand version or other identifier of the network card and one or more digits.
For example, Realtek network interface cards will be called re0, re1, re2, etc.
The ifconfig command will show all the available interfaces.
$ ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768 index 4 priority 0 llprio 3 groups: lo inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4 inet 127.0.0.1 netmask 0xff000000 re0: flags=808843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,AUTOCONF4> mtu 1500 lladdr 00:e0:67:04:ff:14 index 1 priority 0 llprio 3 media: Ethernet autoselect (1000baseT full-duplex,rxpause,txpause) status: active inet xxx.xxx.xxx.xxx netmask 0xffffff00 broadcast xxx.xxx.xxx.xxx re1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 lladdr 00:e0:67:04:ff:15 index 2 priority 0 llprio 3 media: Ethernet autoselect (1000baseT full-duplex,rxpause,txpause) status: active inet x.x.x.x netmask 0xffffff00 broadcast x.x.x.x enc0: flags=0<> index 3 priority 0 llprio 3 groups: enc status: active
The above output shows two Ethernet interfaces: re0 and re1. Both are configured with an ip address and both are active.
Additionally, aside from the Realtek interfaces, there are some other interfaces that are enabled by default. These interfaces have various purposes and are virual interfaces.
- enc - Encapsulating interface
- lo - Loopback interface
- pflog - Packet Filter logging interface
More virtual interfaces can be added with the ifconfig command.
Modifying the Network Configuration #
The configuration for network interfaces resides in a text file in /etc/. There is a separate configuration file per network interface. The naming scheme for these files is hostname.if. So, in the above example, there would be two files named hostname.re0 and hostname.re1.
In case the network interface is configured to have a static ip address, the content of the configuration file will look something like this:
inet 10.0.0.100 255.255.255.0
Or, if ipv6 is also enabled, the content would look like this:
inet xx.xx.xx.xx 255.255.255.0 inet6 xxxx:6000:9344::154 64 -soii
If the interface is configured dynamically the configuration will look like this:
It’s also possible to modify the interface interactively from the commandline using the ifconfig command. This hostname.re0 file also has an interactive equivalent:
ifconfig re0 10.0.0.100 255.255.255.0
In order for any changes made to the configuration file(s) to take effect, a restart of the network is required. On OpenBSD, the network is restarted with the netstart utility.
To start or reset an interface (re1 in this case), use the following command:
sh /etc/netstart re1
Netstart is primarily used on boot to initialize the network. During boot, it performs the following operations:
- Set the machine’s name.
- Configure the loopback interface.
- Configure all the physical interfaces.
- Configure the following non-physical interfaces: trunk, vlan, pfsync, and carp.
- Initialize the routing table and set up the default routes.
- Configure the remaining non-physical interfaces: pppoe, gif, and gre.
- Configure all bridge interfaces.
Setting the Default Hostname #
The hostname of the system is set in a configuration file called myname, located in /etc/. The hostname will be set during the installation process but can be changed afterwards by modifying the content of the /etc/myname file. In order for the change to have effect, execute
Using the hostname command will not result in a permanent change of the hostname. After a system restart or
sh /etc/netstart, the hostname once again be whatever the myname file contains.
Setting the Default Gateway #
Defining the default gateway on OpenBSD happens through a configuration file called mygate, located in /etc/. If the file exists, the default gateway will be added to the routing table after all the interfaces have been configured.
The mygate file can contain an IPv4 address, and IPv6 address, or both IPv4 and IPv6 addresses on 2 lines. The format must be a so-called dotted quad notation for IPv4 addresses and for IPv6 addresses the colon notation should be used.
In case dhcp is configured or, in the case of IPv6, autoconf, the default gateway will not be set using the mygate file.
DNS Resolution #
Setting up DNS on OpenBSD happens in a configuration file called resolv.conf, located in /etc/.
Below is an example confifuration. For the example.com domain, it’s possible to use the short version. A DNS query for fileserver would result in fileserver.example.com, if it exists. Two external nameservers are defined. On the final line is the order in which the lookup is performed. First, the system will look for any matches in the /etc/hosts file. If none are found, it will perform a query on the one of the 2 nameservers.
search example.com nameserver 184.108.40.206 # Chaos Computer Club Berlin nameserver 220.127.116.11 # Germandy Privacy Foundation lookup file bind
Checking Routes #
You can check your routes via netstat or route.
$ netstat -rn Routing tables Internet: Destination Gateway Flags Refs Use Mtu Prio Interface default 10.0.0.1 UGS 4 16 - 12 re0 224/4 127.0.0.1 URS 0 0 32768 8 lo0 127/8 127.0.0.1 UGRS 0 0 32768 8 lo0 127.0.0.1 127.0.0.1 UH 2 15 32768 1 lo0 10.0.0/24 link#1 UC 1 4 - 4 re0 10.0.0.1 aa:0:4:0:81:d UHL 1 11 - 1 re0 10.0.0.38 127.0.0.1 UGHS 0 0 - 1 lo0
$ route show Routing tables Internet: Destination Gateway Flags Refs Use Mtu Prio Iface default 10.0.0.1 UGS 4 16 - 12 re0 base-address.mcast localhost URS 0 0 32768 8 lo0 loopback localhost UGRS 0 0 32768 8 lo0 localhost localhost UH 2 15 32768 1 lo0 10.0.0/24 link#1 UC 1 4 - 4 re0 10.0.0.1 aa:0:4:0:81:d UHL 1 11 - 1 re0 10.0.0.38 localhost UGHS 0 0 - 1 lo0
Setting Aliases on an Interface #
Using aliases can be very useful. It allows you to use multiple IP addresses on a single interface. The confiuration of aliases happens in the network interface’s configuration file “hostname.if” (e.g. hostname.re0).
If the aliases are in the same subnet as the main interface (e.g. 255.255.255.0), the alias netmask will be 255.255.255.255.
An example of a network interface configuration file would be like this. The interface is configured with IPv4 address 10.0.0.2 and there are 2 aliases: 10.0.0.3 and 10.0.0.4.
inet 10.0.0.2 255.255.255.0 inet alias 10.0.0.3 255.255.255.255 inet alias 10.0.0.4 255.255.255.255
After modifying the file, use the
sh /etc/netstart command to let the changes take effect.
Aliases don’t show up on a regular ifconfig command but will when adding the -A option. So use
ifconfig -A to show any aliases.