Mac端口转发

来源:互联网 发布:linux批量解压缩zip 编辑:程序博客网 时间:2024/06/05 05:54

mac os 10.10以上的开启端口转发-解决mac默认不开启102以上端口权限问题,详情请参见man pfctl

1、回到根目录:cd ~
2、pf=yes
3、cd /etc/pf.anchors/
4、管理员权限创建http文件:sudo vi http
编辑如下内容
rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass on en0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
lo0为ifconfig时查询到的网卡的名字
80是tomcat端口
8080为你想转发的端口
注意: 在段落末尾一定要加换行,否则会报syntax error错误。
5、检测配置文件:sudo pfctl -vnf /etc/pf.anchors/http
正常会打出配置信息
6、修改pf的主配置文件/etc/pf.conf, 来引入这个转发规则
在rdr-anchor “com.apple/*”下,添加如下 anchor 声明:rdr-anchor “http-forwarding”
再在load anchor “com.apple” from “/etc/pf.anchors/com.apple”下, 添加 anchor 引入:load anchor “http-forwarding” from “/etc/pf.anchors/http”
pf启动时会自动装载/etc/pf.conf文件,因此将anchor文件链接到/etc/pf.conf,转发规则就会自动建立了。
pf.conf对指令的顺序有严格要求,否则会报出 Rules must be in order: options, normalization, queueing, translation, filtering 的错误,所以相同的指令需要放在一起。
7、导入并允许运行 pf:sudo pfctl -ef /etc/pf.conf
(或sudo pfctl -f /etc/pf.conf
或sudo pfctl -evf /etc/pf.anchors/http)
8、设置开机自动打开:sudo pfctl -e
添加的为-e参数,即enable
关闭pf 命令:sudo pfctl -d
(或为/System/Library/LaunchDaemons/com.apple.pfctl.plist针对 pfctl 的启动项,新增一个 -e (enable) 参数。)

参考:http://hj-h.com

0 0
原创粉丝点击