I've setup port-forwarding on my mac like this:sudo sysctl net.inet.ip.forwarding=1echo rdr pass inet proto tcp from any to any port 445 -> 127.0.0.1 port 5441 | sudo pfctl -ef -To this setup, I am running a server using nc like this:$ nc -l 5441When I try to connect to this server via telnet, the attempt fails with the following error:$ sudo telnet 127.0.0.1 445Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refusedtelnet: Unable to connect to remote hostRunning tcpdump on port 445 doesn't capture any packets. I am not sure what's going on and would appreciate all the help.
Port forwarding isn't working on mac osx
osx;port forwarding;telnet;nc
A rdr is only a redirect; one also may need a pass (or appropriate clicky around in the System Preferences) to permit access to that port. This works for me (though I've almost totally disabled the Apple firewall rules on my Mac OS X 10.11 laptop) in /etc/pf.conf:set skip on { lo0, vboxnet0 }rdr pass inet proto tcp from any to any port 445 -> 127.0.0.1 port 5441block inpass in inet proto tcp from any to any port 445And then a sudo pfctl -f /etc/pf.conf to load that and then testing with nc -l 127.0.0.1 5441 and connections to port 445 from a remote machine shows access.Hmm! However, locally to the Mac OS X system telnet 127.0.0.1 445 fails, probably on account of the skip lo0. This can be rectified by not using skip if localhost access to the redirect is necessary:set skip on vboxnet0rdr pass inet proto tcp from any to any port 445 -> 127.0.0.1 port 5441block inpass on lo0pass in inet proto tcp from any to any port 445Also note that locahost may either mean 127.0.0.1 or ::1 so you may also need to setup inet6 related rules, or ensure that the connections are always done with IPv4 so that IPv6 either works or is not used.