Skip to content
← Back to Blog
By Aaron Hampton Updated

Port Forwarding on Mac: Router, Firewall, and How to Verify It Worked

Port forwarding on Mac requires two separate steps: configuring your router and configuring macOS. Here's how to get both right and confirm the port is reachable.

Port forwarding on Mac involves two separate layers that people often treat as one thing. Your router needs to send incoming traffic to your Mac’s local IP. macOS needs to allow that traffic through its firewall. Getting one right without the other means the port still won’t respond from outside your network.

The Two Layers

When a connection request arrives at your public IP on port 8080, it hits your router first. The router has no idea which device on your local network should receive it. You have to tell it explicitly with a port forwarding rule.

Once that rule exists and the packet reaches your Mac, macOS decides whether to pass it to the app. The macOS Application Firewall is off by default, so unless you or your organization turned it on, nothing blocks the connection at this layer. When it is on, an app that is already running and listening on the port will usually trigger a one-time allow prompt, but you may need to add an explicit exception for command-line servers.

Step 1: Configure Your Router

Every router admin interface looks different, but the concept is the same: map an external port to a specific local IP and port.

First, find your Mac’s local IP. Open Terminal and run:

ipconfig getifaddr en0

Replace en0 with your active interface. Which en number is Wi-Fi and which is Ethernet varies by model (on Mac desktops en0 is often Ethernet), so check with networksetup -listallhardwareports. This returns something like 192.168.1.42. Write it down.

Log into your router’s admin panel (typically at 192.168.1.1 or 192.168.0.1). Find the Port Forwarding or NAT section and add a rule:

  • External port: the port you want accessible from the internet (e.g., 8080)
  • Internal IP: your Mac’s local address (e.g., 192.168.1.42)
  • Internal port: the port your app listens on (usually the same)
  • Protocol: TCP, UDP, or both

Save the rule. Your Mac’s local IP can change unless you set a static DHCP lease in your router settings. If the IP changes, the port forward rule breaks silently.

Step 2: Check the macOS Firewall

Open System Settings > Network > Firewall. If the firewall is off, incoming connections reach your app without restriction. This is common in local development environments behind a home router.

If the firewall is on, click Options. You can add specific applications and allow them to receive incoming connections. For GUI apps (like a web server packaged as a Mac app), this is usually enough.

For command-line servers (Node.js, Python’s http.server, Go binaries, etc.), macOS may not prompt you automatically. In that case, the firewall blocks incoming connections even if the router rule is correct. Add the binary explicitly via the Options list, or disable the firewall on the development machine if you are behind NAT and not directly exposed.

Step 3: Local Port Redirection With pf (Advanced)

If you want to redirect a privileged port (80 or 443) to a high-numbered port where your dev server runs without root access, macOS’s built-in packet filter handles this:

echo "rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080" | sudo pfctl -a com.apple/portforward -f -
sudo pfctl -E

This redirects TCP traffic arriving on port 80 to port 8080 on your Mac. The -a flag loads the rule into its own anchor. Without it, pfctl -f - replaces the whole main ruleset with this single rule and drops the system’s own pf rules. The stock /etc/pf.conf already contains rdr-anchor "com.apple/*", so an anchor under com.apple/ is picked up as is. If you pick a different anchor name, /etc/pf.conf must reference it with its own rdr-anchor line.

sudo pfctl -E enables pf. To remove the rule, run sudo pfctl -a com.apple/portforward -F all. The rule does not survive a reboot. To make it persistent, put it in an anchor file loaded from /etc/pf.conf and configure pf to load at startup.

Verify the Port Is Actually Open

Before blaming the router or firewall, confirm your app is actually listening on the expected port. Run:

lsof -i :8080

If nothing shows up, the app has not started listening. No amount of port forwarding configuration will fix that. Portie shows all listening ports in a live view, which makes it easy to confirm the app is running before chasing external access issues.

For external verification, the test has to start outside your network. A scan run from your own Mac goes through your router’s internal path, so it can report the port as open even when the internet cannot reach it. Test from a device on another network instead: a phone on cellular data, or a remote machine running nc -zv YOUR_PUBLIC_IP 8080. Portie’s remote scanner runs from your Mac, so it is useful for checking other hosts on your LAN or a remote server, not for confirming your own port forward from the outside.

The most common port forwarding failures, in order: the app is not listening yet, the router rule has the wrong local IP because it changed via DHCP, and the macOS firewall is blocking the incoming connection. Check them in that order and you will find the problem quickly.

Try Portie Free

See every open port on your Mac, which app owns it, and kill processes from the list.

Download Free