How to assign hostname in Linux without a reboot ?

In this article, we will see how to assign hostname to a linux machine temporarily or permanent without a reboot.

We have already seen the tip of assigning the domain name here.

Here we will extend it to see how to assign hostname to the system and make it effective without a system reboot.

Lets see how to change hostname step by step:

Changing Linux system hostname permanently

1. Check your current hostname.

[root@nglinux ~]# hostname 
[root@nglinux ~]# 

2. Define new system hostname in /etc/sysconfig/network

### For example:- let me define new hostname for my system as ngelinux.
[root@nglinux ~]# vim /etc/sysconfig/network


3. Restart the network service for changes to take effect.

[root@nglinux ~]# service network restart
Shutting down interface eth2:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth2:  Determining if ip address is already in use for device eth2...
                                                           [  OK  ]
[root@nglinux ~]# 

4. Logout and Login to see the effective changes in hostname.

### Form:
[root@nglinux ~]#

### To:
[root@ngelinux ~]# 

Now we can see the hostname of our system is updated.

Temporarily changing hostname in current shell

Lets see how to temporarily change the hostname in current bash shell.
1. Change using hostname command

[root@nglinux ~]#hostname ngelinux-new
[root@nglinux ~]#hostname

2. Change HOSTNAME Variable value.

[root@nglinux ~]#echo $HOSTNAME 
[root@nglinux ~]#export HOSTNAME=ngelinux-new
[root@nglinux ~]#echo $HOSTNAME 
[root@nglinux ~]#

We need to perform above both steps for temporary change to take effect on the current shell.

I hope now you can change your machine hostname easily.

Please do post your comments/suggestions below.

0 0 votes
Article Rating
Notify of

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments