This will return the current hostname
$ hostname MyHostameTo set hostname immediately:
$ hostname [MY_HOSTNAME]This will change the hostname of your system immediately, but the original hostname will be restored upon next reboot. To set hostname to be permant follow the instructions below. For systemd based distributions(newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. ) use the hostnamectl command:
$ sudo hostnamectl set-hostname [MY_HOSTNAME]For sysvinit(in short init) based distributions(older linux distributions) edit /etc/hostname:
# vim /etc/hostnameAdd a new line for the hostname in /etc/hosts:
# vim /etc/hosts
127.0.0.1 [MY_HOSTNAME]And run:
# /etc/init.d/hostname restartFor RHEL/CentOS based systems that use init, edit /etc/sysconfig/network:
# vi /etc/sysconfig/network
/etc/sysconfig/network NETWORKING=yes HOSTNAME="[MY_HOSTNAME]" GATEWAY="192.168.0.1" GATEWAYDEV="eth0" FORWARD_IPV4="yes"
