端口转发内网redis到公网(firewalld和iptables)
firewall转发
# 检查是否允许伪装ip:
firewall-cmd --query-masquerade
# if return no, allow masquerade
firewall-cmd --add-masquerade --permanent
# add tcp port 36379
firewall-cmd --add-port=36379/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
# add port forword
firewall-cmd --add-forward-port=port=36379:proto=tcp:toaddr=10.1.1.1:toport=6379 --permanent
firewall-cmd --reload
firewall-cmd --list-forward
iptables转发# CentOS 7 disable firewalld, enable iptables
systemctl stop firewalld
systemctl disable firewalld
yum install iptables-services -y
systemctl enable iptables
# Forward redis to public network
iptables -t nat -A PREROUTING -p tcp --dport 36379 -j DNAT --to-destination 10.1.1.1:6379
iptables -t nat -A POSTROUTING -p tcp -d 10.1.1.1 --dport 6379 -j SNAT --to-source 10.2.2.2
# Restart iptables service
service iptables save
service iptables restart
评论