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 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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts