Imagine there's 30 McDonald’s franchises operates under the same menu, layout, the branding.
Similar to 30 Linux server which using clone OS software to duplicate.
To identify each franchises, the name pattern should follow like "MCD_Street_A", "MCD_Street_B"...
30 Linux hostname should be like "Host_A", "Host B"
Change hostname
Verify current hostname
hostname
Change hostname
hostnamectl modifies /etc/hostname automatically so it survives a reboot.
hostnamectl hostname [New hostname]
Example: hostnamectl hostname server1.example.com
Verify current hostname
hostname
Set alias
Check current IP address
ip a
Refer IP address beside lo: (exp: eth0, ens33 or enp0s3)
Open file /etc/hosts
sudo vim /etc/hosts --> Esc --> I --> Enter
Add new line
[IP address] [Hostname] [Alias]
Example: 192.168.0.110 server1.example.com server1
Save and exit:
Esc -->:wq --> Enter
Verify alias
ping [Alias]
Example: ping server1
Solution
student@localhost:~$ hostname
localhost.localdomain
student@localhost:~$ hostnamectl hostname server1.example.com
student@localhost:~$ hostname
server1.example.com
student@localhost:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:51:d6:54 brd ff:ff:ff:ff:ff:ff
altname enx08002751d654
inet 192.168.0.110/24 brd 192.168.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 2001:d08:2230:e7a1:a00:27ff:fe51:d654/64 scope global dynamic noprefixroute
valid_lft 3125sec preferred_lft 3125sec
inet6 fe80::a00:27ff:fe51:d654/64 scope link noprefixroute
valid_lft forever preferred_lft forever
student@localhost:~$ sudo vim /etc/hosts
[sudo] password for student:
student@localhost:~$ ping server1
PING server1.example/com (192.168.0.110) 56(84) bytes of data.
64 bytes from server1.example/com (192.168.0.110): icmp_seq=1 ttl=64 time=0.156 ms
64 bytes from server1.example/com (192.168.0.110): icmp_seq=2 ttl=64 time=0.039 ms
64 bytes from server1.example/com (192.168.0.110): icmp_seq=3 ttl=64 time=0.685 ms
64 bytes from server1.example/com (192.168.0.110): icmp_seq=4 ttl=64 time=0.035 ms
64 bytes from server1.example/com (192.168.0.110): icmp_seq=5 ttl=64 time=0.083 ms
^C
--- server1.example/com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4103ms
rtt min/avg/max/mdev = 0.035/0.199/0.685/0.246 ms
student@localhost:~$