Join Scott Simpson for an in-depth discussion in this video Set the system hostname, part of Linux: Network Configuration.
- We can set our hostname to give a machine an identity, or to be able to distinguish it from others. I'll show you two ways of doing this. The first is within Network Manager tool and MCLI, but before we do that we need to make sure Network Manager is running. I turned it off in the previous chapter, but if you've been skipping around you may not have. Let's see if the service is running with sudo systemctl status NetworkManager. And I can see that mine's not running. To get it running again, I need to enable it and start it up, so I'll write sudo systemctl enable NetworkManager and then sudo systemctl start NetworkManager.
All right. Now I can use sudo nmcli general hostname and set the name of my system to something else, maybe server-1. You might get an SUMX message here and that's fine. This change has taken effect, as I can see by pinging my hostname, but it's not reflected here in the terminal yet. We can fix that by closing this window and opening a new one, or by logging out and back in. You can also use an nmcli general hostname to read the hostname of the system.
Another way to set the hostname is to us hostnamectl. Just typing hostnamectl by itself gives me some information about this system, including the hostname. To set the hostname, we can use the set hostname argument, like this. Hostnamectl set-hostname, and we'll change the name to server-2, and then I can check it again with hostnamectl.
Note: This course concentrates on the CentOS distribution of Linux, but there are separate lessons on configuring networking for Ubuntu/Debian.
- Finding device information
- Managing connections with NetworkManager
- Configuring dynamic addresses using DHCP
- Configuring static clients
- Configuring Wi-Fi
- Configuring networking manually
- Setting the hostname
- Configuring the firewall
- Routing traffic between networks