Modify Server Hostname Using SSH in CentOS
.Change the hostname on a running system
On any Linux system, the hostname can be modified using the command ‘hostname’ Here are some quick usages of the command line hostname:
without any parameter it will output the current hostname of the system.
it will output the fully qualified domain name (or FQDN) of the system.
will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.
RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit
/etc/sysconfig/network NETWORKING=yes HOSTNAME="change.domainname.com" GATEWAY="184.108.40.206" GATEWAYDEV="eth0" FORWARD_IPV4="yes"
So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.
Use sysctl to change the hostname
Why would someone need a different method of doing the same thing as above? No idea, but here is anyway: use sysctl to change the variable kernel.hostname: Use:
to read the current hostname, and
to change it.
Was this answer helpful?
This article provides a step-by-step guide to installing the Python interpreter on an Ubuntu VPS...
A critical file you often need to manage is the php.ini file. It controls many import aspects of...
This article explains the method of changing the root password on a Linux Server using SSH. SSH...
If, at sometime, you are without access to the WHM web interface and are needing to Install the...
To assign a dedicated IP address to a subdomain, perform the following steps: Step 1: Add the...