How to change Linux RedHat HOSTNAME

In this tutorial i will show you how to change Linux Red Hat 6.x HOSTNAME either using DHCP (dynamic IP) or static IP. this might work also on other versions or flavors of Linux, i tested it only on Linux Red Hat 6.x.

 

Configure HOSTNAME with dynamic IP address:

For this tutorial lets say you want to change your machines HOSTNAME to “my_new_hostname”

 

  • Open file /etc/hosts
  • Map your desired HOSTNAME to 127.0.0.1. it should look like:

127.0.0.1               my_new_hostname localhost.localdomain localhost

  • Save and exit the file
  • Open file  /etc/sysconfig/network
  • Look for the line HOSTNAME and add your new HOSTNAME. it should look like:

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=my_new_hostname

  • Save and exit the file
  • Open file /etc/sysconfig/network-scripts/ifcfg-eth0
  • If missing, add the line DHCP_HOSTNAME and add your new HOSTNAME. it should look like:

ONBOOT=yes
BOOTPROTO=dhcp
DHCP_HOSTNAME=my_new_hostname

  • Restart the network using command:

service network restart

  •  Test your configuration:

Run command in shell: hostname. the output should be the new HOSTNAME you configured

From a different PC ping the new hostname using command: ping my_new_hostname. you should get a success reply back

 

 

Configure HOSTNAME with static IP address:

For this tutorial lets say you want to change your machines HOSTNAME to “my_new_hostname” and your static IP address is 10.219.62.21

 

  • Open file /etc/hosts
  • Map your desired HOSTNAME to the static IP you want to assign it. it should look like:

10.219.62.21          my_new_hostname

  • Save and exit the file
  • Open file  /etc/sysconfig/network
  • Look for the line HOSTNAME and add your new HOSTNAME. it should look like:

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=my_new_hostname
GATEWAY=<Your gateway IP>

  • Save and exit the file
  • Open file /etc/sysconfig/network-scripts/ifcfg-eth0
  • If missing, add the line DHCP_HOSTNAME and add your new HOSTNAME. it should look like:

DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.219.62.255
IPADDR=10.219.62.21
IPV6INIT=yes
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=10.219.62.0
DHCP_HOSTNAME=my_new_hostname
ONBOOT=yes

  • Restart the network using command:

service network restart

  •  Test your configuration:

Run command in shell: hostname. the output should be the new HOSTNAME you configured

From a different PC ping the new hostname using command: ping my_new_hostname. you should get a success reply back

 

Advertisements
Tagged with: , , ,
Posted in Computers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: