본문 바로가기

시행착오/[Mac]

Mac OS 에서 포트포워딩(port forwarding) 하는법 - pfctl

로컬호스트 8000 => 로컬호스트 3000 으로 하는법과 삭제법은 다음과 같다.

#!/usr/bin/env bash

# forward localhost:8000 to localhost:3000
echo "rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 8000 -> 127.0.0.1 port 3000" | sudo pfctl -ef -

# remove it
sudo pfctl -F all -f /etc/pf.conf

참고) https://gist.github.com/sbolel/db5ad50c3f72c6a18ab6c7e7a924dcb9


외부에서 오는 모든 [80 포트 트래픽을 로컬호스트 8080] 으로, [443 포트 트래픽을 로컬호스트 8443] 으로 돌리는 법은 다음과 같다.

echo "
rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
" | sudo pfctl -ef -

 

현 포트포워딩 규칙 보는법

sudo pfctl -s nat

참고) https://salferrarello.com/mac-pfctl-port-forwarding/

 

Mac pfctl Port Forwarding - Sal Ferrarello

Historically, I used ipfw from the command line to do port forwarding on my Mac. Unfortunately, as of Yosemite OS X 10.10 ipfw has been removed. (In all fairness, ipfw has been deprecated for some time but I continued using it because it was way easier tha

salferrarello.com

https://apple.stackexchange.com/questions/230300/what-is-the-modern-way-to-do-port-forwarding-on-el-capitan-forward-port-80-to

'시행착오 > [Mac]' 카테고리의 다른 글