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