SFTP默认使用22端口,配置防火墙规则需根据系统类型选择工具,以下是常见方法:
Linux系统(以CentOS/Ubuntu为例)
使用firewalld(CentOS 7+默认)
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --permanent --add-service=sftp
sudo firewall-cmd --permanent --add-rich-rule='rule source address="允许的IP" port port="22" protocol="tcp" accept'
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
使用iptables
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -s 允许的IP -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j DROP
sudo service iptables save
(Ubuntu需安装iptables-persistent
)Windows系统
注意: