Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Why are host names in /etc/hosts not resolving?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
flexmcmurphy
Posts: 1
Joined: 2019-10-20 21:12

Why are host names in /etc/hosts not resolving?

#1 Post by flexmcmurphy »

Hello,

In my local LAN I have my laptop (192.168.1.101) and a Raspberry Pi (192.168.1.124). I have apache2 web server on the Pi running NextCloudPi file server.

Typing http://nextcloudpi into Chrome on my laptop pulls up a little web page I have on that apache2.

This is my /etc/hosts file:

Code: Select all

127.0.0.1	localhost.localdomain localhost
127.0.1.1	nextcloudpi

::1		localhost ip6-localhost ip6-loopback
ff02::1		ip6-allnodes
ff02::2		ip6-allrouters

192.168.1.124	nextcloudpi website2 website3
Here is my Apache2 virtualhost file:

Code: Select all

<VirtualHost _default_:80>

    ServerName nextcloudpi:80
    ServerAlias website2 website3

    DocumentRoot /var/www/mymovies
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/mymovies
    ErrorLog /var/www/mymovies/logs/http-error.log
    CustomLog /var/www/mymovies/logs/http-access.log combined

    <Directory /var/www/mymovies/>
      #Require host localhost
      #Require ip 127.0.0.1
      #Require ip 192.168
      #Require ip 10
    </Directory>

</VirtualHost>
My Question:
Host names - website2 and website3 - should make the same web page appear but they don't. Instead if I try: http://website2 (or website3) then Chrome gives the error message: " website3 ’s server IP address could not be found" "ERR_NAME_NOT_RESOLVED"

How come http://nextcloudpi resolves to the correct local ip address but when I add other host names into /etc/hosts they are not recognized? I’m thinking the format of my /etc/hosts file is wrong but after much googling I don’t see what is wrong with it. nextcloudpi is in /etc/hostnames maybe that is why?

Code: Select all

nano /etc/nsswitch.conf
gives...

Code: Select all

hosts:          files mdns4_minimal [NOTFOUND=return] dns
This means the dns lookup should check /etc/hosts first but it feels like the request from Chrome doesn't look in /etc/hosts at all and maybe the fact the http://nextcloudpi does work is because of some other setting?

I have also tried flushing the dns cache on the laptop and on the Pi and restarting the Pi... many times.

Thank you,

Flex

andre@home
Posts: 398
Joined: 2011-10-02 08:00

Re: Why are host names in /etc/hosts not resolving?

#2 Post by andre@home »

Double post without notice to helpers here.... :x
https://stackoverflow.com/questions/584 ... -resolving

Dai_trying
Posts: 1101
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: Why are host names in /etc/hosts not resolving?

#3 Post by Dai_trying »

I noticed (using palemoon browser) that if I type the name in the location bar without http:// first my system will not resolve to addresses in my /etc/hosts file but if i type in full http://name it will resolve correctly, although you appear to be using http:// in your address it might not be the fault but thought it worth mentioning.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Why are host names in /etc/hosts not resolving?

#4 Post by p.H »

flexmcmurphy wrote:This is my /etc/hosts file
This file seems to be the one on the server. What does the one on the laptop contain ?

coppolino97
Posts: 117
Joined: 2018-06-05 15:23
Location: Italy
Has thanked: 2 times

Re: Why are host names in /etc/hosts not resolving?

#5 Post by coppolino97 »

Hi,

I suggest to configure /etc/hosts in this way:

Code: Select all

127.0.0.1   localhost.localdomain localhost
127.0.1.1   nextcloudpi

::1      localhost ip6-localhost ip6-loopback
ff02::1      ip6-allnodes
ff02::2      ip6-allrouters

192.168.1.124   nextcloudpi 
192.168.1.124  website2
192.168.1.124  website3
:D
Lenovo T460 | 8Gbyte of RAM | Intel core i5 | SSD 250GB | Debian 12

Post Reply