Linux - SecurityThis 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.
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.
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?
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?
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.
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.
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.
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...
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.
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 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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.