Hostname Info and Management with hostnamectl
Use hostnamectl to view and update hostname metadata
I’ve just realised that I have been managing hostnames the old, manual way on most of my servers:
- check
/etc/hosts
- update network configuration scripts
- if necessary, edit
/etc/hostname
- reboot
But the same can be accomplished much easier on most of the modern Linux distros and releases: just use the hostnamectl
command.
Without any parameters, hostnamectl
will show you current settings:
There’s quite a few parameters that hostnamectl
command takes, all implementing additional flexibility in naming and tracking your nodes on infrastructure.
set-hostname
– actually configuring the hostname (you don’t need to know config file locations, just enter the hostname)
set-chassis
– easy way of confirming the hardware your OS is running on (and whether it’s a VM or not)
set-deployment
– option to specify if your Linux box is development, staging or production
set-location
– allows you to specify geographical location of the server (freeform text)
For example, here’s how I can specify that my Raspberry Pi is a server grade hardware:
… if we check now, we will see the Chassis field showing:
See Also
Use hostnamectl to view and update hostname metadata
I’ve just realised that I have been managing hostnames the old, manual way on most of my servers:
- check
/etc/hosts
- update network configuration scripts
- if necessary, edit
/etc/hostname
- reboot
But the same can be accomplished much easier on most of the modern Linux distros and releases: just use the hostnamectl
command.
Without any parameters, hostnamectl
will show you current settings:
There’s quite a few parameters that hostnamectl
command takes, all implementing additional flexibility in naming and tracking your nodes on infrastructure.
set-hostname
– actually configuring the hostname (you don’t need to know config file locations, just enter the hostname)set-chassis
– easy way of confirming the hardware your OS is running on (and whether it’s a VM or not)set-deployment
– option to specify if your Linux box is development, staging or productionset-location
– allows you to specify geographical location of the server (freeform text)
For example, here’s how I can specify that my Raspberry Pi is a server grade hardware:
… if we check now, we will see the Chassis field showing: