takurua
Posts: 16
Joined: Thu Sep 29, 2016 2:23 pm

Webserver can't see hostname

Thu Feb 16, 2017 9:28 am

This seems so basic. I can access my webserver through 192.168.etc but I would like to resolve it down to hostname ( pi.local)
as set on raspi-config. I am trying to use the pi as an offline web server and would like to ask users on my wiif network to log on to pi.local. On my browser if I type in pi.local it attempts to find http://www.pi.local/ and fails.
I have looked through a few instructions but much of what is scattered around the web appears out of date and incomplete.
Running Raspbian Jessie Lite version.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Webserver can't see hostname

Thu Feb 16, 2017 2:54 pm

The two most popular ways are to use DNS or hosts list.

If you are not capable of managing a DNS server, you may be better off using hosts in each computer.

Some routers allow local DNS resolution.

takurua
Posts: 16
Joined: Thu Sep 29, 2016 2:23 pm

Re: Webserver can't see hostname

Thu Feb 16, 2017 3:39 pm

I should add I take my pi into a classroom with no internet and hook it up to my wifi router. The signal is picked up by over 300 smartphones over the course of a week to display a web page. Everything has to be set up on either the pi or the router.
A better way perhaps of phrasing it: the web browsers on student smartphones have to enter 192.168.blah blah to see my web pages. Kinda clumsy.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Webserver can't see hostname

Thu Feb 16, 2017 6:14 pm

OK, then you must use dns. Not that hard with RPi.

Code: Select all

$ sudo apt-get install dnsmasq
$ sudo nano /etc/hosts
Add this to /etc/hosts
192.168.x.x pi.local
The reboot to start the dns server.

Now you must set your RPi as the primary dns server in your router's dhcp settings. It will take effect when the computers on the localnet request or renew their IP leases.

edit: My setup did not like "pi.local" on localnet computers. I use the domain "pi.com" in /etc/dnsmasq.conf
$ sudo nano /etc/dnsmasq.conf
add this
address=/pi.com/192.168.x.x

FYI: This did not work on my iPhone.

After a bit of testing, you can install dnsmasq and use the hostname raspberrypi.local from localnet computers. It still won't work on my iPhone, and I would suspect any IOS device.

Return to “Networking and servers”