CentOS 上 Apache Solr 的正确 iptables 配置是什么?

syn*_*n4k 3 firewall iptables centos solr apache-2.2

我知道运行 iptables 会导致我的 Apache Solr 实例无法访问的事实。我怎么知道这个?因为我跑了:

/sbin/service iptables save && /sbin/service iptables stop
Run Code Online (Sandbox Code Playgroud)

一旦我这样做了,一切都完美无缺。

但是,我想继续使用我的防火墙,添加必要的规则似乎不起作用。我已经用尽了我认为可行的方法:

/sbin/service iptables start
/sbin/iptables -A RH-Firewall-1-INPUT -p tcp -s 127.0.0.1 --dport 8983 -j ACCEPT
/sbin/service iptables save
Run Code Online (Sandbox Code Playgroud)

还是行不通

/sbin/iptables -D RH-Firewall-1-INPUT -p tcp -s 127.0.0.1 --dport 8983 -j ACCEPT
/sbin/iptables -A RH-Firewall-1-INPUT -p tcp --dport 8983 -j ACCEPT
/sbin/service iptables save
Run Code Online (Sandbox Code Playgroud)

还是行不通

我什至尝试在 8983 端口上做一个通用的 ACCEPT:

/sbin/iptables -A INPUT -p tcp --dport 8983 -j ACCEPT
/sbin/service iptables save
Run Code Online (Sandbox Code Playgroud)

还是行不通!

想法?

**/sbin/iptables -L -n -v**

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 215K   50M RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8983 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 279K packets, 286M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain RH-Firewall-1-INPUT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
14286   19M ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    8   672 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 255 
    0     0 ACCEPT     esp  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     ah   --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251         udp dpt:5353 
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:631 
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:631 
 181K   29M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    2   164 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:55 
  148  7676 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8008 
    2   120 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
11208  621K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
 2202  123K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443 
 5372  951K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited
Run Code Online (Sandbox Code Playgroud)

更新(在最后一条规则之前添加):

*# /sbin/iptables -L -n -v --line-numbers*
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     585K  123M RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 782K packets, 822M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain RH-Firewall-1-INPUT (2 references)
num   pkts bytes target     prot opt in     out     source               destination         
1    31867   43M ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
2       27  2232 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 255 
3        0     0 ACCEPT     esp  --  *      *       0.0.0.0/0            0.0.0.0/0           
4        0     0 ACCEPT     ah   --  *      *       0.0.0.0/0            0.0.0.0/0           
5        0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251         udp dpt:5353 
6        0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:631 
7        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:631 
8     502K   76M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
9        4   268 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:55 
10     189  9780 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8008 
11       8   480 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
12   29633 1656K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
13    6138  345K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443 
14   14841 2635K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

*# /sbin/iptables --insert RH-Firewall-1-INPUT 14 -p tcp --dport 8983 -j ACCEPT
# /sbin/iptables -L -n -v --line-numbers*
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     599K  127M RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 RH-Firewall-1-INPUT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 801K packets, 841M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain RH-Firewall-1-INPUT (2 references)
num   pkts bytes target     prot opt in     out     source               destination         
1    32631   44M ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
2       27  2232 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 255 
3        0     0 ACCEPT     esp  --  *      *       0.0.0.0/0            0.0.0.0/0           
4        0     0 ACCEPT     ah   --  *      *       0.0.0.0/0            0.0.0.0/0           
5        0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251         udp dpt:5353 
6        0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:631 
7        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:631 
8     514K   78M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
9        4   268 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:55 
10     292 15136 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8008 
11       8   480 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
12   30425 1701K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
13    6304  355K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443 
14       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8983 
15   15130 2690K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited
Run Code Online (Sandbox Code Playgroud)

即使在RH-Firewall-1-INPUT链的最后一行之前添加了ACCEPT规则,它仍然不起作用

Mad*_*ter 8

iptables 规则的顺序很重要,因为第一场比赛获胜。Red Hat 和大多数明智的人一样,通常在其链的末端放置一个全面的 REJECT,并添加规则以允许 solr 流量 - 或任何其他类型的流量 - 之后将无济于事,因为数据包永远不会到达那么远下链。

如果这是咬你的东西,你需要做一个iptables -L -n -v --line-number,在最后找到一揽子规则的编号,并使用iptables -I RH-Firewall-1-INPUT n ...在行号处插入你的接受n,其中 n 小于毯子拒绝的数量。

编辑:感谢列出。看到最后那条毯子REJECT all -- * *了吗?ACCEPT在那之后添加您的内容毫无意义,因为您永远不会走那么远。尝试执行--line-number列表以找出需要插入该行的位置 - 在最后一行之前的任何位置 - 并查看是否有效。

编辑 2:您还可以确认netstat -an|grep 8983在服务器上返回一些合理的内容吗?

编辑 3:那么您的服务器没有侦听端口 8983,这就是为什么即使在防火墙中打开端口后也无法连接到它的原因。如果你在那个端口上有一个监听器,你会看到类似的东西

[madhatta@www mail]$ netstat -an|grep 443
tcp        0      0 193.219.118.100:443         0.0.0.0:*                   LISTEN 
Run Code Online (Sandbox Code Playgroud)

上面的示例取自我的网络服务器,这就是端口 443 而不是 8983 的原因。在我们取得更多进展之前,您需要找出 8983 上没有侦听器的原因。

编辑 4:您无法连接到不收听的守护进程。我知道您说过“关闭防火墙可以解决所有问题”,当守护进程正在侦听时,这可能是正确的;但现在我对此表示怀疑。如果你愿意重复这个实验:关闭防火墙,确认netstat -an|grep 8983服务器上仍然没有返回任何内容,然后显示telnet server 8983提供连接,我会感到惊喜。

编辑 5:很高兴为您提供帮助!