LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-10-2012, 11:01 AM   #1
splinux
Member
 
Registered: Jun 2011
Location: Sri Lanka
Distribution: centos,redhat,ubuntu
Posts: 90

Rep: Reputation: Disabled
Please provide the exact IPtables rules for this situation


My web server listening Actual port number 8080

The client must access via 80 only other all ports should be closed.


-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP


-A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

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

No one should access port 8080 from client site..

how we can write the rules for this situation ?

Last edited by splinux; 05-10-2012 at 11:04 AM.
 
Old 05-10-2012, 11:37 AM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Why is Apache listening on port 8080 if you do not want connections to be accepted on that port? This doesn't make any sense to me.
 
Old 05-10-2012, 12:03 PM   #3
splinux
Member
 
Registered: Jun 2011
Location: Sri Lanka
Distribution: centos,redhat,ubuntu
Posts: 90

Original Poster
Rep: Reputation: Disabled
I like to hide my actual listening port from out site.
 
Old 05-10-2012, 12:06 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Ive only ever implemented http redirects on a network level through load balancers, never have done it with firewall rules. However, you should be able to use the following rules.
Code:
--iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
--iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
--iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
Modify the interface if needed.
 
Old 05-10-2012, 12:09 PM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
And just a heads up that your listening port can still be determined through by the client using this method.
 
Old 05-10-2012, 12:51 PM   #6
splinux
Member
 
Registered: Jun 2011
Location: Sri Lanka
Distribution: centos,redhat,ubuntu
Posts: 90

Original Poster
Rep: Reputation: Disabled
Still that port can be accessed by clients...
 
Old 05-10-2012, 01:25 PM   #7
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Yep, doesn't really add any security to the box. Actually degrades the security by opening another port.
 
Old 05-11-2012, 04:16 AM   #8
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
I agree that there is nothing to be gained, security wise, by trying to run your web server on a non standard port and then use NAT to translate it to somewhere else. Note that you could do the very same thing with a home grade router using port forwarding. There are a couple of other things that you should consider regarding your intended IPtables rules.
Code:
-P OUTPUT DROP
-A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
You need to be careful with output ports. In the case of the web server, response traffic should go out via port 80 as this was the port used to make the connection. However, most traffic will not, and you will prevent yourself from being able to do things like run updates, which will use a random, high order port. If you choose to run your port translation and obfuscation trick, your output rules will probably also prevent your web server from working as you will now mangle the port on which the response is issued. In other words, you are accepting connections on port 8080 but trying to respond on 80.

Code:
-P INPUT DROP
Be careful with input policy set to drop. You can achieve the same effect with a -A INPUT -j DROP rule as the last line of your rules with an input policy set to accept, without the risk of locking yourself out except for via a physical terminal console (not SSH).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables - Anyone using iptables with 50,000+ rules? lrirwin Linux - Networking 1 03-21-2012 06:35 PM
Restore iptables Rules that have been saved with iptables-save tiuz Linux - Security 4 08-14-2010 05:50 PM
challenging situation with iptables sank1800 Linux - Security 7 03-31-2009 11:22 PM
iptables 1.27a still loading rules after installing iptables 1.3.0 yawe_frek Linux - Software 1 06-07-2007 09:50 PM
IPTABLES - rules in /etc/sysconfig/iptables The_JinJ Linux - Newbie 6 11-20-2004 01:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration