我有一个基于 Java 的服务器(jar 文件),它在端口 8080 上运行。
它在我的电脑上运行良好localhost
,但我无法通过其他网络访问它
我认为这是防火墙问题。因此,我首先尝试socketfilterfw
:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp
hellomac# sudo /usr/libexec/ApplicationFirewall/socketfilterfw --list
ALF: total number of apps = 5
1 : /usr/bin/nc
( Allow incoming connections )
2 : /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java
( Allow incoming connections )
这没用。其次,在 中添加规则pf
。
hellomac# cat /etc/pf.conf
#
# Default PF configuration file.
#
# This file contains the main ruleset, which gets automatically loaded
# at startup. PF will not be automatically enabled, however. Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8). That will ensure that PF
# is disabled only when the last enable reference is released.
#
# Care must be taken to ensure that the main ruleset does not get flushed,
# as the nested anchors rely on the anchor point defined here. In addition,
# to the anchors loaded by this file, some system services would dynamically
# insert anchors into the main ruleset. These anchors will be added only when
# the system service is used and would removed on termination of the service.
#
# See pf.conf(5) for syntax.
#
#
# com.apple anchor point
#
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
pass in proto tcp from any to any port 8080
但这也无济于事。
那么,出了什么问题?我现在该怎么办?
答案1
我刚刚遇到了与 Rails 类似的问题。
问题是 Yosemite 有一个应用程序防火墙,尽管我确信一定有一种方法可以打开单个端口,而不管绑定到该端口的应用程序是什么,但我找不到一种快速简便的方法来做到这一点。
完成您要执行的操作的最简单方法似乎是在系统偏好设置>安全>防火墙>防火墙选项中添加用于运行应用程序的“java”可执行文件(JVM),它应该可以工作。
例如,为了打开端口 3000 来访问我正在开发的 rails 应用程序,我添加了运行 rails 和为我的项目运行的其他 ruby 代码的 ruby 可执行文件。
要确定您正在使用哪个 java(JVM),请使用“哪个 java”。