Start tomcat with port 80 without Linux root user-Use iptables mapping 编辑

作者: wilsoncai 分类: linux 发布时间: 2018-01-06 01:04

In linux system. only root user can use the port small than 1024, so if you change tomcat port to 80 and start without root account, then you will see the following error:

java.net.BindException: Permission denied

The solution is to use iptables to map port 80 with the default port 8080

#map tomcat port:8080  to port:80 , so the external host can access tomcat via both 8080 and 80
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

#let local application to access tomcat via port 80
iptables -t nat -I OUTPUT -p tcp -o lo --dport 80 -j REDIRECT --to-ports 8080

#save mapping, so after linux box reboot, still have these port mapping
service iptables save 

#view existed port mapping
iptables -t nat --line-numbers -n -L

发表评论

电子邮件地址不会被公开。 必填项已用*标注