I run ssh on port 5678.
For my source IP address 1.2.3.4 - I want to connect on port 22 and have firewalld port forward to 5687.
No other source IP addresses get port forwarding.
What firewall-cmd line would I type to achieve this ?
I run ssh on port 5678.
For my source IP address 1.2.3.4 - I want to connect on port 22 and have firewalld port forward to 5687.
No other source IP addresses get port forwarding.
What firewall-cmd line would I type to achieve this ?
You just create a firewalld rule to allow the traffic and then you configure NAT for the traffic. Essentially you are creating an ACL to determine what traffic is allowed in and then are you making a NAT rule to say that the allowed traffic should be translated.
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
How to open port for a specific IP address with firewall-cmd on CentOS?
Figured it out:
CUSTOMPORT=$(netstat -tlpn | grep 0.0.0.0.*ssh | cut -d: -f2 | cut -f1 -d\ )
SOURCE_IP=1.2.3.4
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=\"${SOURCE_IP}\" forward-port port=\"22\" protocol=\"tcp\" to-port=\"${CUSTOMPORT}\""
firewall-cmd --reload