如何根据源IP端口与firewalld

我在端口5678上运行ssh。

对于我的源IP地址1.2.3.4 – 我想连接到端口22,并将firewalld端口转发到5687。

没有其他源IP地址获得端口转发。

我会input什么防火墙cmd行来实现这一目标?

您只需创build一个防火墙规则来允许stream量,然后为stream量configurationNAT。 从本质上讲,您正在创build一个ACL来确定允许哪些stream量,然后您是否在制定NAT规则来说明应允许翻译stream量。

firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" \ source address="1.2.3.4/32" \ port protocol="tcp" port="22" accept" firewall-cmd --permanent --zone=public --add-forward-port=port=22:proto=tcp:toport=5678:toaddr=*private translated IP address* firewall-cmd --reload 

如何在CentOS上使用firewall-cmd打开特定IP地址的端口?

http://www.certdepot.net/rhel7-get-started-firewalld/

弄清楚了:

 CUSTOMPORT=$(netstat -tlpn | grep 0.0.0.0.*ssh | cut -d: -f2 | cut -f1 -d\ ) firewall-cmd --zone=public --permanent --query-masquerade firewall-cmd --zone=public --permanent --add-masquerade firewall-cmd --zone=public --permanent --add-rich-rule="rule family=\"ipv4\" source address=\"101.184.140.18\" forward-port port=\"22\" protocol=\"tcp\" to-port=\"${CUSTOMPORT}\"" firewall-cmd --reload