any service restart options available, to see the hostname change with out a reboot?

  • 20 September 2017
  • 4 replies

with nclu 'net add hostname' -> we can see the hostname after a re-login
but the linux way -> /etc/hosts and /etc/hostname -> the new hostname is showing up only after a reboot. is there a service that could be restarted to see this with just a re-login and not a reboot

4 replies

sudo hostname yourhostname
log in
@Thor, i am actually looking for the 'service' behind this
There is no service to set the hostname. It's set via the hostname command at startup, if the /etc/hostname exists - or via dhcp-client if it's set to do so.

The /etc/rcS.d/ is the startup script responsible to set the hostname at boot. If you examine the code, you'll see it's doing absolutely nothing remarkable.
do_start () {   [ -f /etc/hostname ] && HOSTNAME="$(cat /etc/hostname)"     # Keep current name if /etc/hostname is missing.   [ -z "$HOSTNAME" ] && HOSTNAME="$(hostname)"     # And set it to 'localhost' if no setting was found   [ -z "$HOSTNAME" ] && HOSTNAME=localhost     [ "$VERBOSE" != no ] && log_action_begin_msg "Setting hostname to '$HOSTNAME'"   hostname "$HOSTNAME"   ES=$?   [ "$VERBOSE" != no ] && log_action_end_msg $ES   exit $ES  }  
Userlevel 1
There isn't a 'service' to restart, as far as I am aware.
However, if you are not using NCLU, and prefer to edit /etc/hosts , /etc/hostname to do this, have a look at this script: