# [/etc/hosts] user can't resolve entries in the file (SOLVED)

## nandelbosc

I have written in the spanish forum without results...

In my home I have a LAN with some computers, now I interested in two: my PC (192.168.10.22) and a web server (192.168.10.1)

As you can see, i have a line for resolve the www.tryme.com domain, pointing to my webserver:

```

# cat /etc/hosts

127.0.0.1       michael.loft    michael localhost

::1     localhost

192.168.10.1 www.tryme.com

```

If i send a ping packet as root:

```

michael marc # ping www.tryme.com

PING www.tryme.com (192.168.10.1) 56(84) bytes of data.

64 bytes from www.tryme.com (192.168.10.1): icmp_seq=1 ttl=64 time=0.104 ms

64 bytes from www.tryme.com (192.168.10.1): icmp_seq=2 ttl=64 time=0.085 ms

64 bytes from www.tryme.com (192.168.10.1): icmp_seq=3 ttl=64 time=0.082 ms

--- www.tryme.com ping statistics ---

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

rtt min/avg/max/mdev = 0.082/0.090/0.104/0.012 ms

```

All it's ok!

But if I try the same as another user:

```

marc@michael ~ $ ping www.tryme.com

PING www.tryme.com (213.97.38.xxx) 56(84) bytes of data.

64 bytes from xxx.Red-213-97-38.staticIP.rima-tde.net (213.97.38.xxx): icmp_seq=1 ttl=63 time=1.57 ms

64 bytes from xxx.Red-213-97-38.staticIP.rima-tde.net (213.97.38.xxx): icmp_seq=2 ttl=63 time=1.53 ms

--- www.tryme.com ping statistics ---

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

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

```

It resolve my public IP address. What's happens?

First I think I have not permisions to use /etc/hosts, I change it to 755, without results...

```

marc@michael ~ $ ls -l /etc/hosts

-rwxr-xr-x 1 root root 398  2 mar 22:23 /etc/hosts

```

Later, I think in another possibility, the user marc have some problem, therefore try with another user:

 *Quote:*   

> 
> 
> rosa@michael /home/marc $ ping www.tryme.com
> 
> PING www.tryme.com (213.97.38.xxx) 56(84) bytes of data.
> ...

 

The same!

Somebody have ideas?

Thank's gurus!Last edited by nandelbosc on Sun Mar 04, 2007 11:24 pm; edited 1 time in total

----------

## PaulBredbury

I suppose we'd need to see the contents of:

/etc/host.conf

/etc/resolv.conf

----------

## nandelbosc

```
marc@michael ~ $ cat /etc/host.conf

# /etc/host.conf:

# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/host.conf,v 1.1 2006/09/29 23:52:23 vapier Exp $

# The  file /etc/host.conf contains configuration information specific to

# the resolver library.  It should contain one configuration keyword  per

# line,  followed by appropriate configuration information.  The keywords

# recognized are order, trim, mdns, multi, nospoof, spoof, and reorder.

# This keyword specifies how host lookups are to be performed. It

# should be followed by one or more lookup methods, separated by

# commas.  Valid methods are bind, hosts, and nis.

#

order hosts, bind

# Valid  values are on and off.  If set to on, the resolv+ library

# will return all valid addresses for a host that appears  in  the

# /etc/hosts  file,  instead  of  only  the first.  This is off by

# default, as it may cause a substantial performance loss at sites

# with large hosts files.

#

multi off

marc@michael ~ $ cat /etc/resolv.conf

# Generated by dhcpcd for interface eth1

search loft

nameserver 80.58.32.97

nameserver 194.224.52.36
```

Thank's!

----------

## jmbsvicetto

Hi.

Please run with your user strace ping www.tryme.com.

Also post the contents of /etc/nsswitch.conf.

----------

## nandelbosc

```
michael marc # cat /etc/nsswitch.conf

# /etc/nsswitch.conf:

# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/nsswitch.conf,v 1.1 2006/09/29 23:52:23 vapier Exp $

passwd:      compat

shadow:      compat

group:       compat

# passwd:    db files nis

# shadow:    db files nis

# group:     db files nis

hosts:       files dns

networks:    files dns

services:    files

protocols:   files

rpc:         files

ethers:      files

netmasks:    files

netgroup:    files

bootparams:  files

automount:   files

aliases:     files
```

```
marc@michael ~ $ strace ping www.tryme.com

execve("/bin/ping", ["ping", "www.tryme.com"], [/* 58 vars */]) = 0

brk(0)                                  = 0x8063000

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7eea000

access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY)      = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=102197, ...}) = 0

mmap2(NULL, 102197, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ed1000

close(3)                                = 0

open("/lib/libresolv.so.2", O_RDONLY)   = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 $\0\000"..., 512) = 512

fstat64(3, {st_mode=S_IFREG|0755, st_size=59932, ...}) = 0

mmap2(NULL, 71880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7ebf000

mmap2(0xb7ecd000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xd) = 0xb7ecd000

mmap2(0xb7ecf000, 6344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ecf000

close(3)                                = 0

open("/lib/libc.so.6", O_RDONLY)        = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0F^\1\000"..., 512) = 512

fstat64(3, {st_mode=S_IFREG|0755, st_size=1172580, ...}) = 0

mmap2(NULL, 1136144, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7da9000

mmap2(0xb7eb9000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x110) = 0xb7eb9000

mmap2(0xb7ebc000, 9744, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7ebc000

close(3)                                = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7da8000

set_thread_area({entry_number:-1 -> 6, base_addr:0xb7da86c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0

mprotect(0xb7eb9000, 4096, PROT_READ)   = 0

mprotect(0xb7f06000, 4096, PROT_READ)   = 0

munmap(0xb7ed1000, 102197)              = 0

socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = -1 EPERM (Operation not permitted)

getuid32()                              = 1000

setuid32(1000)                          = 0

brk(0)                                  = 0x8063000

brk(0x8084000)                          = 0x8084000

getpid()                                = 24529

open("/etc/resolv.conf", O_RDONLY)      = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=101, ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ee9000

read(3, "# Generated by dhcpcd for interf"..., 4096) = 101

read(3, "", 4096)                       = 0

close(3)                                = 0

munmap(0xb7ee9000, 4096)                = 0

socket(PF_FILE, SOCK_STREAM, 0)         = 3

fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)

fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0

connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)

close(3)                                = 0

socket(PF_FILE, SOCK_STREAM, 0)         = 3

fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)

fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0

connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)

close(3)                                = 0

open("/etc/nsswitch.conf", O_RDONLY)    = -1 EACCES (Permission denied)

open("/etc/ld.so.cache", O_RDONLY)      = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=102197, ...}) = 0

mmap2(NULL, 102197, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7ed1000

close(3)                                = 0

open("/lib/libnss_dns.so.2", O_RDONLY)  = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300\r\0"..., 512) = 512

fstat64(3, {st_mode=S_IFREG|0755, st_size=18096, ...}) = 0

mmap2(NULL, 20612, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7da2000

mmap2(0xb7da6000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0xb7da6000

close(3)                                = 0

munmap(0xb7ed1000, 102197)              = 0

open("/etc/host.conf", O_RDONLY)        = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=936, ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ee9000

read(3, "# /etc/host.conf:\n# $Header: /va"..., 4096) = 936

read(3, "", 4096)                       = 0

close(3)                                = 0

munmap(0xb7ee9000, 4096)                = 0

socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3

connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("80.58.32.97")}, 28) = 0

fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)

fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0

gettimeofday({1172966900, 558251}, NULL) = 0

poll([{fd=3, events=POLLOUT, revents=POLLOUT}], 1, 0) = 1

send(3, "\225\373\1\0\0\1\0\0\0\0\0\0\3www\ttryme\3com\0\0"..., 35, MSG_NOSIGNAL) = 35

poll([{fd=3, events=POLLIN, revents=POLLIN}], 1, 5000) = 1

ioctl(3, FIONREAD, [51])                = 0

recvfrom(3, "\225\373\201\200\0\1\0\1\0\0\0\0\3www\ttryme\3com\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("80.58.32.97")}, [16]) = 51

close(3)                                = 0

socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3

connect(3, {sa_family=AF_INET, sin_port=htons(1025), sin_addr=inet_addr("213.97.38.xxx")}, 16) = 0

getsockname(3, {sa_family=AF_INET, sin_port=htons(32878), sin_addr=inet_addr("192.168.10.22")}, [16]) = 0

close(3)                                = 0

dup(2)                                  = 3

fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)

fstat64(3, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7ee9000

_llseek(3, 0, 0xbffd21b8, SEEK_CUR)     = -1 ESPIPE (Illegal seek)

write(3, "ping: icmp open socket: Operatio"..., 48ping: icmp open socket: Operation not permitted

) = 48

close(3)                                = 0

munmap(0xb7ee9000, 4096)                = 0

exit_group(2)                           = ?

Process 24529 detached

```

----------

## jmbsvicetto

Run as your user getent ahosts.

From the strace, it seems like glibc is not looking at /etc/hosts.

----------

## nandelbosc

```
marc@michael ~ $ getent ahosts

127.0.0.1       michael.loft    michael localhost

::1     localhost

192.168.10.1 www.tryme.com

```

```

marc@michael ~ $ ping www.tryme.com

PING www.tryme.com (213.97.38.xxx) 56(84) bytes of data.

64 bytes from xxx.Red-213-97-38.staticIP.rima-tde.net (213.97.38.xxx): icmp_seq=1 ttl=63 time=1.57 ms

64 bytes from xxx.Red-213-97-38.staticIP.rima-tde.net (213.97.38.xxx): icmp_seq=2 ttl=63 time=1.53 ms

--- www.tryme.com ping statistics ---

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

rtt min/avg/max/mdev = 1.577/1.577/1.577/0.000 ms 
```

How can I solve this?

----------

## nandelbosc

SOLVED RE-EMERGING glibc

I see some differences in /etc/nsswitch.conf ...

New file:

```
services:    db files

protocols:   db files

rpc:         db files

ethers:      db files

```

Old file:

```
services:    files

protocols:   files

rpc:         files

ethers:      files

```

----------

## Hu

 *nandelbosc wrote:*   

> SOLVED RE-EMERGING glibc

 

For the record, that was probably overkill.  From looking at your strace output, I noticed

```
open("/etc/nsswitch.conf", O_RDONLY)    = -1 EACCES (Permission denied)
```

That is, marc did not have permission to open /etc/nsswitch.conf.  Most likely, this led to glibc falling back on built-in defaults.  According to the manpage, the default for hosts is:

```
hosts:          dns [!UNAVAIL=return] files
```

You probably fixed the file permissions when updating configuration files after the glibc reinstall.  However, making nsswitch.conf owner:group=root:root mode=644 should have worked just as well.  :Smile: 

----------

