# setting hostname on running system



## Anonymous (Apr 22, 2010)

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


----------



## sixtydoses (Apr 22, 2010)

Am not at my machine right now, but have you tried `# /etc/rc.d/hostname restart`
?


----------



## vermaden (Apr 22, 2010)

mharvey87 said:
			
		

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




```
# hostname ${NEW_HOSTNAME}
```

Verify with

```
# hostname
${NEW_HOSTNAME}
```

... but to keep it permanent, remember to put it also in the /etc/rc.conf file.


----------



## Anonymous (Apr 22, 2010)

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.


----------



## Anonymous (Apr 22, 2010)

@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.


----------



## vermaden (Apr 22, 2010)

mharvey87 said:
			
		

> it doesn't seem to have changed.


It have changed here ...


```
core# hostname
core
core# hostname CORE
core# hostname
CORE
core#
```


----------



## SirDice (Apr 22, 2010)

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.


----------



## Anonymous (Apr 22, 2010)

hostname $<myhostname> works, I was retaining the $< & > which seems to have made it not work.


----------

