Mac端口转发

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值