Host administratively prohibited 问题

sftp 连接远端 server 超时,

 Wireshark 抓包,显示 Host administratively prohibited,很大程度是远端 server 防火墙问题。

解决方法1

如果是内部 server,关闭远端 server 的防火墙服务即可,

$ sudo systemctl stop firewalld.service
$ sudo systemctl disable firewalld.service

解决方法2

保持防火墙服务,调整 iptables 服务,例如,

$ sudo iptables -t filter -I INPUT -p tcp -s 192.168.2.10 --dport 14920  -j ACCEPT    # 允许源地址为 192.168.2.10 的 tcp 数据包通过 server 的 14920 端口
$ sudo iptables -t filter -I OUTPUT -p tcp --dport 14920 -j ACCEPT                    # 允许 server 的任何外发数据包通过 14920 端口 

经过上述设置后,就能临时开启 sftp 服务 (假设已设置 sftp 走 14920 端口,而不是默认的 22 端口),重启后失效

注意,CentOS 7  默认没有安装 iptables-services,要先安装,

$ sudo yum install iptables-services

查看现有规则,

$ sudo iptables -L -n

重新调整 iptables 如本例最开始两条命令,然后保存设置并重启服务,

$ sudo service iptables save
$ sudo systemctl restart iptables.service  

可查看保存的设置  /etc/sysconfig/iptables-config

===========================================

常用的设置参考,

//先允许所有,不然有可能会杯具  
iptables -P INPUT ACCEPT  
// 清空所有默认规则  
iptables -F  
// 清空所有自定义规则  
iptables -X  
// 所有计数器归0  
iptables -Z  
// 允许来自于lo接口的数据包(本地访问)  
iptables -A INPUT -i lo -j ACCEPT  
// 开放22端口  
iptables -A INPUT -p tcp --dport 22 -j ACCEPT  
// 开放21端口(FTP)  
iptables -A INPUT -p tcp --dport 21 -j ACCEPT  
// 开放80端口(HTTP)  
iptables -A INPUT -p tcp --dport 80 -j ACCEPT  
// 开放443端口(HTTPS)  
iptables -A INPUT -p tcp --dport 443 -j ACCEPT  
// 允许ping  
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT  
// 允许接受本机请求之后的返回数据 RELATED,是为FTP设置的  
iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT  
// 其他入站一律丢弃  
iptables -P INPUT DROP  
// 所有出站一律绿灯  
iptables -P OUTPUT ACCEPT  
// 所有转发一律丢弃  
iptables -P FORWARD DROP  

(完)

原文地址:https://www.cnblogs.com/gaowengang/p/14681864.html