首页 新闻 会员 周边

关于使用iptables禁用某网段ssh不可登陆该服务器------不成功的求助

0
[待解决问题]

疑难杂症:为何我始终没有办法禁止掉来自192.168.49.0/24的流量,以下两种方式都试了,下面是iptables规则

[root@centos-linux-02 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
DROP tcp -- 192.168.49.0/24 anywhere tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

[root@centos-linux-02 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
DROP tcp -- 192.168.49.0/24 anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

huskiesir的主页 huskiesir | 菜鸟二级 | 园豆:204
提问于:2018-12-27 00:33
< >
分享
所有回答(2)
0

把drop这条放在最上面,drop tcp 改为 drop all 。试一下

AYard | 园豆:436 (菜鸟二级) | 2018-12-27 09:47

可是我只想禁止192.168.49.0/24段的啊,你说的那样肯定可以禁止访问,可是都禁止掉了啊

支持(0) 反对(0) huskiesir | 园豆:204 (菜鸟二级) | 2018-12-27 22:31
0

原因找到了,编辑iptables之前,首先要iptables -F去清除默认规则表,不然会影响接下来写入的匹配。
可以这样写:
iptables -I INPUT -s 192.168.49.0/24 -p tcp --dport 22 -j DROP
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
或者:
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 192.168.49.0/24 -p tcp --dport 22 -j DROP

huskiesir | 园豆:204 (菜鸟二级) | 2018-12-28 23:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册