OS - How to change the hostname
In this post I'm sharing how to address of the most repetitive tasks after fresh build or clone a VM. Eg. for database pre install tasks .
First of all , I will how to change the hostname.
Next, I will setup the local naming resolution.
At end, how to play with the firewall.
Change hostname
- the hostname is key including for server provisioning and orchestration, the server name can be changed using the hostnamectl command. Lets see bellow some examples.
root@Unknown-08-00-27-26-48-7d # hostnamectl status
Static hostname: localhost.localdomain
Transient hostname: Unknown-08-00-27-26-48-7d
Icon name: computer-vm
Chassis: vm
Machine ID: d5a9e3e4d118804089e345228a189582
Boot ID: f76e3fc1c76f49028a1583b90eb01511
Virtualization: kvm
Operating System: Oracle Linux Server 7.7
CPE OS Name: cpe:/o:oracle:linux:7:7:server
Kernel: Linux 4.14.35-1902.3.2.el7uek.x86_64
Architecture: x86-64
root@Unknown-08-00-27-26-48-7d # hostnamectl set-hostname wls.example.com
root@Unknown-08-00-27-26-48-7d # hostnamectl status
Static hostname: wls.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: d5a9e3e4d118804089e345228a189582
Boot ID: f76e3fc1c76f49028a1583b90eb01511
Virtualization: kvm
Operating System: Oracle Linux Server 7.7
CPE OS Name: cpe:/o:oracle:linux:7:7:server
Kernel: Linux 4.14.35-1902.3.2.el7uek.x86_64
Architecture: x86-64
Setup local name resolution
TIP - I'm getting the IP (192.168.1.118) from the router ( who acts as DHCP). If the VM was cloned, is recommended to generate a new MAC address. With a different MAC the server will receive other available IP.

Humans call each-other by name not by mobile number neither ID number. Is good idea to do the same with server, for that we need a mechanism called "naming resolution". I will leave the details for that topic out this post. For the immediate propose, let's say it could be like a mobile contact list ( name / number).
As mentioned above, i'm getting the IP (192.168.1.118), that information is listed is in a file called "hosts":
Linux : /etc/hosts
Windows : %Systemroot%\System32\drivers\etc\hosts
Backing to Linux command line.
root@Unknown-08-00-27-26-48-7d # ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.118 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::144a:40e:d8a5:5e46 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:26:48:7d txqueuelen 1000 (Ethernet)
RX packets 2703552 bytes 3841742453 (3.5 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 165177 bytes 11675354 (11.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:c1:d2:9c txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@Unknown-08-00-27-26-48-7d # cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
root@Unknown-08-00-27-26-48-7d # echo "192.168.1.118 wls.example.com wls" >> /etc/hosts
root@Unknown-08-00-27-26-48-7d # cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.118 wls.example.com wls
Test the IP conectivity / name resoution
root@Unknown-08-00-27-26-48-7d # ping wls
PING wls.example.com (192.168.1.118) 56(84) bytes of data.
64 bytes from wls.example.com (192.168.1.118): icmp_seq=1 ttl=64 time=0.105 ms
64 bytes from wls.example.com (192.168.1.118): icmp_seq=2 ttl=64 time=0.071 ms
^C
--- wls.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1054ms
rtt min/avg/max/mdev = 0.071/0.088/0.105/0.017 ms
Manage Firewall
To reduce / avoid time on troubleshooting mainly within weblogic ( it has lot of no well know ports used for internal communications) is also recommended to stop / disable the firewall.
root@wls # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-04-09 23:24:47 BST; 4s ago
Docs: man:firewalld(1)
Main PID: 5306 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─5306 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
Apr 09 23:24:46 wls.example.com systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 09 23:24:47 wls.example.com systemd[1]: Started firewalld - dynamic firewall daemon.
root@wls # systemctl stop firewalld
root@wls # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-04-09 23:26:10 BST; 4s ago
Docs: man:firewalld(1)
Process: 5306 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 5306 (code=exited, status=0/SUCCESS)
Apr 09 23:26:09 wls.example.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 09 23:26:10 wls.example.com systemd[1]: Stopped firewalld - dynamic firewall daemon.
root@wls # systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
root@wls # systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Apr 09 23:26:09 wls.example.com systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 09 23:26:10 wls.example.com systemd[1]: Stopped firewalld - dynamic firewall daemon.
Conclusion, these three tasks simplify the system administrator's life, help to prevent issues and time wasting on troubleshooting in VM Lab environments.
Further reading ..
CONFIGURING HOST NAMES USING HOSTNAMECTL(RedHat)
MANAGING SYSTEM SERVICES (RedHat)
Thank you for reading, hope this post was helpful.
Rogerio
Comments