# Local Hostname Lookup Failure



## BAK (Mar 26, 2011)

Hello,

I am running FreeBSD 8.1 Release, and am encountering some problems resolving local hostnames. Here are the symptoms I have observed:


Initial connection to Samba is extremely slow. When attempting to navigate to the machine from a Windows client, it took upwards of 45 seconds to connect. Once it connected, navigation/transfer speeds were fine. [Solved by adding IP address/machine name to hosts file]
Initial connection to SSH client is extremely slow, despite hosts file entry as above. 45seconds+
I can ping the FreeBSD machine from other machines.
The FreeBSD machine can't ping machines by hostname - after a delay of 5-7 seconds it returns:

```
ping: cannot resolve <hostname>: Host name lookup failure
```

The FreeBSD machine can ping machines by IP address.
The FreeBSD machine can resolve and ping external websites (ie: google.com).

I partially resolved my initial problem, the delayed connection to Samba - by adding into the hosts file my IP address and hostname:

/etc/hosts

```
::1  localhost localhost
127.0.0.1 neon.local. neon
192.168.1.3 neon neon
```
However this machine may not always have the same IP address and although this has resolved my most pressing issue there is still an underlying problem.


I believe that the problem lies in a (local) hostname lookup timing out, as once it has connected, network speeds are unaffected - but I'm at a loss of how to troubleshoot it.

Additional Information:
The FreeBSD Machine is a DHCP Client, on a Workgroup based network.
It is running a mostly standard install from the 8.1 Release CD, I have installed Samba but no additional networking services.

rc.conf:

```
hostname="neon"
ifconfig_re0="DHCP"
ipv6_enable="NO"
zfs_enable="YES"
powerd_enable="YES"
sshd_enable="YES"
samba_enable="YES"
```


Any help, even in direction of how to troubleshoot this further, would be greatly appreciated.


----------



## DutchDaemon (Mar 26, 2011)

Keep this in /etc/hosts.


```
127.0.0.1		localhost localhost.my.domain
```

Add to it, if you must, but make sure 'localhost' resolves to 127.0.0.1.


----------



## BAK (Mar 27, 2011)

Hi Dutch,

Thankyou for the prompt reply. I have modified my /etc/hosts file as suggested and it now contains:


```
::1  localhost localhost
127.0.0.1 localhost localhost
192.168.1.3 neon neon
```

Unfortunately this has made no difference to the symptoms outlined in my original post.

I am able to ping the machine (which has a name of 'neon' and an IP address of 192.168.1.3, as suggested by the hosts file entry I created) by name, but removing the hosts entry and attempting to ping by hostname returns the same "Host name lookup failure" message.

How does FreeBSD resolve hostnames (without an entry in /etc/hosts) and what could be stopping it from doing this?


----------



## wblock@ (Mar 27, 2011)

BAK said:
			
		

> How does FreeBSD resolve hostnames (without an entry in /etc/hosts) and what could be stopping it from doing this?



Host names are resolved by the DNS servers set in /etc/resolv.conf (resolv.conf(5)).  If the machine is set up with DHCP, those DNS servers should be filled in automatically.  Otherwise, set them to your local DNS servers:
/etc/resolv.conf

```
nameserver 192.168.1.1
```


----------



## BAK (Mar 27, 2011)

The DHCP has populated /etc/resolv.conf with:

```
nameserver 192.168.1.254
```
Which is correct. The machine is able to ping my router successfully.

So if /etc/resolv.conf is pointing to the right nameserver, is able to ping it, but is still unable to resolve hostnames of other machines on my network, including itself unless there is a specific entry in the /etc/hosts, what could the problem be? No other machines (admittedly all windows clients) on my network have issues with host name resolution, so I'm more inclined to believe that it's the FreeBSD machine rather than the router that is causing the problems.

For reference the router is a Billion 7402GL DSL Modem/Router.


----------



## wblock@ (Mar 27, 2011)

The DHCP/DNS server in the router might not be able to set hostnames, the Windows machines might not be sending them when they get a DHCP lease, could be the Windows machines are using NETBIOS names.  Setting the router to hand out static addresses to the Windows machines by MAC address might be the easiest way to solve it.


----------



## BAK (Mar 27, 2011)

If that's the case why can the windows clients resolve hostnames?

Are you suggesting I need to add a record to the hosts file for every computer on my network?

My router is not an uncommon brand, if it were the router's issue surely there would be more evidence of this issue occurring; knowing my lack of experience with UNIX I'm more inclined to believe that I've broken something without knowing it.


----------



## Beastie (Mar 27, 2011)

BAK said:
			
		

> Are you suggesting I need to add a record to the hosts file for every computer on my network?


Yes, as you can see it from the example inside /etc/hosts (cf. "Imaginary network.").

```
127.0.0.1	localhost machinezero
192.168.1.5	machineone
192.168.1.6	machinetwo
192.168.1.7	machinethree
192.168.1.8	machinefour
```


----------



## wblock@ (Mar 27, 2011)

BAK said:
			
		

> If that's the case why can the windows clients resolve hostnames?



Possibly because Windows can use alternate ways to do it.  DNS is a standard, but not Microsoft's standard, so they came up with alternatives.  That may not be the problem, just a possibility.  I did check an XP system, and it correctly sent its hostname to the DHCP server, which then registered it with DNS.  But this is with isc-dhcp41-server and BIND.  A small router is limited in RAM, ROM, and production cost.



> Are you suggesting I need to add a record to the hosts file for every computer on my network?



That's one way, and may be the easiest way, depending on the size of the network.  You'd also have to set the router to assign a static address to each Windows machine so they don't move around.



> My router is not an uncommon brand, if it were the router's issue surely there would be more evidence of this issue occurring; knowing my lack of experience with UNIX I'm more inclined to believe that I've broken something without knowing it.



http://forums.whirlpool.net.au/archive/1160572 is interesting.  Looking at the manual, it appears that it doesn't really have a DNS server at all.  So we're back to the question of how the Windows machines resolve their names, and again I'd suspect alternate methods (NETBIOS).  The various SAMBA ports in /usr/ports/net may have a way to do that on FreeBSD.


----------



## BAK (Mar 27, 2011)

Ultimately the fact that external hostnames don't resolve isn't that important an issue - however the issue is that the machines OWN hostname doesn't resolve - so when trying to connect to Samba and by SSH there is an enormous delay before it finally realises that I'm talking to it.

Having to add a hosts entry for every machine is really overkill and not something that I really want to do. The machine may eventually be moving around semi regularly and adapting the hosts file for each new network would be too complex a task, as the networks it's likely to be connected to will have a similar issue owing to similar hardware providing DHCP and "DNS".

If the alternative is NetBIOS, bearing in mind that I know very little about BSD, I am using Samba3.5 - can I reinstall/modify the existing install of Samba to include NetBIOS support? Assuming this is what you meant when you suggested it may have NetBIOS support.


----------



## BAK (Mar 27, 2011)

Sorry for the double post, I don't seem to be able to edit my previous post - when I said "can I reinstall/modify" the Samba install, what I actually meant was "how would I go about reinstalling/modifying".


----------



## wblock@ (Mar 28, 2011)

BAK said:
			
		

> Ultimately the fact that external hostnames don't resolve isn't that important an issue - however the issue is that the machines OWN hostname doesn't resolve - so when trying to connect to Samba and by SSH there is an enormous delay before it finally realises that I'm talking to it.



What is the output of
`% hostname`

Whatever that is should have an entry in /etc/hosts.  For example:

```
::1  localhost  # only needed for IPv6
127.0.0.1  localhost
192.168.1.3 neon neon.my.domain.
```

That final dot could be helpful.


----------



## BAK (Mar 28, 2011)

The output of [CMD=]% hostname[/CMD] is "neon" (which is correct)

I added the final dot as suggested so my /etc/hosts now reads:

```
::1
127.0.0.1 localhost localhost
192.168.0.3 neon neon.
```
However this has not affected anything as far as I can tell.

I've been doing some reading and it looks like NetBIOS is the way I'll need to go in order to resolve this problem, however I am a little concerned still that the results of a [CMD=]% ping neon[/CMD] return a "Host name lookup failure" message without the explicit entry in /etc/hosts. Should this be a cause for concern?

A lot of the reading I've done regarding NetBIOS support in FreeBSD has been from forums/mailing lists and it's all relatively old - mentioning FreeBSD 4.x-6.x, but I gather that I will need Samba to handle NetBIOS requests via nmbd.

As I already have an existing install of Samba - is there a way to check which modules of Samba I have installed, or to modify which modules are installed? Or would I need to remove Samba entirely and reinstall?


----------



## JimW (Mar 28, 2011)

BAK said:
			
		

> Any help, even in direction of how to troubleshoot this further, would be greatly appreciated.



If you want to be able to resolve NETBIOS names for a local workgroup of Windows workstations, you might want to look into setting up your Samba Server to also act as a *WINS* server...

http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/NetworkBrowsing.html

If you set up your Samba server to act as the local master browser and WINS server, that should solve your name resolution problems with your local Windows workstations.

It's probably also a good idea to give your server a static ip address too.

Maybe you can post your /usr/local/etc/smb.conf file to give everyone a better idea on how you set up your Samba server.


----------



## BAK (Mar 28, 2011)

My issue is, I've set my machine up as a ZFS NAS/fileserver which will likely be taken to LAN parties. Configuring it with a static IP address, to be a local master browser and/or WINS server isn't really an option - it's essentially going to be a client only, in network services respects. I don't necessarily mind that it can't resolve other hostnames however I would like it to be able to resolve its own without a manual entry in /etc/hosts (because its IP can/will change depending on where it is).

smb.conf:

```
[global]
   workgroup = WORKGROUP
   server string = neon
   security = user
   
   guest account = nobody
   map to guest = bad password

   disable spoolss = yes
   load printers = no

   log file = /var/log/samba/log.%m
   log level = 3
   max log size = 50

[homes]
   comment = Home Directories
   browseable = no
   writable = yes

[share]
   path = /path/to/share
   comment = Comment 
   public = yes
   guest ok = yes
   writable = yes
   printable = no
   write list = bak
   create mask = 0775
   directory mask = 0775
```


----------

