LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2010, 03:48 AM   #1
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
iptables port redirection woes.


Hello all,

There is this server where in I want to use port redirection using iptables. For port redirection I have used nat table with PREROUTING chain and REDIRECT option.
Like:
Code:
iptables -t nat -A PREROUTING -p tcp --dport pop3 -j REDIRECT --to-port 8110
It just does not work. I have tried to redirect other ports as well but nothing works.
Where am I missing?

iptables -t nat -L -v output:

Code:
Chain PREROUTING (policy ACCEPT 1111 packets, 83779 bytes)
 pkts bytes target     prot opt in     out     source               destination        
    0     0 REDIRECT   tcp  --  any    any     anywhere             anywhere            tcp dpt:pop3 redir ports 8110
    1    48 REDIRECT   tcp  --  any    any     anywhere             anywhere            tcp dpt:smtp redir ports 8110
 
Old 06-17-2010, 05:16 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by linuxlover.chaitanya View Post
Hello all,

There is this server where in I want to use port redirection using iptables. For port redirection I have used nat table with PREROUTING chain and REDIRECT option.
Like:
Code:
iptables -t nat -A PREROUTING -p tcp --dport pop3 -j REDIRECT --to-port 8110
It just does not work. I have tried to redirect other ports as well but nothing works.
Where am I missing?

iptables -t nat -L -v output:

Code:
Chain PREROUTING (policy ACCEPT 1111 packets, 83779 bytes)
 pkts bytes target     prot opt in     out     source               destination        
    0     0 REDIRECT   tcp  --  any    any     anywhere             anywhere            tcp dpt:pop3 redir ports 8110
    1    48 REDIRECT   tcp  --  any    any     anywhere             anywhere            tcp dpt:smtp redir ports 8110


do you have an INPUT rule that is allowing port 110?
are you allowing INPUT to port 8110?

You need to paste ALL of your iptables rules
 
Old 06-17-2010, 05:45 AM   #3
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
Yes, I am allowing all the ports that I need. The incoming ports and the ports to which I need to redirect, are open and accepting the connections.
I am not exactly a newbie so I do not need a spoon fed solution, just direction where I should be looking. I am out of my wits now. I can not see anything.
 
Old 06-18-2010, 05:31 AM   #4
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by linuxlover.chaitanya View Post
Yes, I am allowing all the ports that I need. The incoming ports and the ports to which I need to redirect, are open and accepting the connections.
I am not exactly a newbie so I do not need a spoon fed solution, just direction where I should be looking. I am out of my wits now. I can not see anything.
I dont know then...

Code:
iptables -I  PREROUTING -t nat -p tcp   --dport 110 -j REDIRECT --to-ports 25
worked fine when i tested...
Only solution now then is to create a chain for anything that isnt allowed to be dropped, and then see what, if anything is being added to this log when you attempt connections
 
Old 06-18-2010, 06:42 AM   #5
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
I am now putting up a test machine with similar packages but running Ubuntu server rather than CentOS5.5. Most of the packages that are not default would be installed with apt. That might help a bit. I do not know.
I also have asked one of my friends to make a test scenario at his office and see if he also has issues with port redirection. Will receive some inputs from him as well. Till then I am putting my hope behind my new machine. Will keep you posted.
Thanks for looking and trying. I know this is just a small uncomplicated rule that should not have given too much trouble. But it seems CentOS5 is behaving like this.
 
Old 06-18-2010, 07:19 AM   #6
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by linuxlover.chaitanya View Post
I am now putting up a test machine with similar packages but running Ubuntu server rather than CentOS5.5. Most of the packages that are not default would be installed with apt. That might help a bit. I do not know.
I also have asked one of my friends to make a test scenario at his office and see if he also has issues with port redirection. Will receive some inputs from him as well. Till then I am putting my hope behind my new machine. Will keep you posted.
Thanks for looking and trying. I know this is just a small uncomplicated rule that should not have given too much trouble. But it seems CentOS5 is behaving like this.
Hmm..ok.

I tested on centos.
what i did.

10.220.241.18 is the source ip. (windows)
10.220.241.237 is the destination (centos 5.3)

on 10.220.241.237


Code:
iptables -I INPUT -s 10.220.241.18 -j ACCEPT
iptables -I  PREROUTING -t nat -p tcp   --dport 110 -j REDIRECT --to-ports 25
then i started up postfix and made sure it listened on the external address as by default it starts up and listens on localhost.


on 10.220.241.18

Code:
telnet 10.220.241.237 110

and this gives me

Code:
220 servername ESMTP Postfix
 
Old 06-18-2010, 07:22 AM   #7
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by centosboy View Post
Hmm..ok.

I tested on centos.
what i did.

10.220.241.18 is the source ip. (windows)
10.220.241.237 is the destination (centos 5.3)

on 10.220.241.237


Code:
iptables -I INPUT -s 10.220.241.18 -j ACCEPT
iptables -I  PREROUTING -t nat -p tcp   --dport 110 -j REDIRECT --to-ports 25
then i started up postfix and made sure it listened on the external address as by default it starts up and listens on localhost.


on 10.220.241.18

Code:
telnet 10.220.241.237 110

and this gives me

Code:
220 servername ESMTP Postfix


2 main things to note.

The host you are testing from is allowed the correct access to the destination.

The redirect ports are actually listening on the correct interface and this is proved by connecting directly to them.
 
Old 06-24-2010, 12:16 AM   #8
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
Sorry for being late. Was on holiday for friend's wedding.
I can see that the ports are listening and can telnet. I am still not sure why this is not working.
Let me see.
And if nothing works, then I will probably put some ebox appliance or something.
Will keep you posted about it. Todays the first day at office after holiday. Will need some time.
Thanks for taking interest anyhow.
 
Old 06-24-2010, 02:23 AM   #9
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
This is from the local machine:

Code:
[root@squid etc]# telnet 192.168.2.1 pop3
Trying 192.168.2.1...
Connected to squid.ib.com.local (192.168.2.1).
Escape character is '^]'.
220 squid.ib.com.local ESMTP Sendmail 8.13.8/8.13.8; Thu, 24 Jun 2010 12:38:53 +0530
^]
Interesting. It is redirecting the connections from pop to smtp. But not from pop to 8110?
 
Old 06-24-2010, 02:52 AM   #10
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
can you get to 8110 directly from remote machine?
 
Old 06-24-2010, 05:46 AM   #11
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
I would say yes.

Code:
chaitanya@IBDesk06:~$ telnet 192.168.2.1 8110
Trying 192.168.2.1...
Connected to 192.168.2.1.
Escape character is '^]'.
Connection closed by foreign host.
 
Old 06-25-2010, 02:28 AM   #12
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by linuxlover.chaitanya View Post
I would say yes.

Code:
chaitanya@IBDesk06:~$ telnet 192.168.2.1 8110
Trying 192.168.2.1...
Connected to 192.168.2.1.
Escape character is '^]'.
Connection closed by foreign host.
i meant from this same machine

Code:
[root@squid etc]#

best to do all testing from the same machine....
is there anything showing up in the drop logs - (assuming you have set up logging with iptables) when an attempt to port redirect fails?
 
Old 06-25-2010, 05:44 AM   #13
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
It is accepting connections even on the same machine. I am trying this on a test machine. So it will take some time before I can do that. Will keep you posted.
 
Old 06-28-2010, 12:57 AM   #14
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Original Poster
Rep: Reputation: Disabled
Well let me give some more information that I forgot till now. This machine that I am trying port forwarding is behind a ADSL modem and D-Link wireless router.
So you could take it as:
Code:
Adsl modem ---> Wireless router -----> my system ------>lan
The wireless router does have some ethernet ports for wires connection and can act as a hub.
If this information makes difference. Though it should not. I have tried connecting directly to the adsl modem.

Last edited by linuxlover.chaitanya; 06-28-2010 at 01:00 AM. Reason: typo
 
Old 06-28-2010, 03:35 PM   #15
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by linuxlover.chaitanya View Post
Well let me give some more information that I forgot till now. This machine that I am trying port forwarding is behind a ADSL modem and D-Link wireless router.
So you could take it as:
Code:
Adsl modem ---> Wireless router -----> my system ------>lan
The wireless router does have some ethernet ports for wires connection and can act as a hub.
If this information makes difference. Though it should not. I have tried connecting directly to the adsl modem.
well i must admit...my testing was with 3 machines on my lan, 2 running centos 5.3 and 1 with windows.
i guess a process of elimination determines if it is any devices in the network causing the issue or iptables itself (which i doubt)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with iptables, I think, to allow a port redirection for rdp clients wpflum Linux - Networking 2 01-29-2010 08:26 AM
iptables - redirection port from alias - problem dlugasx Linux - Networking 1 06-25-2009 03:19 AM
Port redirection with iptables not working as expected. Eric-Mtl Linux - Networking 1 08-16-2007 07:42 AM
Port redirection, iptables, apache questions? sarajevo Linux - Security 2 09-22-2006 06:02 AM
Iptables, Port redirection... and I'm a nimrod finegan Linux - Networking 3 09-14-2003 01:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration