I recently installed apache2 on my raspberry pi 4B. I can reach it from the local IP ( FYI I used this tutorial. Anyway anywhere 'example.com' showed up I entered an UNUSED domain name, which we'll call mydomain.com (sorry I couldn't show you the real domain). Anyway, it still gives me a 404 error (even on port 80), the default I set. There's probably something I'm doing terribly wrong, but I find DNS and apache confusing, so if you could help me that'd be great.

  • TBH this is not a Pi issue... voted to close. Not wise to use an unused domain name - you have no control over the internet and someone could start using it. Google have recently started web crawling and testing with random domain names as a way of checking if your ISP redirects to ad based sites :-(
    – user115418
    Sep 14 '20 at 21:29

That it is always a 404 is a bit odd, unless by coincidence this domain name is an existing one and you are accidentally connecting to an external server.

we'll call mydomain.com (sorry I couldn't show you the real domain)

If this is an actual domain name that you have registered, you will need to set the name server you are using to point to the correct IP. A 192.168.x.x address is not valid for that.

Since you don't refer to any of this, I'm assuming it isn't registered and you were just hoping the domain would work (perhaps because you put it in an apache configuration). That's not how it works.

I won't regurgitate how DNS resolution works since this is very well documented many places online already. What you can do, if you want to use the domain name locally in development (sometimes this is significant), is add to the localhost entries in /etc/hosts:       localhost foo.bar
::1             localhost ip6-localhost ip6-loopback foo.bar

When you try to connect to foo.bar from the Pi, you will now be connecting to the Pi (local loopback). This will not work from another machine regardless of where it is unless you similarly spoof the DNS settings there.

Note this is not the same as setting the global hostname, which will remain unchanged.

  • Is there a way to host my own domain from my raspberry pi as well, rather than having to go out and pay for one (I don't want to use things like Freenom)?
    – user123730
    Sep 15 '20 at 23:03
  • You can, but you then need a service to provide dynamic nameservers that properly route traffic to your home: en.wikipedia.org/wiki/Dynamic_DNS (see esp. the "DDNS for Internet access devices" bit). This is probably less expensive than hosting. You then also need to set up port forwarding with your router. This is all because of the not insignificant difference between connecting to internet from inside your house and someone else connecting to a device inside your house without you having initiated the exchange.
    – goldilocks
    Sep 16 '20 at 14:10
  • ...There's also the option of getting a commericial ISP account that includes a static IP address assigned to your domain name, but this is much more expensive than any of the other options.
    – goldilocks
    Sep 16 '20 at 14:13

Unless you have a domain name registered and an A record pointing to the IP address of the Raspberry Pi, you have to use an IP address to connect to your Pi's webserver.

Also, your Pi's IP address is not globally accessible - it can only be reached from your own LAN.

Assuming you are running Raspberry Pi Os Buster, your Pi is running avahi-daemon which means it is advertising its own hostname to your LAN on the .local pseudo domain.

Type hostname to find out your Pi's hostname.

Then, from another computer, try

ping -n raspberrypi.local

(raspberrypi is the default hostname; substitute your Pi's actual hostname for raspberrypi).

  • Nope - you can use a local DNS server (e.g. PI-HOLE) or enter the pi address in the hosts file...
    – user115418
    Sep 14 '20 at 21:26
  • Many questions in computing have multiple correct answers. Yes, the OP could set up their own DNS server, or edit /etc/hosts at their web client. The question doesn't provide enough detail to know if this is a good idea, so I suggested they try mDNS, which should be already configured and working for them, over a local LAN.
    – nickandrew
    Sep 16 '20 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy