Howto change hostname without reboot on Centos or Redhat RHEL

Howto change hostname without reboot on Centos or Redhat RHEL



1. Check Present Hostname

[root@Redhat6 ~]# hostname
[root@Redhat6 ~]# cat /etc/sysconfig/network
[root@Redhat6 ~]#

2. Change to new hostname

[root@Redhat6 ~]# vi /etc/sysconfig/network
[root@Redhat6 ~]#

3. Check Ip address on Centos or RHEL and map that IP Address to /etc/hosts

[root@Redhat6 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:57:eb:8d brd ff:ff:ff:ff:ff:ff
inet brd scope global eth0
inet6 fe80::20c:29ff:fe57:eb8d/64 scope link
valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
link/ether 1e:27:d4:44:f8:e2 brd ff:ff:ff:ff:ff:ff
[root@Redhat6 ~]#
[root@Redhat6 ~]# cat /etc/hosts localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 FileServer
[root@Redhat6 ~]#

4. Change hostname in kernel

[root@Redhat6 ~]# vi /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.# Controls IP packet forwarding
net.ipv4.ip_forward = 0# Controls source route verification
net.ipv4.conf.default.rp_filter = 1# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536

# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296

# Hostname
kernel.hostname = FileServer

6. Restart network to get the new hostname

[root@Redhat6 ~]# /etc/init.d/network restart
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/5
state: activated
Connection activated
[ OK ]

7. Check new hostname

[root@Redhat6 ~]# hostname
[root@Redhat6 ~]#

That’s all. Thanks for using

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>