Routing localhost traffic to external IP address
I have a host with Mac OS and another machine (192.168.100.50) in the same LAN. I would like to configure Mac OS in that way if I access localhost:443 it will redirect to 192.168.100.50:443.
I'm able to redirect ports inside Mac OS, so if I access localhost:444 it redirects to localhost:443 this way:
- sudo sysctl net.inet.ip.forwarding=1
2. /etc/pf.anchors/dev:
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 444
3. /etc/pf.conf:
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "dev"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "dev" from "/etc/pf.anchors/dev"
4. sudo pfctl -ef /etc/pf.conf
But if I change from any to 127.0.0.1 port 443 -> 127.0.0.1 port 444 to from any to 127.0.0.1 port 443 -> 192.168.100.50 port 443 it doesn't work.
I guess I should set up NAT somehow, but I'm not sure how to do that with PF to achieve that. So any help will be very appreciated.
MacBook Pro 15", macOS 10.14