setting hostname on running system

A

Anonymous

Guest
How do you set the hostname on a system without one without rebooting?

I've tried the following sources to find the information:
  • FreeBSD handbook: Networking Services chapter
  • google.com/bsd search "setting hostname" top 10 results
 
mharvey87 said:
How do you set the hostname on a system without one without rebooting?

Code:
# hostname ${NEW_HOSTNAME}

Verify with
Code:
# hostname
${NEW_HOSTNAME}

... but to keep it permanent, remember to put it also in the /etc/rc.conf file.
 
Just tried killing apache, killing hostname, changing hostname in /etc/rc.conf to hostname="localhost" and then restarting /etc/rc.d/hostname and apachectl but when I checked hostname by entering the commmand "hostname" into the shell it did not show a change in the variable so the hostname didn't appear to have been affected.
 
@vermaden The ouput of hostname ${localhost} or ${example.com} returns the current value of hostname (The default null-string/Amnesiac?). I then try using hostname to verify using the command "hostname" but it doesn't seem to have changed. Apache after a restart doesn't seem to have noticed as well.
 
mharvey87 said:
Just tried killing apache, killing hostname, changing hostname in /etc/rc.conf to hostname="localhost" and then restarting /etc/rc.d/hostname and apachectl but when I checked hostname by entering the commmand "hostname" into the shell it did not show a change in the variable so the hostname didn't appear to have been affected.

localhost is a reserved hostname (RFC-2606). Don't use it as an actual hostname.
 
hostname $<myhostname> works, I was retaining the $< & > which seems to have made it not work.
 
Back
Top