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

标签 linux ssh firewall iptables ufw

几天前,我通过 SSH 在我的 Ubuntu 主机上安装了 CSF。一切似乎都运行良好,我有机会玩了几个小时。弄清楚我如何关闭和打开端口。一切似乎都运行良好。

今天尝试限制mysql的3306端口,只允许特定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 将输出一个巨大的规则列表,源为任意位置,目标为任意位置。我以前没有这方面的经验,所以我不确定我是否能够提取正确的敏感信息,但在阅读之后我认为这不适合我的情况。

另一方面,csf -L 有不同的输出。大多数源和目标 ip 为 0.0.0.0/0。我可以从 csf -L 输出中提取的是有一个 INVALID Chain。

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 上,并且在 csf.conf TCP_IN、TCP_OUT 列表中找到了 ssh 端口。

最佳答案

嗯,对我来说,我将策略更改为 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(对于目标)添加您想要的 IP@!

关于linux - 从 TCP_IN 中删除端口不会将其与 CSF 上的外部流量关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39229038/

相关文章:

linux - Bash - 提高功率时的可变指数

Linux/Unix 在同一行中选择特定数据

linux - 查找比特定列长/短的记录

linux - EC2 key 对在一个实例中有效但在其他实例中失败 - 权限被拒绝(公钥)

mysql - 使用工作台通过 ssh 连接到远程 MySQL 数据库

linux - ssh 使用私钥无需密码

git - 配置具有GIT的Magento站点,并通过SSH连接连接到BitBucket

.net - 为什么 C# Google.Cloud.Firestore 库无法连接到企业 MITM 防火墙?

azure - 新的 Azure 门户(无端点)如何从防火墙后面使用 RDP 连接到 VM

php - 无法从 AWS AMI 运行 FTP 命令