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

Kernels & Hardware, configuring network, installing services

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

Postby flexmcmurphy » 2019-10-20 21:18

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
flexmcmurphy
 
Posts: 1
Joined: 2019-10-20 21:12

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

Postby andre@home » 2019-10-20 23:20

Double post without notice to helpers here.... :x
https://stackoverflow.com/questions/584 ... -resolving
andre@home
 
Posts: 347
Joined: 2011-10-02 08:00

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

Postby Dai_trying » 2019-10-21 07:13

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.
Dai_trying
 
Posts: 800
Joined: 2016-01-07 12:25

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

Postby p.H » 2019-10-21 07:54

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 ?
p.H
 
Posts: 1160
Joined: 2017-09-17 07:12

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

Postby coppolino97 » 2019-11-05 21:08

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
HP Elitebook 840 G3 | 8Gbyte of RAM | Intel core i5 | SSD 250GB | Debian 10
coppolino97
 
Posts: 47
Joined: 2018-06-05 15:23


Return to System configuration

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable