# Name resolution

## acidreign

Belive it or not, i have found something that effects alot of desktop application speed, is name resolution. Adding your ip and hostname to your /etc/hosts can sometimes an application change from "sluggish" to smooth.

----------

## fghellar

This is a nice trick. I've made this post sticky.  :Smile: 

----------

## lk42pro

good thing i done it....  :Laughing: 

----------

## paulisdead

Would anybody happen to know how you're supposed to do this if you use DHCP?  If all the IPs on the LAN start with 10.0.0, should I put that into my hosts file?

*Edit*Nevermind I just figured it out, finally.  I should have just gone to google first.  Anyways, to set this up for DHCP, put this in your /etc/hosts file

source /etc/dhcpc/dhcpcd-eth0.info     #where eth0 is your nic

$IPADDR [hostname]

----------

## Jeevz

 *paulisdead wrote:*   

> Would anybody happen to know how you're supposed to do this if you use DHCP?  If all the IPs on the LAN start with 10.0.0, should I put that into my hosts file?
> 
> *Edit*Nevermind I just figured it out, finally.  I should have just gone to google first.  Anyways, to set this up for DHCP, put this in your /etc/hosts file
> 
> source /etc/dhcpc/dhcpcd-eth0.info     #where eth0 is your nic
> ...

 

Can also use your loop back IP address: 127.0.0.1

----------

## west

Doesn't X complain if you don't do it?

[edit: add 127.0.0.1 and hostname to /etc/hosts that is :]

(no, cant check, sitting on a [W-word]-box now ...   :Rolling Eyes: )

----------

## Curious

Oh yeah, this one got me on KDE3 for the first time - but remember you might also need to alter and or create /etc/host.conf ( I think ) so it says:

```
order hosts,bind
```

 This will tell it to search the hosts files before querying name servers ( which is probably the best way to do it. )

 And there I was wondering why my gateway was dialling everytime I started KDE.  :Razz: 

Bryn.

----------

## FINITE

Hmm, maybe this is my prob with kde. Will have to check it out. Thanx  :Very Happy: 

----------

## rlyacht

I am usng dhcp and it's working fine.  However my machine can't look itself up.  That is (machine is named tumnus), I can't ping tumnus.  This is causing me some trouble. Code that does gethostbyname fails.   I saw this post:

```
DHCP, put this in your /etc/hosts file

source /etc/dhcpc/dhcpcd-eth0.info #where eth0 is your nic

$IPADDR [hostname]

```

but it doesn't work for me, and seems to be inconsistent with the man page for /etc/hosts. It kinds of makes sense.  Are people literally using an /etc/hosts that looks like

```

127.0.0.1 localhost

source /etc/dhcpc/dhcpcd-eth0.info  

$IPADDR tumnus

```

----------

## acidreign

 *Curious wrote:*   

> Oh yeah, this one got me on KDE3 for the first time - but remember you might also need to alter and or create /etc/host.conf ( I think ) so it says:
> 
> ```
> order hosts,bind
> ```
> ...

 

Just a quick note, the order hosts, bind is no longer in use.(With the new glibc anyway)  It has been replaced by a more global settings file called /etc/nsswitch.conf.

It should contain the line.

```
 hosts:       files dns 
```

Which is the new standard for the glibc configuration.

----------

## acidreign

UNTICK THE BOX TO DISABLE BBCODE IN THIS POST.

----------

## Curious

 *acidreign wrote:*   

> 
> 
> Just a quick note, the order hosts, bind is no longer in use.(With the new glibc anyway)  It has been replaced by a more global settings file called /etc/nsswitch.conf.
> 
> 

 

 That's quite interesting... I have this file ( /etc/nsswitch.conf ), and it is configured as described - and yet name lookups were definitely causing dialups as the resolver tried to contact primary and secondary dns on 203.56.8.1 and 203.56.8.2 respectively.

 Very odd.  Very odd.

----------

## gsfgf

I can tell.

----------

## bakgwailo

What host name should I use with ATT Broad Band ? They wont give you one as its assigned by DHCPCD (I think...). I've tried everything as a host name and IP addy, but they all cause errors at boot (host name is invalid, etc.). Any suggestions? Also, if it matters, this comp is hooked up to a 4 port Belkin router. Thanks!

joe

----------

## betatim

having a look at the nsswitch.conf fiel i found this

```
networks:    files dns
```

what exactly is this??which fiels does it look at?or what does it try to fidn out ?? it isn't nameresolution but network resolution ???

----------

## arkane

 *betatim wrote:*   

> having a look at the nsswitch.conf fiel i found this
> 
> ```
> networks:    files dns
> ```
> ...

 

Whoa there Kimosabe... your about to have a coronary there....

that just tells in what order to do name resolution.  It's checking files first (/ec/resolv.conf, /etc/hosts) then it goes for DNS.

name and network resolution soemetimes go hand in hand.... it's all translation of a human name to a number system.

----------

## arkane

 *bakgwailo wrote:*   

> What host name should I use with ATT Broad Band ? They wont give you one as its assigned by DHCPCD (I think...). I've tried everything as a host name and IP addy, but they all cause errors at boot (host name is invalid, etc.). Any suggestions? Also, if it matters, this comp is hooked up to a 4 port Belkin router. Thanks!
> 
> joe

 

that you would have to ask them, but it honestly shouldn't matter.  I just made up one.

Mine is orioncomputing.com...

Where do you get errors?  is it when sendmail (or whatever) pops up, or what?

----------

## kraylus

ok, so now im confused...

since im using dhcp what file do i edit and what do i put in it?

so many people said different things  :Sad: 

ryan

----------

## sonicwave

I simply use: 127.0.0.1 <hostname>

And i am using DHCP all the time.. but as that IP is a loopback to your own computer it should do the trick.

----------

## johnnyb

1) Make sure /etc/hostname contains a single line with your complete hostname like this:

```
[hostname].[domain]
```

Example:

```
gladiator.exampledomain.com
```

(Yes, the domain name is part of your fully qualified hostname.)

2) Make sure /etc/hosts looks like this:

```
127.0.0.1     localhost [hostname].[domain] [hostname] 
```

Example:

```
127.0.0.1     localhost gladiator.exampledomain.com gladiator
```

2b) If you have a static IP, /etc/hosts should look like this:

```
127.0.0.1       localhost

##.##.##.##     [hostname].[domain] [hostname]
```

Example:

```
127.0.0.1       localhost

192.168.0.1     www.gentoo.org www
```

3) In /etc/nsswitch.conf there should be a line that says:

```
hosts: files dns
```

(This appears to be the default for a Gentoo system.)

----------

## csnyder

 *paulisdead wrote:*   

> Nevermind I just figured it out, finally.  I should have just gone to google first.  Anyways, to set this up for DHCP, put this in your /etc/hosts file
> 
> source /etc/dhcpc/dhcpcd-eth0.info     #where eth0 is your nic
> 
> $IPADDR [hostname]

 

Sorry, but that doesn't work - /etc/hosts is not a shell script.  Here's something I just figured out.  You have to modify your /etc/init.d/net.xxx files for this to work.  New code is the last three lines:

```

                /sbin/dhcpcd ${dhcp_args} ${IFACE} >/dev/null || {

                        retval=$?

                        eend ${retval} "Failed to bring ${IFACE} up"

                        return ${retval}

                }

                source /etc/dhcpc/dhcpcd-${IFACE}.info

                echo "127.0.0.1 localhost

${IPADDR} `hostname -s` `hostname`" > /etc/hosts

```

The new code started at line 42 for me.

Note: this wipes out your /etc/hosts file.  If you have any other hosts in this file, you should add them to this script as well.

Another note: If the DHCP client gets another IP without being restarted, this won't be taken into account.  There must be a better way to do this than this.  :Idea: 

----------

## hielvc

csnyder wrote:

         /sbin/dhcpcd ${dhcp_args} ${IFACE} >/dev/null || {

                        retval=$?

                        eend ${retval} "Failed to bring ${IFACE} up"

                        return ${retval}

                }

                source /etc/dhcpc/dhcpcd-${IFACE}.info

                echo "127.0.0.1 localhost

${IPADDR} `hostname -s` `hostname`" > /etc/hosts 

This didnt work for me. but his idea pointed the way. 

   code:

	/sbin/dhcpcd ${dhcp_args} ${IFACE} >/dev/null || {

			retval=$?

			eend ${retval} "Failed to bring ${IFACE} up"

			return ${retval}

		}

		source /etc/dhcpc/dhcpcd-eth0.info

		echo "127.0.0.1 localhost

	$IPADDR gentoo.$DOMAIN gentoo" > /etc/hosts

	cat /etc/resolv.conf >> /etc/hosts

Thisl yields a hosts file like this.

hosts:

127.0.0.1 localhost

	68.7.73.38 gentoo.sd.cox.net gentoo

nameserver 68.6.16.30

nameserver 68.2.16.30

nameserver 68.1.17.5

search sd.cox.net

One beni is my dns lookups are sure fast  :Laughing:  THe only prob is a Xserver

fragment that only shows up when running links in a xterm. Its about finding 'service host found in line 1  host.conf.

----------

## rommel

i added it to the 127.0.0.0 loop since i run dhcpcd but i wasnt having i dont think problems before...i cant really say i see any speed difference with my hostname added to hosts

----------

## csnyder

 *rommel wrote:*   

> i added it to the 127.0.0.0 loop since i run dhcpcd but i wasnt having i dont think problems before...i cant really say i see any speed difference with my hostname added to hosts

 

I don't notice a speed difference either.  My main reason for running this is that Apache won't start if it can't resolve its own hostname, and I want it to be able to start even if the nameserver is down.

----------

## hielvc

The speed increace Ive seen is that I rarely see "looking up URL", its quite often just "loading sight".. If you'er using cox.net this isnt correst yet in that your IP ex: 67.7.71.120  and domain: sd.cox.net and marry them as so

ip67-7-71-120sd.sd.cox.net. Im just learning bash scripting so im puzzeling how to parse this. It might actualy take 3 rewrites of 'hosts'to do this correctly. I'll it in the next wk.

hielvc

----------

## hielvc

Here is the script that works with dhcpc, at least at boot time & with cox.net. Youll have to put in your own cox city codes ex: sd > san diego.  I took out the pasting of resolv.conf but if you want it leave it in it shouldnt hurt or really help, sigh.

code:

/sbin/dhcpcd ${dhcp_args} ${IFACE} >/dev/null || {

			retval=$?

			eend ${retval} "Failed to bring ${IFACE} up"

			return ${retval}

		}

		source /etc/dhcpc/dhcpcd-eth0.info

                COXIP="${IPADDR//./-}"

			echo "127.0.0.1 localhost

	$IPADDR ip$COXIP.sd.$DOMAIN gentoo" > /etc/hosts

To see what your real ip looks like the only sight that I can remember that shows it to you is linuxpackages.net. There are more but I dont remeber where.

----------

## ebrostig

Hi all!

This problem is really easy to solve.

1. Make sure that dhcpcd is run with the  -D -H options

2. Add the following to /etc/init.d/net.eth0 at the end of the start() function:

  (echo -n `hostname -i`; echo -n "   "; hostname -f; echo "127.0.0.1 localhost" ) > /etc/hosts

Explanation:

echo -n => No newline at the end

`hostname -i` >= Return ip-address

hostname -f >= Return fully qualified domainname, i.e www.gentoo.org

The rest should be obvious....

Good Luck!   :Cool: 

Erik

----------

## rac

Rescued from the depths of Desktop Environments to Documentation, Tips & Tricks.

----------

## Mnemia

Interestingly, if I put the fully qualified hostname (ie host.domain.com) into /etc/hostname, the DHCP server denies me a DNS address mapping, but still gives me an IP address. In other words, it is not possible for me to ping or access the computer by hostname from any other host, but I can ping the IP. If, however, I put only the host part of the hostname in, the server works correctly.   Is this correct? Am I doing something wrong, or is the server misconfigured in some way (this is primarily a windows LAN).

----------

## iancurtis

So if you just have the loopback "127.0.0.1 localhost" in /etc/hosts your fine right? The threads havent been clear to me. I have RR cable service, and it uses DHCP.

----------

## choward

Another related tip that I found helped me greatly was making sure that nscd is running.  nscd stands for the name server caching daemon.  Once you look up a name in DNS it is cached for a certain amount of time locally so that DNS can be avoided later on.  This is great for loading several webpages from the same server as the DNS lookup is only done once.

nscd comes with glibc I believe.

----------

## riceboy50

An /etc/hosts file like this

```
127.0.0.1 localhost

<my static ip> <my hostname>.<my domain> <my hostname>

nameserver <my nameserver>

nameserver <my nameserver 2>

search <my domain>

```

An /etc/hostname file like this

```
<my hostname>.<my domain>

```

fixed the apache error "could not find fully qualified hostname, using 127.0.0.1 instead"

Thanks guys  :Smile: 

----------

## genneth

And for those who run their machines on windows networks (though which network admin would be so stupid (aside from my school's, obviously) as to run a college network on windows servers...), change your /etc/nsswitch.conf to have the following:

```

hosts:       files dns wins

networks:    files dns

```

And have samba installed, of course. This will enable WINS lookup so that all those myriad of insignificant windows machines will resolved.

----------

## BliZZZard

Just as a not to people trying this... I found the dhcpcd-eth0.info file NOT to be in /etc/dhcpc but in /var/lib/dhcpc/

```

source /var/lib/dhcpc/dhcpcd-eth0.info

$IPADDR [hostname]

```

Just a FYI...  :Razz: 

----------

