[SOLVED] correct/safe iptables rules for redirecting port 80 to 8080
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
correct/safe iptables rules for redirecting port 80 to 8080
I am setting up tomcat server on my Centos 5.5 machine. I've been advised to run tomcat on 8080 as non root user and redirect traffic to it from port 80.
I searched and found the following iptables commands for this:
I have a doubt:
Tomcat is not accessible via port 80 without the second command. But the second command opens 8080 and makes it accessible over the internet (tomcat is accesible via both: www.<website>.com and http://<ip address>:8080). This doesn't seem right. Is there some simple (iptables) way to redirect traffic "internally" from port 80 to 8080 without having to open 8080 to the internet.
BTW, why can't you just make it listen on port 80 in order to avoid all of this?
I don't want to run tomcat on port 80 because that would have to be done as root and I want to avoid logging in as root regularly for the administration, testing, deployment etc.
For someone who reads this later: I tried a slight variation of the iptables mangle command mentioned in post linked above and it restricts access to 8080 from outside/internet while allowing the redirects from port 80.
Code:
iptables -t mangle -A PREROUTING -p tcp --dport 8080 -j MARK --set-mark 1
iptables -I INPUT -m mark --mark 1 -j DROP
I had to use -I in second rule instead of -A, as in the post linked above, this might depend on sequence of rules in your iptables
Can someone comment on how good a solution this is for simple deployment of tomcat on 8080?
I don't want to run tomcat on port 80 because that would have to be done as root and I want to avoid logging in as root regularly for the administration, testing, deployment etc.
That's a good reason IMO.
That said, isn't it kind of odd that the program doesn't have root privilege dropping as a feature? I've never used Tomcat so I don't really know the particulars. In any case, I understand why you're doing this now – and running daemons as root is almost always a terrible idea.
Quote:
Can someone comment on how good a solution this is for simple deployment of tomcat on 8080?
I can't comment on Tomcat, but the iptables technique seems pretty solid to me. I've used it myself, and have recommended it to other members who report satisfactory results. See this thread, for example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.