# Problem with setting host name



## bobrof (Jul 11, 2009)

I have a problem with FreeBSD 7.1.
To set up host name, a line was added to /etc/rc.conf:
	
	



```
# -- sysinstall generated deltas -- # Wed Jul  1 15:59:06 2009
# Created: Wed Jul  1 15:59:06 2009
# Enable network daemons for user convenience.
# Please make all changes to this file, not to /etc/defaults/rc.conf.
# This file now contains just the overrides from /etc/defaults/rc.conf.
keymap="ru.koi8-r"
moused_enable="YES"
defaultrouter="192.168.0.1"
ifconfig_ral0="WPA DHCP"
postgresql_enable="YES"
accf_http_load="YES"
hostname="aaa.bb"
apache22_enable="YES"
apache22_http_accept_enable="YES"
```

After the boot process, I check host name with "hostname" command, but get empty line.
Setting hostname with "#hostname mt-note" works well, but after reboot host name is still empty.

My uname:
	
	



```
FreeBSD aaa.bb 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Thu Jan  1 14:37:25 UTC 2009     [email]root@logan.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386
```

Can anyone please help with setting host name? Thanks in advance.


----------



## graudeejs (Jul 11, 2009)

To avoid freebsd complaining about unqualified hostname, I set it to my IP

for example:

```
hostname="192.168.0.100" # works without problem
```


----------



## bobrof (Jul 11, 2009)

Sorry, this didn't work too.


----------



## vivek (Jul 11, 2009)

Add rc.conf

```
hostname="server.example.com"
```

At shell type:

```
hostname server.example.com
```

Finally, add it /etc/hosts

```
echo '192.168.0.2 server.example.com'  >>/etc/hosts
```
Replace 192.168.0.2 and server.example.com with actual names you want. It is possible that DHCP creating some problem and erasing hostname.


----------



## bobrof (Jul 11, 2009)

I tried
	
	



```
#rc.conf:
hostname="home.vezde.biz"

hostname home.vezde.biz

#/etc/hosts
127.0.0.1 home.vezde.biz
```
But still after reboot I have empty hostname. May be it is really DHCP. If it is so, how can I solve it?


----------



## vivek (Jul 11, 2009)

Yes, that is what dhcp does. What you can do is set hostname to empty in rc.conf:

```
hostname=""
```
Your DHCP server isn't sending the hostname back at all. Is it wi-fi router or dhcpd server running on UNIX / Linux? 

To solve your problem just create you *own* script using the dhclient-exit-hooks which sets hostname. Under freebsd create a file /etc/dhclient-exit-hooks and add the following code to setup hostname:

```
#!/bin/sh
check_hostname(){
 hostname you.example.com
}
```
And set perms:

```
chmod +x /etc/dhclient-exit-hooks
```
Try it out and let me know. Once done try restarting the system. If above fails use /etc/dhclient-enter-hooks instead of /etc/dhclient-exit-hooks with same shell code:


----------



## bobrof (Jul 11, 2009)

Thank you, renaming to /etc/dhclient-enter-hooks worked!


----------

