Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Problem with port forwarding
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
sbrenneis
n00b
n00b


Joined: 08 Dec 2006
Posts: 9

PostPosted: Fri Jun 19, 2009 2:49 am    Post subject: Problem with port forwarding Reply with quote

I have a Gentoo server that I am using for a firewall/DMZ. It has two NICsOn my LAN, I have a Fedora system that is running jboss on port 8080. I want to forward port 8080 traffic to the internal server.

I have set up the following iptables rules on the Gentoo server:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 8080 -j DNAT --to 192.168.0.101:8080
iptables -A INPUT -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 993 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport 1194 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 3690 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 10080 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 10081 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW,INVALID -j DROP

I have verified that nothing is running on port 8080 on the firewall/DMZ server, and I have verified that jboss is listening on port 8080 on the internal server. WHen i give the URL for the jboss console to my browser, it times out. I have had other people attempt to get to the URL as well.

Any ideas? I have no idea how to troubleshoot an iptables issue, as there are no logs that I know of.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23100

PostPosted: Fri Jun 19, 2009 3:15 am    Post subject: Reply with quote

Have you turned on IP forwarding? What is the output of iptables-save -c? Have you conducted your tests from outside? Your PREROUTING rule will only cover traffic coming from the Internet, so if you test this from inside the LAN, it will not work.

You can use the LOG target to record when traffic matches a rule. Additionally, each rule maintains counters of how many packets and bytes have matched it. You could also use tcpdump to monitor the interface to confirm that the request arrives from the Internet.
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Fri Jun 19, 2009 3:25 am    Post subject: Reply with quote

You might find these useful:

http://security.maruhn.com/
http://www.kalamazoolinux.org/presentations/20010417/conntrack.html
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
bbgermany
Veteran
Veteran


Joined: 21 Feb 2005
Posts: 1844
Location: Oranienburg/Germany

PostPosted: Fri Jun 19, 2009 6:40 am    Post subject: Reply with quote

Instead of an input rule, you need a forward rule like this:

Code:

iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to 192.168.0.101:8080
iptables -A FORWARD -p tcp --dport 8080 -d 192.168.0.101 -m state --state NEW,ESTABLISHED -j ACCEPT


in some cases, you may need RELATED as state as well.

bb
_________________
Desktop: Ryzen 5 5600G, 32GB, 2TB, RX7600
Notebook: Dell XPS 13 9370, 16GB, 1TB
Server #1: Ryzen 5 Pro 4650G, 64GB, 16.5TB
Server #2: Ryzen 4800H, 32GB, 22TB
Back to top
View user's profile Send private message
xtz
Apprentice
Apprentice


Joined: 29 Oct 2007
Posts: 181
Location: Singapore

PostPosted: Fri Jun 19, 2009 6:49 am    Post subject: Reply with quote

MASQUERADE is obsolete, a simple DNAT rule should do the work, since SNAT/DNAT work in both ways. Also, as bbgermany mentioned, it's the FORWARD table you need to modify - not the INPUT one.
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Fri Jun 19, 2009 8:44 am    Post subject: Reply with quote

the input table is for traffic destined for the firewall machine itself
the forward table is for everything else
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
sbrenneis
n00b
n00b


Joined: 08 Dec 2006
Posts: 9

PostPosted: Fri Jun 19, 2009 1:32 pm    Post subject: Reply with quote

Thanks to all. The FORWARD table entry fixed it. I appreciate the help.
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Fri Jun 19, 2009 5:40 pm    Post subject: Reply with quote

Spend some time with the resources at those links. They are very informative.
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23100

PostPosted: Sat Jun 20, 2009 2:00 am    Post subject: Reply with quote

xtz wrote:
MASQUERADE is obsolete


Not entirely. MASQUERADE has the useful property that it will automatically determine the IP address to place on the outbound packet, which can be useful if the interface is dynamically configured and could have its address changed outside your control.
Back to top
View user's profile Send private message
xtz
Apprentice
Apprentice


Joined: 29 Oct 2007
Posts: 181
Location: Singapore

PostPosted: Mon Jun 22, 2009 12:02 pm    Post subject: Reply with quote

Well, it could be done with SNAT/DNAT also (and some scripting)... but if the address changes on the fly, it surely will miss some packets, even if the scripts are run immediately. I guess MASQUERADE is better, if that is the situation. Thanks :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum