查看一个masquerade状态,查询命令如下:

firewall-cmd --query-masquerade

假如查到结果为no那么就启动它(加–permanent是永久)

firewall-cmd --add-masquerade --permanent

首先防火墙打开本机对外的端口

firewall-cmd --add-port=本机开发的端口/tcp --permanent 

接下来就是映射

firewall-cmd --permanent --add-forward-port=port=本机开放的端口:proto=tcp:toaddr=(转发到机器的IP):toport=(转发到机器的端口)

重新加载

firewall-cmd --reload

查看一下结果

firewall-cmd --list-all

如无意外映射成功需要删除的话如下:

firewall-cmd --permanent --remove-forward-port=port=本机开放的端口:proto=tcp:toaddr=(转发到机器的IP):toport=(转发到机器的端口)