Many websites recommend using the hostname command to obtain the IP address.
In this post, I will explain why you should not use this command.
The hostname command in Linux is used to display or set the hostname of a computer.
When used without any arguments, the hostname command will display the current hostname of the system:
This is safe.
When used with an argument, the hostname command can be used to set the hostname of the system:
sudo hostname new_hostname
hostname command also has the -I or --ip-address option to display the IP address of the system:
sudo hostname -I
This will display the IP addresses assigned to the system's network interfaces.
so here is the problem.
If you forgot to type the -, your hostname will be changed to I.
What will happen when the hostname is changed?
In our env, we have many oracle rac clusters.
In the Oracle RAC cluster, the hostname is used to identify the node and communicate with other nodes in the cluster.
When the hostname is changed, other nodes are not be able to communicate with the node and the node becomes inaccessible to the rest of the cluster.
we got two incidents that were related to this in the past year.
So we should always choose the safe command in our daily operation tasks as it can help minimize potential risks.
Check this post to know how to safely check ip address in Linux.
Top comments (0)