Is it possible to use my public IP address to serve a website? (Catalina)

Solution 1:

There are several ways to achieve this:

  • The classic way is to configure your router to do "port forwarding". You tell it that any connection destined to port 80 should be forwarded to your computer, so anyone trying to make an HTTP request to your public IP address would be sent to the HTTP server on your Mac.

    You would probably also do the same for port 443 (HTTPS).

    Limitations apply: your ISP must not block inbound traffic (explicitly or implicitly because they would be using CGNAT), you can only forward to a single server...

    Instead of using your public IP address, you can use a dynamic DNS service which will give you a domain name that maps to your IP address and is updated if your IP address changes. If you have a fixed IP address, you can directly point a DNS name to your IP.

  • Another way is to do tunnelling. Something on your Mac connects to a server on the outside, and a tunnel is created inside this connection, which forwards traffic received on the outside server's IP/port to your server.

    If you have your own Linux server hosted somewhere, you could use ssh with a remote port forwarding request (-R) to achieve that.

    Or you can use a service like Ngrok which will do that for you. You tell it the local protocol and port on your Mac, and it will give you a publicly accessible URL which is forwarded back to the server on your Mac. There are probably tons of alternatives.

    There are also more general-purpose VPNs that could be used, but beware of security implications.

    The drawback of all these methods is that you depend on "something" out there on the Internet, and that all traffic will go through this device/service before reaching your home server. This can add latency or bandwidth bottlenecks, and of course there's often a direct or indirect cost as you need to pay for this "something".

Note that in both cases, you should be mindful about security: your local network is normally protected from the outside by NAT, but you're opening a "hole". If there are any security issues on the server you run on your Mac, external users may be able to access stuff on your Mac or on the rest of your network they wouldn't usually be able to.

Solution 2:

Is it possible? Yes. But there are some caveats:

  1. Your Internet Service Provider may (probably does) block servers of any sort from being hosted behind your network - as listed in their terms of service
  2. Apache (and therefore websites) generally require constant uptime, hosting it on a Mac is not impossible, by any means, but you'd need to keep the computer turned on all the time. Which can eventually slow your computer down to the point it is unusable by you.
  3. If you get enough traffic (bots, etc) - it may be considered a Denial of Service (DoS) attack by your ISP. They can suspend your service.

If, for whatever reason, it turns out that your ISP does not block servers on the network, you can use a service like DynDNS to point a hostname to your external IP which makes everything so much easier to remember.

You would also need to port-forward port 80 (and/or 443) via your modem to your internal private IP which may or may not change behind your network.