Intro

Changing a computer's name is a common thing to do.

This is how.

 

Guide

To change the hostname permanently, follow these steps.

 

For CentOS

  1. Edit /etc/sysconfig/network.
    # nano /etc/sysconfig/network
  2. Change the HOSTNAME.
    HOSTNAME=newHostname
  3. Save and exit.

  4. Edit /etc/hosts
    # nano /etc/hosts
  5. Add a new line.
    127.0.0.1 newHostname
  6. Save and exit.

  7. Restart the network daemon.
    For CentOS 6 and older:
    # service network restart

    For CentOS 7 and newer, as well as for most Ubuntu-distros:
    # systemctl restart NetworkManager
  8. If restarting the network didn't or won't change the hostname for some reason, try restarting the computer.
    # shutdown -r now
  9. Confirm the name change.
    # hostname
    newHostname

 

 

For Ubuntu

  1. Edit /etc/hosts.
    # nano /etc/hosts
  2. Add a new line.
    127.0.0.1 newHostname
  3. Save and exit.

  4. Run hostnamectl to check the name.
    # hostnamectl
    Static hostname: oldHostname
    Icon name: computer-desktop
    Chassis: desktop
    Operating System: Ubuntu 18.04.1 LTS
    Kernel: Linux 4.15.0-43-generic
    Architecture: x86-64
  5. Nope, not yet set. So we run hostnamectl again, but this time with a couple of parameters.
    # hostnamectl set-hostname newHostname
  6. And a confirmation.
    # hostnamectl
    Static hostname: newHostname
    Icon name: computer-desktop
    Chassis: desktop
    Operating System: Ubuntu 18.04.1 LTS
    Kernel: Linux 4.15.0-43-generic
    Architecture: x86-64

 

 

 

Sources

https://unix.stackexchange.com/questions/145019/how-to-change-hostname-on-centos-6-5

https://support.rackspace.com/how-to/centos-hostname-change/

https://linuxize.com/post/how-to-change-hostname-on-ubuntu-18-04/

 

 

 

 

 

 

 

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext