mj0*_*011 2 bash iptables shell-scripting
我正在尝试设置一些规则来阻止 TCP(SSH 和 FTP)上除 21 和 22 之外的所有端口。但是当我尝试运行这个脚本时,我被锁定在我的实例之外并且无法访问它。这是脚本:
# Flush the FW Rules
iptables -F
iptables -X
# Block all traffic
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# Allow SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
# Allow FTP
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT
# Allow ICMP (ping)
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
在脚本中,它为 SSH 和 FTP 设置传入和传出请求,但为什么我无法访问它?
OUTPUT
链中的规则,您应该指定源端口匹配 ( --sport
),而不是目标端口 ( --dport
)。DROP
,OUTPUT
链中的策略并不常见。iptables-save
和iptables-apply
工具。 归档时间: |
|
查看次数: |
161 次 |
最近记录: |