---
title: "Start tomcat with port 80 without Linux root user-Use iptables  mapping"
author: "caiwenhn2008"
date: "2016-05-25T17:39:52Z"
tags: []
categories: ["企业架构"]
slug: "start-tomcat-with-port-80-without-linux-root-user-use-iptables-mapping"
draft: false
lastmod: "2016-05-25T17:40:23Z"
id: 2300898
url: "https://caerun.iteye.com/blog/2300898"
---

> 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
java.net.BindException: Permission denied <null>
```



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

```java
#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
```