需求场景
服务器的mysql需要对外访问,但为了安全起见,对外需使用33077端口。
实现方案
通过防火墙firewalld来实现端口转发。
过程代码
查询端口转发情况
firewall-cmd –query-masqueradefirewall-cmd –add-masquerad –permanentfirewall-cmd –reload
注意事项:一定要加–permanent参数
转发33077端口到本机的3306端口
firewall-cmd –permanent –zone=public –add-forward-port=port=33077:proto=tcp:toport=3306
注意,一定要加参数–permanent,否则不会生效。
测试
外网链接远程服务器
mysql -h147.11.16.39 -听话的绿草_user -P33077 -p 其他用法 firewall-cmd –query-masquerade # 检查是否允许伪装IPfirewall-cmd –add-masquerade # 允许防火墙伪装IPfirewall-cmd –remove-masquerade# 禁止防火墙伪装IP# 将80端口的流量转发至8080firewall-cmd –add-forward-port=port=80:proto=tcp:toport=8080# 将80端口的流量转发至firewall-cmd –add-forward-port=port=80:proto=tcp:toaddr=192.168.1.0.1192.168.0.1# 将80端口的流量转发至192.168.0.1的8080端口firewall-cmd –add-forward-port=port=80:proto=tcp:toaddr=192.168.0.1:toport=8080
vps云服务器参考端口转发:
https://www.cnblogs.com/ilvutm/p/9301919.html
48968272