从TCP_IN中删除端口不会将其从CSF上的外部流量关闭

时间:2016-08-30 13:35:38

标签: linux ssh firewall iptables ufw

几天前,我已经通过SSH在我的Ubuntu主机上安装了CSF。一切似乎工作正常,我有机会玩它几个小时。弄清楚我如何关闭和打开端口。一切似乎都很好。

今天我尝试对我的3306 mysql端口进行限制,并且只允许访问特定的IP地址。我这样做是通过检查它是从csf.conf上的TCP_IN和TCP_OUT行中删除并将其插入csf.allow。

当使用nmap扫描端口时,端口看起来是打开的,因此不会起作用。在进一步调试之后,我发现我现在对csf.conf和csf.allow文件所做的任何更改都不会影响端口的可用性。

我进一步研究并发现ufw防火墙,iptables和csf之间可能存在一些问题,所以我停止了ufw防火墙并删除了所有的iptables规则并将它们设置为默认值。

:~$ sudo iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

:~$ sudo service ufw status
ufw stop/waiting

现在我只是刷新,停止并启动了csf防火墙: csf -f,csf -x,csf -e

重新启动后,看起来sudo iptables -L会输出一个庞大的规则列表,其中包含source作为任何地方和目标。我以前没有这方面的经验所以我不确定我是否能够提取正确的敏感信息,但在阅读之后我认为这不适合我的情况。

另一方面,csf -L具有不同的输出。大多数源和目标IP都为0.0.0.0/0。我可以从csf -L输出中提取的是有一个无效链。

Chain INVALID (2 references)
num   pkts bytes target     prot opt in     out     source                      destination
1        0     0 INVDROP    all  --  *      *       0.0.0.0/0               0.0.0.0/0            ctstate INVALID
2        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x00
3        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x3F
4        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x03/0x03
5        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x06/0x06
6        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x05/0x05
7        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x11/0x01
8        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x18/0x08
9        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x30/0x20
10       0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:!0x17/0x02 ctstate NEW

Chain ALLOWIN (1 references)
num   pkts bytes target     prot opt in     out     source               destination
 1      210 10680 ACCEPT     all  --  !lo    *       [mysship]        0.0.0.0/0

Chain ALLOWOUT (1 references)
num   pkts bytes target     prot opt in     out     source                destination
1      295 41404 ACCEPT     all  --  *      !lo     0.0.0.0/0              [mysship]

MYSSHIP是我使用SSH连接的ip,我已经将它放在csf.allow上,而且ss端口也可以在csf.conf TCP_IN,TCP_OUT列表中找到。

2 个答案:

答案 0 :(得分:0)

嗯,对我来说,我把政策改为Drop然后我允许我想要的任何东西,看看:

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

您可以使用-s(对于源)或-d(对于destinaiton)添加所需的IP @!

答案 1 :(得分:0)

我不确定是什么导致了这种混乱,但我从iptables和csf刷新了我之前的所有配置。我重新安装了csf而不是逐个编写所有配置,使用nmap在每一步测试。我还将TESTING_INTERVAL修改为15.我认为当我保持TESTING = 1时,我的防火墙设置被清除得太快;