# /etc/hosts broken

## Moriah

I have installed this system twice this week, and each time, the resolver behaves in a broken way.  It can resolve domain names via lookup thru an external name server, but it gets all confused looking up names in /etc/hosts  :Question: 

First, some background:

```
ezekiel ~ # uname -a

Linux ezekiel.elilabs.com 2.6.12-gentoo-r6 #1 Wed Jul 27 15:51:38 CDT 2005 i686 AMD Athlon(tm)  AuthenticAMD GNU/Linux

ezekiel ~ # 
```

```
ezekiel ~ # cat /etc/resolv.conf 

domain elilabs.com

nameserver 198.147.221.34

nameserver 192.107.41.34

nameserver 216.68.4.10

ezekiel ~ # 
```

```
ezekiel ~ # cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1       localhost.localdomain   localhost

# static ip addresses on lan -- 192.168.1.0/24

#

192.168.1.1             aaron           aaron.elilabs.com

192.168.1.2             elisha          elisha.elilabs.com

192.168.1.3             ezra            ezra.elilabs.com

192.168.1.4             gabriel         gabriel.elilabs.com

192.168.1.5             lp              lp.elilabs.com

192.168.1.6             abraham         abraham.elilabs.com

192.168.1.7             ruth            ruth.elilabs.com

192.168.1.8             shaphan         shaphan.elilabs.com

192.168.1.9             samuel          samuel.elilabs.com

192.168.1.11            daniel          daniel.elilabs.com

192.168.1.13            ezekiel         ezekiel.elilabs.com

### temporary addresses

#

192.168.1.50            neweli          neweli.elilabs.com

# static ip addresses on dmz -- 192.168.2.0/24

#

192.168.2.1             nehemiah        nehemiah.elilabs.com

#192.168.2.10           urim            urim.elilabs.com

192.168.1.102           urim            urim.elilabs.com

#192.168.2.11           thummim         thummim.elilabs.com

192.168.1.101           thummim         thummim.elilabs.com

192.168.2.13            eli             eli.elilabs.com         www.elilabs.com         elilabs.com

#192.168.1.101          eli             eli.elilabs.com         www.elilabs.com         elilabs.com

# static ip addresses allocated by xnet

#

# our cidr block: 205.243.154.192/28 & 204.248.49.62

#

# xnet servers

#

198.147.221.34          ns1.xnet.com            # nameserver

198.147.221.35          ns2.xnet.com            # nameserver

198.147.221.66          typhoon.xnet.com        # shell

198.147.221.37          flood.xnet.com          # news

# static ip addresses allocated by zoomtown

# 

# zoomtown servers

#

216.68.4.10             ns1.zoomtown.com

216.68.5.10             ns2.zoomtown.com

#

# our gateway

#

10.251.36.120           dsl                     dsl.elilabs.com

10.251.36.1             dslam                   dslam.elilabs.zoomtown.com

216.68.54.75            dhcp                    dhcp.elilabs.zoomtown.com

# static ip addresses allocated by iglou

#

64.253.104.156          eli01.cindsl01.iglou.com        # tunnel ppp0 on nehemiah

204.255.233.225         lanadvantage-01.iglou.com       # lac (tunnel server)

64.253.104.1            cindsl01-2.iglou.com            # our gateway to the internet via iglou

#

192.107.41.34           dns1.iglou.com

192.107.41.21           dns2.iglou.com

192.107.41.38           shellaccess.com

#

# our cidr block: 64.253.103.8/29

#

# 64.253.103.8          network

# 64.253.103.9          spare1.elilabs.com

# 64.253.103.10         urim.elilabs.com        ns1.elilabs.com

# 64.253.103.11         thummim.elilabs.com     ns2.elilabs.com

# 64.253.103.12         spare2.elilabs.com

# 64.253.103.13         www.elilabs.com         eli.elilabs.com         elilabs.com

# 64.253.103.14         spare3.elilabs.com

# 64.253.103.15         broadcast

# disable annoying delays on drudge site

127.0.0.2       code.fastclick.net

127.0.0.3       a.tribalfusion.com

127.0.0.4       servedby.advertising.com

127.0.0.5       cserver.mii.instacontent.com

127.0.0.6       media.fastclick.net

ezekiel ~ # 
```

Now some examples of good behavior:

```
ezekiel ~ # ping localhost

PING localhost (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.061 ms

64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.023 ms

--- localhost ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1000ms

rtt min/avg/max/mdev = 0.023/0.042/0.061/0.019 ms

ezekiel ~ # ping ftp.uu.net

PING ftp.uu.net (192.48.96.9) 56(84) bytes of data.

64 bytes from ftp.UU.NET (192.48.96.9): icmp_seq=1 ttl=244 time=102 ms

64 bytes from ftp.UU.NET (192.48.96.9): icmp_seq=2 ttl=244 time=121 ms

64 bytes from ftp.UU.NET (192.48.96.9): icmp_seq=3 ttl=244 time=113 ms

--- ftp.uu.net ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 102.145/112.576/121.962/8.123 ms

ezekiel ~ # ping forums.gentoo.org

PING forums.gentoo.org (140.211.166.170) 56(84) bytes of data.

64 bytes from dove.gentoo.osuosl.org (140.211.166.170): icmp_seq=1 ttl=49 time=155 ms

64 bytes from dove.gentoo.osuosl.org (140.211.166.170): icmp_seq=2 ttl=49 time=152 ms

--- forums.gentoo.org ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 152.407/154.113/155.819/1.706 ms

ezekiel ~ # 
```

Now some examples of bad behavior:

```
ezekiel ~ # ping ezekiel

ping: unknown host ezekiel

ezekiel ~ # ping elisha

ping: unknown host elisha

ezekiel ~ # ping ezra

PING elilabs.com (64.253.103.13) 56(84) bytes of data.

64 bytes from elijah-5.iglou.com (64.253.103.13): icmp_seq=1 ttl=63 time=2.06 ms

--- elilabs.com ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 2.066/2.066/2.066/0.000 ms

ezekiel ~ # ping eli

PING elilabs.com (64.253.103.13) 56(84) bytes of data.

64 bytes from elijah-5.iglou.com (64.253.103.13): icmp_seq=1 ttl=63 time=1.72 ms

--- elilabs.com ping statistics ---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

rtt min/avg/max/mdev = 1.720/1.720/1.720/0.000 ms

ezekiel ~ # 
```

Notice that ezekiel cannot even resolve its own name.  It resolves ezra to the wrong ip address -- the same one it correctly resolves eli to.  

I have fiddled with this until my patience is exhausted.  I have posted for help before, but it took a while to really characterize the total symptom set.  At one time, it would not resolve localhost.

After I noticed this weird behaviour on the part of the resolver, I decided that maybe an ebuild was temporarily screwed up, so I reinstalled the system last night and this morning.  The new installation produces the same symptoms.

BTW The /etc/hosts and /etc/resolv.conf files were copied from a system that works.

HELP  :Evil or Very Mad: 

----------

## cyrillic

Have you tried putting the FQDN before the hostname ?

Like this

```
127.0.0.1       localhost.localdomain   localhost 
```

Instead of this

```
192.168.1.13            ezekiel         ezekiel.elilabs.com 
```

----------

## ONEEYEMAN

Hi, Moriah,

What is you subnet mask? Is it 255.255.255.0? Or 255.255.0.0?

Also what is the output of the "ifconfig eth0"?

Thank you.

----------

## Moriah

Regarding the subnetmask:

```
ezekiel ~ # ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0D:61:51:E5:87  

          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1

          RX packets:29488 errors:0 dropped:0 overruns:0 frame:0

          TX packets:13183 errors:0 dropped:0 overruns:0 carrier:0

          collisions:2 txqueuelen:1000 

          RX bytes:5731304 (5.4 Mb)  TX bytes:2759344 (2.6 Mb)

          Interrupt:11 Base address:0xb800 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:14 errors:0 dropped:0 overruns:0 frame:0

          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:1176 (1.1 Kb)  TX bytes:1176 (1.1 Kb)

ezekiel ~ # 
```

Regarding reversing the order of the FDQN names and the bare ones, all I can say is that the same /etc/hosts file works on several -- albiet older -- systems.  Did they change something recently that reverses the ordering?

----------

## ONEEYEMAN

I think that cyrillic is correct.

That's the correct order of the things.

Thank you.

----------

## Moriah

Well, I just reversed the order, and it made no difference in the symptoms.

----------

## cyrillic

 *Moriah wrote:*   

> Regarding reversing the order of the FDQN names and the bare ones, all I can say is that the same /etc/hosts file works on several -- albiet older -- systems.  Did they change something recently that reverses the ordering?

 

I don't mess with domains on my own lan, but I read somewhere that the order was significant, and the bare hostname should go last.

ps. I use net-dns/dnsmasq for local DNS and DHCP.  I would think with a setup as complicated as yours, something like this would make life easier than having a huge /etc/hosts file.

----------

## Moriah

Well, I have been doing it this way for the last 10 years or so, and it worked fine until very recently.  In fact, it still does work on most of the systems; its just the new ones (Ihave several with the same problem that were supposed to be "upgrades") that are messed up.  Something has definately changed in the domain name resolver, and it sure looks broken to me.

----------

## ONEEYEMAN

How do you connecting to the network? Are you using the router, hub or...?

You mentioned that you have other Gentoo boxes thatworks fine. Are they connected to the same network. Can you "ping" from the working PC the ezekiel? Can you ping it by IP address?

Thank you.

----------

## gentoo_dude

I would also check that the kernel routes correctly the network

post your 

```
 route 
```

 output

----------

## Moriah

Here it is:

```
ezekiel ~ # route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

127.0.0.0       localhost       255.0.0.0       UG    0      0        0 lo

default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

ezekiel ~ # 
```

I seem to have determined that the poor system doesn't know its own dnsdomainname, as seen here:

```
ezekiel ~ # dnsdomainname

dnsdomainname: Unknown host

ezekiel ~ # 
```

So I am beginning to think that this may be at the root of the problem.  

Recently, the use of /etc/hostname and /etc/dnsdomainname has been depricated in preference for /etc/conf.d/hostname and /etc/conf.d/domainname and as far as I can tell, that was the beginning of sorrows.   :Crying or Very sad: 

Just for the record, here is what is enabled with rc-update:

```
ezekiel ~ # rc-update show

            bootmisc | boot                          

             checkfs | boot                          

           checkroot | boot                          

               clock | boot                          

         consolefont | boot                          

          domainname |      default                  

                 gpm |                               

              hdparm |                               

            hostname | boot                          

             keymaps | boot                          

               local |      default nonetwork        

          localmount | boot                          

             modules | boot                          

            net.eth0 |      default                  

              net.lo | boot                          

            netmount |      default                  

                nscd |                               

             numlock |                               

           rmnologin | boot                          

              rsyncd |                               

                sshd |      default                  

           syslog-ng |      default                  

             urandom | boot                          

          vixie-cron |      default                  

ezekiel ~ # 
```

I just can't believe that I am the only person who has seen this.  Surely there must be others...

----------

## Moriah

In reply to ONEEYEMAN, who said: *Quote:*   

> How do you connecting to the network? Are you using the router, hub or...?
> 
> You mentioned that you have other Gentoo boxes thatworks fine. Are they connected to the same network. Can you "ping" from the working PC the ezekiel? Can you ping it by IP address? 

 You may see how I connect to the network from the diagram at http://www.elilabs.com/elilabs_network.html but to make it short, it is a classic dual firewall with a dmz setup.  

I get my connecttion from a cable modem which is in bridge mode and the gateway firewall (running iptables and l2tpd) gets a dynamic ip address from the cable provider's dhcp server.  It then uses this address to connect to an L2TP LAC and builds an L2TP tunnel to an ISP that provides me with my CIDR block of static ip addresses for the servers on the dmz.  The dmz is static natted by the firewall so that only the firewall's iptables configuration file needs to change if any of the server addresses change.  

Also on the dmz is the choke firewall, which is masqueraded behind the gateway firewall to be invisible from the internet.  The choke firewall performs a second level of masquerading for the workstations etc. on the lan.

This whole setup works beautifully, except for these 4 new machines, which are all experiencing the same goofy problem; therefore, I know it is not the connection to the internet.

All the machines acting badly are behind the choke firewall.  All the other machines working properly are either on the lan, the dmz, or they are one of the two firewalls.

I can ping any of the sick systems from any machine using a numerical ip address, and I can ping from any of the sick boxes to anywhere using a numerical ip address,  It is not a network problem; it is a resolver problem.  Addresses that are resolved by a true domain name server query work correctly on the sick boxes.  It is only addresses in the /etc/hosts file that are messed up.

As I posted above, the sick machines do not know what their domain name is.   :Surprised: 

----------

## dr_walm

I hade the same problem but solved it with creating 

```
/etc/nsswitch.conf
```

and add

```
hosts: files dns
```

----------

## jmbsvicetto

Hi.

In case you're missing the /etc/nsswitch.conf file, here is mine

```
atl64 linux # cat /etc/nsswitch.conf

# /etc/nsswitch.conf:

# $Header: /var/cvsroot/gentoo-x86/sys-libs/glibc/files/nsswitch.conf,v 1.1 2005/05/17 00:52:41 vapier Exp $

passwd:      compat

shadow:      compat

group:       compat

hosts:       files dns

networks:    files dns

services:    db files

protocols:   db files

rpc:         db files

ethers:      db files

netmasks:    files

netgroup:    files

bootparams:  files

automount:   files

aliases:     files

atl64 linux #
```

By the way, the /etc/nsswitch.conf file belongs to the glibc package.

```
atl64 linux # equery belongs /etc/nsswitch.conf

[ Searching for file(s) /etc/nsswitch.conf in *... ]

sys-libs/glibc-2.3.5 (/etc/nsswitch.conf)

atl64 linux # 
```

----------

## MickKi

Hi Moriah,

Not sure if this helps, but since you are referring to recent changes . . . the /etc/hostname and /etc/dnsdomainname files have been replaced by /etc/conf.d/hostname and /etc/conf.d/domainname, after baselayout-1.11.12-r4.  You'll need to rename/move/delete the old files after you have made the appropriate entries in the new ../conf.d/ equivalents.

----------

## vthokiestm

I'm having the same problem. I just upgraded my system and I can no longer resolve any name in /etc/hosts.

It's like /etc/hosts is being completely ignored.

Updating /etc/nsswitch didn't help either.

----------

## TreeFree

I just did a fresh install and found out I was infact missing /etc/nsswitch.conf file too which was not allowing localhost to be resolved.  I created the file and copied in the contents that jorge posted and I'm back in business.  Thanks!!  :Very Happy: 

----------

## jmbsvicetto

Glad to help.

----------

## tosk

I also was having this problem and the nsswitch.conf solution solved the problem.

----------

## gmtl3

For what it's worth.  I was having a similar problem, with "search" and "domain" statement conflicts in /etc/resolv.conf preventing non-FQND entries for local domain to not get resolved for things like ping/ssh/etc.  Simply making sure the "domain" statement was above the "search" statement fixed it.

Hope this helps someone else.

----------

## Maedhros

Moved from Installing Gentoo to Networking & Security.

----------

## Larde

 *gmtl3 wrote:*   

> [...]  I was having a similar problem, with "search" and "domain" statement conflicts in /etc/resolv.conf[...] Simply making sure the "domain" statement was above the "search" statement fixed it.
> 
> Hope this helps someone else.

 

Well, what you wanted to say is: Use either the "search" or the "domain" statement. There can only be one...  :Smile: 

Or as the manpage calls it:

```

   The  domain  and search keywords are mutually exclusive.  If more than one instance of these keywords

   is present, the last instance wins.

```

Or, as a better, non-gentoo manpage calls it:

```

   A search entry defines the list of domains to search when resolving a name. Only one domain 

   entry or search entry can be used. If the domain entry is used, the default search list is 

   the default domain. A search entry should be used when a search list other than the default 

   is required. The entry is of the form:

   search DomainName ...

   The search entry can have up to a maximum of 1024 characater strings for the DomainName variable. 

   The first DomainName variable is interpreted as the default domain name. 

   The domain entry and search entry are mutually exclusive. If both entries are used, the one that

   appears last will override the other.

```

Just to be nitpicking...  :Wink: 

Yours,

Larde

----------

## mfairchi

I was having basicly the same probelm.

somehow /etc/nsswitch.conf had

hosts:       files wins

I changed it to

hosts:       files dns

now everything works fine

 :Smile: 

thanks,

Michael

----------

## vthokiestm

Finally figured this out. Users couldn't read /etc/nsswitch.conf.

I fixed my machine with...

```
chmod 644 /etc/nsswitch.conf
```

...and everything is working now!!!

----------

