I'm having an issue accessing my Pi hostname (respbian) on my local network (similar to Can't access web server via hostname, although from my remote host (a Mac) I can telnet to the hostname and port:
my-macbook-pro-2:~ me$ telnet raspbian.local 80
Trying 10.0.1.12...
Connected to raspbian.local.
Escape character is '^]'.
^]
I can also ssh to my locally named Pi host from my Mac. But, I cannot perform an nslookup (which is not surprising, since I am not running a DNS).
However, I still cannot browse via web from my Mac to the Pi's hostname (I can to its local assigned IP). So, the billion dollar question is: If port 80 is listening on the Pi and the Pi's local hostname is being resolved (either on the Mac or at the router), then why isn't the web browser resolving the Pi's local host name (I do have it in the /etc/hosts file on my Mac, incidentally)? The router does see the Pi's name when I look at the client list via the Airport Utility.
I am using apache2 as a web server, and Raspbian as the OS, FWIW.
1 Answer 1
If port 80 is listening for this on the Pi and resolving the local hostname
I'm not sure if you're confused here or not about how name resolution works -- the bit about "port 80 listening...and resolving the local hostname" implies you are confused.
Logically enough, hostname resolution does not happen on the target system (the pi), it happens on the local system (your Mac). "Logically enough", because there is no "hostname" used in TCP/IP, there is only the IP address, so for any communication to reach the target system, the hostname must first be correctly resolved, either on the local machine via its own mechanisms, or via DNS lookup, which, once again, logically cannot, except by pure coincidence (e.g., you are running a DNS server on the same system, which the local machine uses by IP) involve the target system.
In this case, since you can use the hostname correctly, it is either configured on the Mac (e.g., via LAN zeroconf, which is probably enabled on both systems; Raspbian uses avahi for this) or else relies on DNS resolution via the router.
That the hostname does not work on the Mac browser then implies one of two causes:
The browser or local OS is causing the problem.
The web server is rejecting the request. A hostname is used in HTTP headers, and apache or software it dispatches to may be configured to only accept requests with a specific name.
To definitively distinguish between the two possibilities, you could watch the transaction from one side or the other using a tool such as wireshark.
In any case, questions about OSX and OSX software are off-topic here and belong on Ask Different. Questions about apache configuration are also off-topic but might be appropriate on Unix & Linux, Server Fault, or perhaps Stack Overflow. As a clue, I would find out where the server logs to and check those logs to see if it is rejecting requests based on hostname. If this is the case, again, apache configuration is a topic better researched elsewhere, including the official documentation.
If in fact your problem is a browser on the pi (i.e., the same system the server is running on), edit /etc/hosts
and to the end of the 127.0.0.1 localhost.localdomain
line (probably the first one), add raspbian.local
.
-
Thanks, you are correct about name resolution. I had typed this rather quickly when I posted it. I just edited my question to reflect this.horcle_buzz– horcle_buzz2015年11月04日 20:46:46 +00:00Commented Nov 4, 2015 at 20:46
-
Apache's logs by default will be somewhere in
/var/log
-- either the obvious/var/log/apache
or perhaps/var/log/httpd
. If it is rejecting requests, you'll see some indication that it at least received them in there, then if so you just need to figure out how to get it to accept whatever host name.goldilocks– goldilocks2015年11月04日 21:18:01 +00:00Commented Nov 4, 2015 at 21:18 -
Apache logs are clean. Hosts file on both the Pi and Macbook are configured correctly. And I can access raspbian.local via the Pi's browser...horcle_buzz– horcle_buzz2015年11月05日 00:40:39 +00:00Commented Nov 5, 2015 at 0:40
-
Then you might as well treat this as an opportunity to get acquainted with wireshark. There's a drop dead simple difference in possibilities involved: Either the local system actually is sending packets to the target, or it is not. The possible solutions in one case are completely different than the other.goldilocks– goldilocks2015年11月05日 01:01:56 +00:00Commented Nov 5, 2015 at 1:01
-
I will definitely take a look, since I have other uses for it (I assume it is a network sniffer). In any case, @Mausy5043 gave the answer, but I could not select it, since it was only a comment. I couldn't even up-vote it either.horcle_buzz– horcle_buzz2015年11月05日 01:22:03 +00:00Commented Nov 5, 2015 at 1:22
apt-get install avahi-daemon libnss-mdns
on the Pi.