OpenBSD Change / Set IP Address For Network Interface

How do I configure or change existing IP address under OpenBSD operating system? How do I configure TCP / IP under OpenBSD?

Under OpenBSD network interface-specific configuration stored in files located at /etc directory. First you need to find out your interface name using ifconfig command. If your interface name is pcn0, open /etc/hostname.pcn0 file for TCP/IP configuration. The hostname.* and bridgename.* files contain information regarding the configuration of each network interface. One file should exist for each interface that is to be configured, such as hostname.fxp0 or bridgename.bridge0. However, a configuration file is not needed for lo0 (loopback interface).

Task Find out current interface name and IP information

Type the following command at a shell prompt:
# ifconfig
Sample output:

lo0: flags=8049 mtu 33224
        groups: lo
        inet netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
pcn0: flags=8843 mtu 1500
        lladdr 00:0c:29:7a:b5:ce
        groups: egress
        media: Ethernet autoselect (autoselect)
        inet netmask 0xfffffff0 broadcast
        inet6 fe80::20c:29ff:fe7a:b5ce%pcn0 prefixlen 64 scopeid 0x1
pflog0: flags=0 mtu 33224
enc0: flags=0 mtu 1536

Task: View pcn0 interface TCP / IP configuration

Type the following command:
# cat /etc/hostname.pcn0
Sample output:

inet NONE

Task: Change IP configuration

To set new IP address open interface configuration file /etc/hostname.pcn0
# vi /etc/hostname.pcn0
Append/modify configuration:
inet NONE
Save and close the file.

How do I restart or update networking configuration

To reset or restart an existing interface to its default state or update state, by invoking the following, where pnc0 is the interface name:
# sh /etc/netstart pnc0

Assign ip address using ifconfig command

You can assign the address of with a network mask of to interface pnc0, use:
# ifconfig pnc0 inet netmask

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • M May 9, 2010 @ 19:16

    what i do if the file comes with

  • Web Hosting Oct 19, 2011 @ 20:09

    Just wanted to add here that unfrotunately the netstart script didn’t restore my default gateway so in fact it changed the IP address correctly but I wasn’t able to connect to the internet. So to in order to add back the default route you would have to issue the following command:

    route add default `cat /etc/mygate`

    don’t forget here to modify the IP of your default router in /etc/mygate

  • Sergio Jimenez Oct 24, 2020 @ 3:30

    How i configure:
    re0 --> internet
    re1 --> private lan
    re2--> internet

    I have 192.168.*.2 in re1
    132.248.*.251 in re0
    132.248.*.250 in re2
    where re0 and re1 work fine
    but re2 dont show gw 132.248.*.254. Any tip ?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum