2

I'm a bit new to the topic of servers, ip addresses (public and private), ports, networking, and how all of this stuff ties together.

Playing around, I managed to run apache on my mac and get an html page up and running on localhost. I typed my private IP address into another device and I was able to see this page.

If I understand correctly, a private IP address is an IP address that's specific to my "local network" which I assume is anything connected to my wifi.

Is it possible to make a webpage that is served from my mac and visible from devices not connected to my local network? I expect to be able to type my public ip address into a URL bar and see this page.

I am aware that there is an app from the App store related to this topic, but I feel this should be basic functionality that can be done from the Terminal (correct me if I'm wrong).

Thanks for the help!

2
  • How is your Mac connected to the Internet, is there a router or modem involved somewhere? Can you access the configuration of it? – nohillside Apr 14 at 5:49
  • 1
    Don't! Not until you have the knowledge and experience to securely maintain your web server - and that is an ongoing commitment to security. Otherwise your web site is an open invitation to take over your Mac and anything else on your local network. Better to host your web page on a professionally managed server for a few dollars a month. – Gilby Apr 14 at 22:09
2

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.

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.

2
  • 1
    How does keeping your computer on all the time "slow your computer down to the point it is unusable"? My uptime is generally on the order of hundreds of days. BTW, I've run webservers, ftp, etc. from my home on multiple occasions (with internet via Knology, WoW, Comcast), never any issue, though it is fun to watch the logs to see how many times I still get Code Red attacks. Haven't tried with Google Fiber yet though. – Glen Yates Apr 14 at 15:07
  • I have this issue where I have to reboot about once a week - regardless of the Mac I am on (Mac Pro or Macbook Pro, doesn’t seem to matter, has also occurred on Mac Minis, although I initially believed this to be because of the lack of RAM) because it starts to utilise a massive swap file, and eat all its RAM. It absolutely CAN slow your computer down. – s3_gunzel Apr 14 at 23:26
2

Much will depend on your network set-up and is beyond the scope of a single answer.

Try with my Miln Beyond application to confirm your primary outgoing IP address, and if a NAT or UPnP device is on your network. This is to test if the devices are configurable and your network is truly publicly accessible.

Use Beyond's Beyond Network window to see your computer and network's assigned IP addresses:

Screenshot of Miln Beyond

Do you have another computer or device on a separate network, such as a mobile phone with a data (non-wifi) connection? Use this second device to test access to your server. Testing access using the same network can provide misleading results.

If this works, then you can achieve the same via the command line and Apache httpd.

Unverified Address

You commented:

Unverified potentially accessible address. Provided by local Network Address Translation (NAT) or Universal Plug and Play (UPnP) device.

An "unverified" address is potentially accessible from the Internet. It is unverified only because Beyond has not actively checked it (that requires a membership).

The listing also suggests that your router supports NAT or UPnP to open external ports and allow incoming traffic.

Does your Internet router have a web interface? The router is a device often supplied by your Internet Service Provider (ISP). If so, look for NAT or UPnP settings; these may also be called Port Forwarding.

By default, your router should block incoming traffic from the Internet into your network. To offer a server to the wider Internet, your router needs to be told to accept specific incoming traffic and to pass it to the server inside your network.

For short lived servers and services, like video/voice calls, NAT and UPnP are used. This is what Beyond has managed to do on your network.

3
  • 1
    Great application: 👏🏻! – dan Apr 14 at 9:54
  • 1
    Very useful, thanks! For my public IP address I am seeing an orange circle as the status and it says "Unverified potentially accessible address. Provided by local Network Address Translation (NAT) or Universal Plug and Play (UPnP) device." So I suspect, like the other answers said, that it's something my ISP doesn't allow. – Mister Nick Apr 15 at 4:07
  • That is hopeful news. This suggests you can access your Mac from the Internet. I have extended my answer. Could you browse to the web server provided by Beyond? – Graham Miln Apr 15 at 6:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .