OpenBSD Change Hostname

I am a new OpenBSD Unix user. How do I change my hostname under OpenBSD operating system using the cli?

The hostname command displays the name of the current OpenBSD server or host. The superuser (root) can set the host name by editing a /etc/myname file. This is used at system boot time by netstart to initialize the hostname.

How to display hostname on OpenBSD

Type the any one of the following command
# hostname
# cat /etc/myname

Sample outputs:
OpenBSD Change Hostname Commands

OpenBSD Chane Host Name

Simply login as root:
$ su -
$ doas -s
Type the following command to change/update your hostname:
# echo "" > /etc/myname
# echo "" > /etc/myname
# echo 'unixbox' > /etc/myname

Or edit using a text editor such as vi:
# vi /etc/myname
From the man page:

/etc/myname contains the symbolic name of the host machine. The file should contain a single line specifying the fully qualified domain name (FQDN) of the system (e.g. The name must be resolvable, either by matching a hostname specified in /etc/hosts (see hosts(5)) or through DNS (see resolv.conf(5)). The hostname is set via the hostname(1) utility at boot time. See hostname(7) for a description of hostname resolution.

During the system boot, netstart is executed. netstart performs the various operations including setting up the machine’s name. You can reboot box to test new settings:
# reboot
OR just set hostname at the cli i.e. no need to reboot the server:
# hostname
You must edit /etc/hosts file too:
# vi /etc/hosts
Rename all old hostname to new hostname if present in that file. For more info see the following man pages:
$ man hostname
$ man 5 myname
$ man 5 hosts
$ man 8 netstart
$ man 1 su
$ man 1 doas

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

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
1 comment… add one
  • Michael Kremser Apr 23, 2014 @ 16:24

    To make hostname changes effective, one could issue this command:
    hostname `cat /etc/myname`

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