Solved

IPTables Accept Only Redirected Packets?

Posted on 2006-11-01
4
232 Views
Last Modified: 2010-03-18
I am wondering if this is possible.  I would like to have port 80 be accessible to the outside world, but redirect it to other ports internally depending on source.  I want to blanket deny all ports on the server except port 80.  So basically I want to drop anything but port 80, while still allowing the redirected ports to work.  Is this possible?  I was thinking about using connection tracking?
0
Comment
Question by:efaden
  • 2
4 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 17852549
#allow forwarding of port 80
iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
#but note, that You may already have some rules on FORWARD chain, if so, use (-I) instead of (-A)
#forward port80 to inside server depending on the source (-s parameter) - replace ethX with outside interface name
iptables -t nat -A PREROUTING -i ethX -p tcp -s 1.2.3.4/24 --dport 80 -j DNAT --to ip.of.inside:80
iptables -t nat -A PREROUTING -i ethX -p tcp -s 11.22.33.44/24 --dport 80 -j DNAT --to another.ip.of.inside:8080
#default port80 connection gets gracefuly rejected
iptables -t nat -A PREROUTING -i ethX -p tcp --dport 80 -j REJECT --reject-with tcp-reset
#or redirect to inside as well
iptables -t nat -A PREROUTING -i ethX -p tcp --dport 80 -j DNAT --to some.ip.on.inside:80
0
 

Author Comment

by:efaden
ID: 17852709
Hmmmm.  I'm not sure that is what I was trying to do.  The setup is.... Computer 1 is running on 192.168.0.1.  It is set to accept all connections on lo.  I want to forward 192.168.0.1:80 to 192.168.0.1:8000 while denying all access to 192.168.0.1:8000 from anywhere other than 192.168.0.1 itself.  Does that make sense?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17852764
No.
> I want to forward 192.168.0.1:80 to 192.168.0.1:8000 while denying all access to 192.168.0.1:8000 from anywhere other than 192.168.0.1 itself
What is the point then in redirecting port80->port8000 then? Still nobody can access it...
If You forward traffic from port80 to 8000 it will actually appear on port 8000. If the port is blocked - no access.
but the rule would look like
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
Note however that on INPUT chain it will appear with destination port = 8000
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question