Enabling routing and NAT on macOS

Steps: Enable routing on macOS

  1. Open the Terminal application and enter this command:
    • sysctl -w net.inet.ip.forwarding=1

Steps: Enable NAT on macOS

  1. Create a file titled “pf-nat.conf” and add this rule:
    • nat on en0 from utun0 to any -> (en0)
  2. Save the pf-nat.conf file.
  3. Start pfctl using the rule from the pf-nat.conf file.
    • sudo pfctl -d    #disables pfctl
    • sudo pfctl -F all    #flushes all pfctl rules
    • sudo pfctl -f /Path/to/file/pf-nat.conf -e    #starts pfctl and loads the rules from the pf-nat.conf file