Skip to content

Instantly share code, notes, and snippets.

@reedho
Created December 10, 2024 22:33
Show Gist options
  • Save reedho/d2e41c9207e1f017d11d272f150795f8 to your computer and use it in GitHub Desktop.
Save reedho/d2e41c9207e1f017d11d272f150795f8 to your computer and use it in GitHub Desktop.
Mac OS redirect port with pf

This is for scenario where we want to access kubernetes cluster on our mac that is created with colima.

The kube api server is a k0s docker container running inside colima with url: https://172.17.0.2:6443.

  1. Modify /etc/pf.conf file to be like below, note that the rdr pass ... line must be exactly before anchor and load anchor.
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
dummynet-anchor "com.apple/*"
rdr pass on lo0 inet proto tcp from any to 172.17.0.2 port 6443 -> 127.0.0.1 port 6443
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
  1. Reload pf setting
sudo pfctl -f /etc/pf.conf
sudo pfctl -e
sudo pfctl -vvsn
sudo route add 172.17.0.0/24 127.0.0.1
  1. Setup route
sudo route add 172.17.0.0/24 127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment