firewall-cmd tcp ssh REJECT规则不起作用

时间:2019-12-03 03:33:49

标签: centos7 firewalld

以下xml内容显示了我创建的防火墙规则。有两个状态为“拒绝”的规则是避免与服务器建立ssh连接的方法。但这是行不通的。允许连接。 我做了firewall-cmd重新加载。另一条icmp规则工作正常,但不确定ssh出了什么问题。

请帮助。

<?xml version="1.0" encoding="utf-8"?>
<direct>
  <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p all --state RELATED,ESTABLISHED -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p icmp -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p all -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 22 -j REJECT</rule>
  <rule priority="0" table="filter" ipv="ipv6" chain="INPUT">-p all --state RELATED,ESTABLISHED -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv6" chain="INPUT">-p icmp -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv6" chain="INPUT">-p all -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT</rule>
  <rule priority="0" table="filter" ipv="ipv6" chain="INPUT">-p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 22 -j REJECT</rule>
</direct>

1 个答案:

答案 0 :(得分:0)

原因是该端口未为sshd服务打开。 在sshd_config文件中,我在行下面添加了

firewall-cmd --add-port=5670/tcp --permanent
systemctl restart sshd

然后在命令下面运行

import Colors from '....';