How can I do a permanent port forwarding on my Mac Catalina:

  • it will run on background
  • it will work after reboot
  • FW is off

Today I use command:

ssh -L 5900:localhost:5901 localhost

But it runs on foreground and closes after computer restart. So, I need something like this command BUT with 3 requirements that I wrote above. Is it possible?


Ok, I think that I found the possible solution for me:

  1. sudo touch /etc/pf-xxx.conf

  2. Write to the file(/etc/pf-xxx.conf): I did it for my vnc ports

    rdr pass inet proto tcp from to port 5901 -> port 5900

    rdr pass inet proto tcp from to port 5902 -> port 5900

  3. Create & edit com.apple.pfctl-xxx.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <false/> <key>Label</key> <string>com.apple.pfctl-xxx</string> <key>WorkingDirectory</key> <string>/var/run</string> <key>Program</key> <string>/sbin/pfctl</string> <key>ProgramArguments</key> <array> <string>pfctl</string> <string>-e</string> <string>-f</string> <string>/etc/pf-xxx.conf</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>

  4. sudo chown root:wheel /Library/LaunchDaemons/com.apple.pfctl-xxx.plist

  5. sudo chmod o-w /Library/LaunchDaemons/com.apple.pfctl-xxx.plist

  6. sudo launchctl load /Library/LaunchDaemons/com.apple.pfctl-xxx.plist

The links that I used:

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.