How set PF on macOS Mojave rules and restrict ip access

时间:2019-04-17 02:42:44

标签: macos firewall rules

Information

Docker for Mac: version: 2.0.0.3 (31259)

macOS: version 10.14.4 Mojave

PF ruels

Refer the link https://blog.neilsabol.site/post/quickly-easily-adding-pf-packet-filter-firewall-rules-macos-osx/

Trouble

My trouble is:

In the /etc/pf.conf add the rules:

block return in proto tcp from any to any port 443
pass in inet proto tcp from 10.2.0.0/24 to any port 443 no state

then run the command sudo pfctl -evf /etc/pf.conf

Then in browser(Chrome/Safari) can not access the ip address. Is pf not working in mojave?

1 个答案:

答案 0 :(得分:2)

感谢您阅读我的博客,并对此深表歉意。

我用类似于您的设置进行了一些测试,并且pf似乎在Mojave(10.14.x)和Catalina(10.15.x-beta)中的工作方式与在High Sierra(10.13.x)中的工作方式相同。 / p>

您是否正在尝试从运行Docker的Mac通过https://localhosthttps://127.0.0.1访问该站点?如果是,则可能需要添加第二条规则(下面的最后一行):

block return in proto tcp from any to any port 443
pass in inet proto tcp from 10.2.0.0/24 to any port 443 no state
pass in inet proto tcp from 127.0.0.1 to any port 443 no state

为了测试Mojave和Catalina,我做了以下工作。

  1. 启动Apache测试容器
docker run -dit --name apache24-test -p 80:80 httpd:2.4
  1. 已确认通过 http://localhost http://ipaddress

  2. 访问
  3. 将这些规则添加到 /etc/pf.conf

block return in proto tcp from any to any port 443
pass in inet proto tcp from 10.2.0.0/24 to any port 443 no state
pass in inet proto tcp from 127.0.0.1 to any port 443 no state
  1. 加载规则并启用pf
sudo pfctl -f /etc/pf.conf
sudo pfctl -E

完成后,可以从运行Docker的Mac和10.2.0.0/24子网中的其他PC在端口80上访问Apache测试站点“ It Works”。无法从其他网络访问它。

让我知道这是否有所帮助或有所作为。如果没有,则可能需要解决Docker级网络配置。

谢谢你, -尼尔