資料顯示 MAC OS本質是Unix系統,預設非root使用者無法使用1024一下的端口,要是非要用,比如一般情況下,本地項目用tomcat運作,一般都是localhost:8080/XXXX,如果想通過localhost/XXXf方式來通路, 可以通過間接的方式來使用80端口;
1.打開終端,
2.建立檔案 :
sudo vim /etc/pf.anchors/eclipse.tomcat.forwarding
3.輸入檔案内容:
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 8443
4:儲存并退出,按住ESC ,輸入:wq
5.建立檔案 :
sudo vim /etc/pf-tomcat.conf
6.輸入檔案内容
rdr-anchor "forwarding"
load anchor "forwarding"from "/etc/pf.anchors/eclipse.tomcat.forwarding"
7.儲存并退出,按住ESC ,輸入:wq
8.啟動
sudo pfctl -ef /etc/pf-tomcat.conf
執行結果如下就可以通過80端口來通路了
root@ymdeMacBook-Air etc# sudo pfctl -ef /etc/pf-tomcat.conf
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.
No ALTQ support in kernel
ALTQ related functions disabled
pf enabled
想要關閉的話,指令是
sudo pfctl -d
全部關閉的指令
pfctl -F all -f /etc/pf.conf