Centos7端口映射


開啟tomcat后,訪問需要加端口號8080才能訪問,在不改變tomcat默認端口號的情況下,添加nat的端口映射,將80端口映射到8080端口,即可實現不加8080訪問。

向nat表的 PREROUTING鏈 的末尾追加 “目的端口為80,映射到8080” 的表項

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

 

端口映射命令(80>8080):

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 

重啟后會失效。

保存命令:

service iptables save

centos7沒有該命令:

# service iptables save The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl. 

解決方法:
1.先執行如下命令:

systemctl stop firewalld
systemctl mask firewalld

2.安裝iptables services

yum install iptables-services

3.設置開機啟動

systemctl enable iptables 

4.重啟iptables service

systemctl restart iptables

5.執行保存配置命令

service iptables save


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM