MAC 接口转发

mac与linux一样,1024以下的端口为特权端口,只有root用户才有权监听。

因此要使用80端口要么使用root启动tomcat,要么使用端口转发。

使用ipfw(Internet Protocol Firewall)设置端口转发

        ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

不过ipfw已经被标记为废弃状态。

使用pf(packet filter)设置端口转发

1.创建anchor文件

sudo vi /etc/pf.anchors/tomcat

rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
2.测试anchor文件是否正确配置
      pfctl -vnf /etc/pf.anchors/tomcat

如果正确会显示
          
          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.

rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port = 80 -> 127.0.0.1 port 8080

添加到主配置文件
pf启动时会自动装载/etc/pf.conf文件,因此将anchor文件链接到/etc/pf.conf,转发规则就会自动建立了。

rdr-anchor "tomcat-forwarding"
    load anchor "tomcat-forwarding" from "/etc/pf.anchors/tomcat"
注意要紧随文件中现有的anchor后面添加上面两行

有的电脑 需要严格按照上面的顺序来
打开pf
pf默认是关闭的。可以使用以下命令启动pf:

pfctl -e /etc/pf.conf
也可以使用其他配置文件启动pf。

也可以修改LaunchDaemons来使pf开机自动打开。
/System/Library/LaunchDaemons/com.apple.pfctl.plist

<key>ProgramArguments</key>
      <array>
      <string>pfctl</string>
      <string>-e</string>
      <string>-f</string>
      <string>/etc/pf.conf</string>
    </array>

添加的为-e参数,即enable

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,324评论 19 139
  • 在使用mac os 进行web开发时,会遇到80端口已经被占用的情况。mac禁止了普通用户访问1024以下的端口,...
    lsif的简书阅读 11,649评论 2 5
  • 想要自己玩服务器,pagekit是用来做测试的好东西,然而要把tomcat设到80端口又不合适了.Mac OS X...
    TEASON阅读 11,667评论 2 7
  • 转自陈明乾的博客,可能有一定更新。 转原文声明: 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 ...
    LUNJINGJIE阅读 9,388评论 1 33
  • 今天是9月10日,是我高中毕业以来至今的第8个年头,回望过去8年的青春时光,不禁感叹时光飞逝,流年似水,...
    百合花的春天SSY阅读 3,508评论 0 1