Solved

IPTables Accept Only Redirected Packets?

Posted on 2006-11-01
4
208 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now