Skip to content

Change hostname for Linux

Here are some methods to change hostname for a certain Linux system.

One-time Change

Side effect, ineffective after reboot

hostname {NEW host name}

Permanently Change

1 revise /etc/hosts

127.0.0.1  localhost  {NEW host name}

2 revise /etc/sysconfig/network

HOSTNAME={NEW host name}

Using hostnamectl

hostnamectl set-hostname NAME

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App