# [solved] /etc/hosts ignored

## grooveman

Hi,

Strange issue here.  I am trying to override a DNS host mapping by putting an entry in my hosts file.

i.e. the dns mapping for my.host.com = 133.133.133.133 (registered say, at godady)

I don't want certain machines to go to that IP for my.host.com, so I enter this into my /etc/hosts:

```
my.host.com 192.168.0.53
```

I ping or dig my.host.com, and the DNS address is the address that is consistently resolved (133.133.133.133).  Not good.

Here is my /etc/host.conf file:

```

order hosts, bind

multi on

```

Here is my resolv.conf

```
# Generated by dhcpcd from br0

# /etc/resolv.conf.head can replace this line

search mydom.com

nameserver 10.99.99.1

nameserver 133.133.133.138

# /etc/resolv.conf.tail can replace this line
```

I removed the "search" directive in case it was interfering, but it made no difference.

I am not running a local instance of bind or djbdns -- or caching dns information in any way.

I have been using hosts files for many years, but have not run into anything like this.  Is this a bug?  Or am I missing something here?

Thanks for the help.

G

----------

## Hu

 *grooveman wrote:*   

> I ping or dig my.host.com, and the DNS address is the address that is consistently resolved (133.133.133.133).  Not good.

 Using dig is not a good test.  It is specifically meant to retrieve DNS records, so it ignores entries in /etc/hosts.  However, ping should do the right thing.  What does dev-util/strace show with regard to how the name is resolved?

----------

## grooveman

hmm... I don't see anything really crazy, except that it doesn't bother to look at /etc/hosts until fairly late in the game... and I'm not sure what this line is all about: "write(3, "ping: icmp open socket: Operatio"..., 48ping: icmp open socket: Operation not permitted "....

```
strace ping my.host.com 

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

brk(0)                                  = 0x2541000                        

fcntl(0, F_GETFD)                       = 0                                

fcntl(1, F_GETFD)                       = 0                                

fcntl(2, F_GETFD)                       = 0                                

access("/etc/suid-debug", F_OK)         = -1 ENOENT (No such file or directory)

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e5000

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e4000

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

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

fstat(3, {st_mode=S_IFREG|0644, st_size=199490, ...}) = 0                                

mmap(NULL, 199490, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f283f0b3000                        

close(3)                                = 0                                              

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

read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3408\0\0\0\0\0\0"..., 832) = 832 

fstat(3, {st_mode=S_IFREG|0755, st_size=84624, ...}) = 0                                 

mmap(NULL, 2189960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f283ecb3000

mprotect(0x7f283ecc6000, 2097152, PROT_NONE) = 0                                          

mmap(0x7f283eec6000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13000) = 0x7f283eec6000

mmap(0x7f283eec8000, 6792, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f283eec8000     

close(3)                                = 0                                                                       

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

read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\353\1\0\0\0\0\0"..., 832) = 832                          

fstat(3, {st_mode=S_IFREG|0755, st_size=1399984, ...}) = 0                                                        

mmap(NULL, 3508264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f283e95a000                        

mprotect(0x7f283eaa9000, 2097152, PROT_NONE) = 0                                                                  

mmap(0x7f283eca9000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14f000) = 0x7f283eca9000

mmap(0x7f283ecae000, 18472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f283ecae000      

close(3)                                = 0                                                                         

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0b2000                           

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0b1000                           

arch_prctl(ARCH_SET_FS, 0x7f283f0b16f0) = 0                                                                         

mprotect(0x7f283eca9000, 16384, PROT_READ) = 0                                                                      

mprotect(0x7f283eec6000, 4096, PROT_READ) = 0                                                                       

mprotect(0x607000, 4096, PROT_READ)     = 0                                                                         

mprotect(0x7f283f0e6000, 4096, PROT_READ) = 0                                                                       

munmap(0x7f283f0b3000, 199490)          = 0                                                                         

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

getuid()                                = 1000                                                                      

setuid(1000)                            = 0                                                                         

brk(0)                                  = 0x2541000                                                                 

brk(0x2562000)                          = 0x2562000                                                                 

getpid()                                = 9770                                                                      

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

fstat(3, {st_mode=S_IFREG|0644, st_size=191, ...}) = 0                                                              

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000                           

read(3, "# Generated by dhcpcd from br0\n#"..., 4096) = 191                                                         

read(3, "", 4096)                       = 0                                                                         

close(3)                                = 0                                                                         

munmap(0x7f283f0e3000, 4096)            = 0                                                                         

stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=191, ...}) = 0                                              

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

fstat(3, {st_mode=S_IFREG|0644, st_size=191, ...}) = 0                                                              

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000                           

read(3, "# Generated by dhcpcd from br0\n#"..., 4096) = 191                                                         

read(3, "", 4096)                       = 0                                                                         

close(3)                                = 0                                                                         

munmap(0x7f283f0e3000, 4096)            = 0                                                                         

socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3                                                      

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|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3                                                      

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)    = 3                                                                         

fstat(3, {st_mode=S_IFREG|0644, st_size=508, ...}) = 0                                                              

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000                           

read(3, "# /etc/nsswitch.conf:\n# $Header:"..., 4096) = 508                                                         

read(3, "", 4096)                       = 0                                                                         

close(3)                                = 0                                                                         

munmap(0x7f283f0e3000, 4096)            = 0                                                                         

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

fstat(3, {st_mode=S_IFREG|0644, st_size=199490, ...}) = 0

mmap(NULL, 199490, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f283f0b3000

close(3)                                = 0

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

read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200!\0\0\0\0\0\0"..., 832) = 832

fstat(3, {st_mode=S_IFREG|0755, st_size=51528, ...}) = 0

mmap(NULL, 2147728, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f283e74d000

mprotect(0x7f283e758000, 2097152, PROT_NONE) = 0

mmap(0x7f283e958000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xb000) = 0x7f283e958000

close(3)                                = 0

mprotect(0x7f283e958000, 4096, PROT_READ) = 0

munmap(0x7f283f0b3000, 199490)          = 0

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

fstat(3, {st_mode=S_IFREG|0644, st_size=935, ...}) = 0

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000

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

read(3, "", 4096)                       = 0

close(3)                                = 0

munmap(0x7f283f0e3000, 4096)            = 0

open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3

fcntl(3, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)

fstat(3, {st_mode=S_IFREG|0644, st_size=1095, ...}) = 0

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000

read(3, "# /etc/hosts: Local Host Databas"..., 4096) = 1095

read(3, "", 4096)                       = 0

close(3)                                = 0

munmap(0x7f283f0e3000, 4096)            = 0

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

fstat(3, {st_mode=S_IFREG|0644, st_size=199490, ...}) = 0

mmap(NULL, 199490, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f283f0b3000

close(3)                                = 0

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

read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \20\0\0\0\0\0\0"..., 832) = 832

fstat(3, {st_mode=S_IFREG|0755, st_size=22744, ...}) = 0

mmap(NULL, 2117888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f283e547000

mprotect(0x7f283e54c000, 2093056, PROT_NONE) = 0

mmap(0x7f283e74b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0x7f283e74b000

close(3)                                = 0

mprotect(0x7f283e74b000, 4096, PROT_READ) = 0

munmap(0x7f283f0b3000, 199490)          = 0

socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3

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

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

sendto(3, "1\245\1\0\0\1\0\0\0\0\0\0\10datersed\10host\3c"..., 39, MSG_NOSIGNAL, NULL, 0) = 39

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

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

recvfrom(3, "1\245\201\200\0\1\0\1\0\0\0\0\10datersed\10host\3c"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("10.99.99.1")}, [16]) = 55

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("72.245.233.171")}, 16) = 0

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

close(3)                                = 0

dup(2)                                  = 3

fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)

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

mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f283f0e3000

lseek(3, 0, 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(0x7f283f0e3000, 4096)            = 0

exit_group(2)                           = ?

```

----------

## krinn

 *grooveman wrote:*   

> 
> 
> I don't want certain machines to go to that IP for my.host.com, so I enter this into my /etc/hosts:
> 
> ```
> ...

 

 :Very Happy: 

try like this instead

```
192.168.0.53 my.host.com

```

edit: i'm just Hu's solver bot, thanks him

----------

## Hu

 *grooveman wrote:*   

> I'm not sure what this line is all about: "write(3, "ping: icmp open socket: Operatio"..., 48ping: icmp open socket: Operation not permitted "....

 This is normal.  When a program is run under strace, the setuid bit is not respected, so ping lacked the capability to prepare a raw socket.

----------

## grooveman

 *Quote:*   

> 
> 
> try like this instead
> 
> ```
> ...

 

Okay dammit.... that's it.  I need some sleep....

thanks...

How embarassing...  :Embarassed: 

----------

