Linux - Security This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
09-26-2006, 12:53 PM
|
#1
|
LQ Newbie
Registered: Feb 2003
Location: Seattle, WA
Posts: 16
Rep:
|
iptables port forwarding issue
I am trying to port forward all connections to our WAN side IP address using port 81 to an internal web server listening on port 80. The two statements I'm using below do work but I am wondering two things:
1) Is the forwarding statement necessary?
2) If the forwarding statement is necessary, should it be forwarding port 80 or port 81?
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 81 -j DNAT --to 192.168.0.35:80
iptables -A FORWARD -p tcp -i eth0 -d 192.168.0.35 --dport 80 -j ACCEPT
Sometimes I get confused on how a packet travels through the firewall. Thanks in advance.
|
|
|
09-26-2006, 02:10 PM
|
#2
|
Member
Registered: Sep 2005
Location: New delhi
Distribution: RHEL 3.0/4.0
Posts: 777
Rep:
|
Quote:
Originally Posted by Garak
I am trying to port forward all connections to our WAN side IP address using port 81 to an internal web server listening on port 80. The two statements I'm using below do work but I am wondering two things:
1) Is the forwarding statement necessary?
2) If the forwarding statement is necessary, should it be forwarding port 80 or port 81?
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 81 -j DNAT --to 192.168.0.35:80
iptables -A FORWARD -p tcp -i eth0 -d 192.168.0.35 --dport 80 -j ACCEPT
Sometimes I get confused on how a packet travels through the firewall. Thanks in advance.
|
Ans 1: Forwarding rules are'nt necesary if your default forward policy isnt DROP or any other FORWARD rule isnt blocking these particular packets. Anyhow if any packet isnt meant for your box.. it goes through PREROUTING -> FORWARD -> POSTROUTING & hence a block at FORWARD could stop these packets to further traverse.
Ans 2: Forwarding port 80 or 81 is a dependant situation on what you require & is also dependant on what is your existing FORWARD policy & other rules. e.g. If i have my FORWARD policy as DROP, then i would need to allow them biredirectionally with two rules. Like in your case, i got to allow DPORT 80 in @ FORWARD & either established/related packets back OUT or sport 80 BACK.
I hope this might clear your some confusion.
You could get good piece of information about NATing, iptables port forwarding here at http://amitsharma.linuxbloggers.com/portforwarding.htm
__________________
With best regards,
Amit..
--
Quote:
Originally Posted by Albert einstein
Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world.
|
--
RSYNC tutorial : http://www.amitsharma.linuxbloggers.com/how_to_rsync.htm
FIND command tutorial : http://amitsharma.linuxbloggers.com/how_to_find.htm
Samba tutorial : http://www.amitsharma.linuxbloggers.com/how_to_samba.htm
Port forwarding tutorial: http://amitsharma.linuxbloggers.com/portforwarding.htm
Last edited by amitsharma_26; 09-26-2006 at 06:04 PM.
|
|
|
09-26-2006, 02:31 PM
|
#3
|
Senior Member
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658
Rep:
|
Quote:
1) Is the forwarding statement necessary?
|
If the packet will be getting sent to some other host, then you will need a forwarding rule (or policy) to accept the packet.
Quote:
2) If the forwarding statement is necessary, should it be forwarding port 80 or port 81?
|
The packet will be handled by the FORWARD chain after it has been processed by the nat table (where PREROUTING happens). So if you are altering the dest port in PREROUTING, then when the packet hits the FORWARD chain it will have the new port number (80)
Quote:
Sometimes I get confused on how a packet travels through the firewall.
|
http://iptables-tutorial.frozentux.n...ERSINGOFTABLES
|
|
|
09-26-2006, 03:00 PM
|
#4
|
LQ Newbie
Registered: Feb 2003
Location: Seattle, WA
Posts: 16
Original Poster
Rep:
|
Thanks for the info guys. That does clear it up. My default policies are set to DROP for all chains so I'm leaving the forwarding rule in. I also hadn't thought about the destination port being changed before the next chain so that clears up question two for me. Thanks for the help.
|
|
|
09-26-2006, 03:18 PM
|
#5
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
Quote:
Originally Posted by Garak
My default policies are set to DROP for all chains
|
that's a very good policy (pun intended)...
Quote:
so I'm leaving the forwarding rule in
|
cool, just remember that you'll need a rule for packets which are going back to the client from the server... you can do it like this (using stateful packet filtering):
Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 81 \
-j DNAT --to 192.168.0.35:80
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.0.35 --dport 80 \
-m state --state NEW -j ACCEPT
also notice how i made the FORWARD rule a little bit more specific by specifying the outgoing interface for the packet... being as specific as you can is also a good policy...
just my ...
Last edited by win32sux; 09-26-2006 at 03:26 PM.
|
|
|
09-29-2006, 04:20 PM
|
#6
|
Member
Registered: Apr 2004
Location: east midlands, england
Distribution: Ubuntu 9.04
Posts: 56
Rep:
|
Useful information chaps, but it's not working for me, trying to do much the same thing.
I'm doing the following:
Code:
iptables -F
iptables -t nat -A PREROUTING -p tcp -i lo --dport 3306 -j DNAT --to 192.168.7.8
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -i lo -o eth1 -d 192.168.7.8 --dport 3306 -m state --state NEW -j ACCEPT
.. to forward port 3306 (mysql) to a separate mysql server, but it's not happening sadly. I've tested by doing telnet localhost 3306 but I just get a connection refused message, whereas I'd expect to get the same gibberish response from mysqld that telnet 192.168.7.8 3306 gives.
I've checked that port fowarding is enabled:
[root@www root]# cat /proc/sys/net/ipv4/ip_forward
1
[root@www root]#
.. any clues, anyone?
|
|
|
09-29-2006, 04:34 PM
|
#7
|
Member
Registered: Sep 2005
Location: New delhi
Distribution: RHEL 3.0/4.0
Posts: 777
Rep:
|
Quote:
Originally Posted by slimjim
Useful information chaps, but it's not working for me, trying to do much the same thing.
I'm doing the following:
Code:
iptables -F
iptables -t nat -A PREROUTING -p tcp -i lo --dport 3306 -j DNAT --to 192.168.7.8
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -i lo -o eth1 -d 192.168.7.8 --dport 3306 -m state --state NEW -j ACCEPT
.. to forward port 3306 (mysql) to a separate mysql server, but it's not happening sadly. I've tested by doing telnet localhost 3306 but I just get a connection refused message, whereas I'd expect to get the same gibberish response from mysqld that telnet 192.168.7.8 3306 gives.
I've checked that port fowarding is enabled:
[root@www root]# cat /proc/sys/net/ipv4/ip_forward
1
[root@www root]#
.. any clues, anyone?
|
use this..
Code:
iptables -t nat -A OUTPUT -p tcp --dport 3306 -j DNAT --to 192.168.7.8
__________________
With best regards,
Amit..
--
Quote:
Originally Posted by Albert einstein
Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world.
|
--
Port forwarding tutorial: http://amitsharma.linuxbloggers.com/portforwarding.htm
|
|
|
09-29-2006, 05:31 PM
|
#8
|
Member
Registered: Apr 2004
Location: east midlands, england
Distribution: Ubuntu 9.04
Posts: 56
Rep:
|
Hmm, progress! Thanks for that!
I can now telnet to localhost 3306 and go through to the mysql server. Unfortunately the webpage hosted by the server gives an error, where it didn't with a local mysqld running ..
Code:
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var2/copied/home/httpd/vhosts/propertysalesonline.com/httpdocs/Scripts/PHP/dataconnect.php on line 2
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var2/copied/home/httpd/vhosts/propertysalesonline.com/httpdocs/Scripts/PHP/dataconnect.php on line 2
Couldn't make connection.
however that's probably for a different topic, unless someone has a quick answer!
Many thanks,
James
|
|
|
All times are GMT -5. The time now is 12:01 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|