LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-12-2010, 03:18 PM   #1
adrigo
LQ Newbie
 
Registered: Oct 2007
Posts: 17

Rep: Reputation: 0
Iptables redirect ip and port


I have a server with internet and firewall and I have some pages too,
I have other server into my network where I have another web page I need redirect for this server "it is a windows 2003" with iptables when people need open this page outside of my network.
So I creat a virual Interface eth0:1 with one ip, and try redirect ip
in the windows server 2003 pages is on port 8080
so I did
iptables -t nat -A PREROUTING -p tcp -d xxx.xxx.xxx.xxx --dport 80 -j DNAT --to 172.16.0.12:8080
But when a do this and try open the page I have timeout.
I have any idea I am trying to see the logs but a found no solution
 
Old 07-12-2010, 05:26 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by adrigo View Post
I have a server with internet and firewall and I have some pages too,
I have other server into my network where I have another web page I need redirect for this server "it is a windows 2003" with iptables when people need open this page outside of my network.
So I creat a virual Interface eth0:1 with one ip, and try redirect ip
in the windows server 2003 pages is on port 8080
so I did
iptables -t nat -A PREROUTING -p tcp -d xxx.xxx.xxx.xxx --dport 80 -j DNAT --to 172.16.0.12:8080
But when a do this and try open the page I have timeout.
I have any idea I am trying to see the logs but a found no solution
Do you have IP forwarding enabled? Check with:
Code:
cat /proc/sys/net/ipv4/ip_forward
You'll also need to deal with the returning packet, otherwise it'll remain with 172.16.0.12 as the source IP address. This is typically done with a SNAT/MASQUERADE rule. Example:
Code:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
BTW, I recommend you always specify an interface match in PRE/POSTROUTING rules.

Also, your FORWARD chain must be set to allow the forwarded packets. Check with:
Code:
iptables -nvL FORWARD

Last edited by win32sux; 07-12-2010 at 05:28 PM.
 
Old 07-13-2010, 07:08 AM   #3
adrigo
LQ Newbie
 
Registered: Oct 2007
Posts: 17

Original Poster
Rep: Reputation: 0
When I use the command iptables -nvL it should appear a rule with the ip I used ?
I try to put this rule in the start of firewall script but It dont work yet.
I an reading a book it say a have to make the rule to return but the book I have is a little old
I try do this
iptables -t nat - A POSTROUTING -p tcp -s 172.16.0.12 --dport 8080 -j SNAT xxx.xxx.xxx.xxx:80
but I am not sure.
I Would like to say thanks for all help
 
Old 07-13-2010, 01:55 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I already gave you a POSTROUTING rule you can use. You haven't shown us that you have IP forwarding enabled, or what your FORWARD chain looks like. Please post the command output here. While were at it, show us the nat table setup too, with:
Code:
iptables -nvL -t nat
BTW, please use code tags for this sort of thing.
 
Old 07-13-2010, 02:56 PM   #5
adrigo
LQ Newbie
 
Registered: Oct 2007
Posts: 17

Original Poster
Rep: Reputation: 0
The result of command you ask me
thanks...

root@server1:/firewall# cat /proc/sys/net/ipv4/ip_forward
1

root@server1:/firewall# iptables -nvL -t nat
Chain PREROUTING (policy ACCEPT 160 packets, 14455 bytes)
pkts bytes target prot opt in out source destination
0 0 LOG tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4511 LOG flags 0 level 6 prefix `REDIRECIONANDO PROTCLI: '
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4511 to:172.16.0.1
1 48 LOG tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4512 LOG flags 0 level 6 prefix `REDIRECIONANDO VERSAO: '
1 48 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4512 to:172.16.0.1
0 0 LOG tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8001 LOG flags 0 level 6 prefix `REDIRECIONANDO CRM: '
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8001 to:172.16.0.12
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 200.23.15.132 tcp dpt:80 to:172.16.0.12:8080

Chain POSTROUTING (policy ACCEPT 247 packets, 17398 bytes)
pkts bytes target prot opt in out source destination
32 2659 SNAT all -- * eth0 0.0.0.0/0 0.0.0.0/0 to:200.23.15.130

Chain OUTPUT (policy ACCEPT 278 packets, 20009 bytes)
pkts bytes target prot opt in out source destination
 
Old 07-13-2010, 03:01 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Almost there. Still waiting for you to post the FORWARD chain.

Why aren't you using code tags? It's unnecessarily difficult to read this without them.
 
Old 07-13-2010, 03:23 PM   #7
adrigo
LQ Newbie
 
Registered: Oct 2007
Posts: 17

Original Poster
Rep: Reputation: 0
I am sorry but do you wanna see the rule I put in the script ?
 
Old 07-13-2010, 07:45 PM   #8
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by adrigo View Post
I am sorry but do you wanna see the rule I put in the script ?
No, what I wanted was for you to add code tags to your previous post, and also to post the output of "iptables -nvL FORWARD" (using code tags too). In any case, the rules you need look like this (assuming FORWARD policy is set to DROP):
Code:
iptables -t nat -A PREROUTING -i eth0 -p TCP -d $WINDOZE_EXTERNAL_IP --dport 80 \
-j DNAT --to $WINDOZE_INTERNAL_IP:8080

iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i eth0 -o eth1 -p TCP -d $WINDOZE_INTERNAL_IP --dport 8080 \
-m state --state NEW -j ACCEPT

iptables -t nat -A POSTROUTING -o eth0 -s $WINDOZE_INTERNAL_IP \
-j SNAT --to-source $WINDOZE_EXTERNAL_IP
When I recommended the MASQUERADE target, I had forgotten you were using an aliased IP.

Last edited by win32sux; 07-13-2010 at 07:51 PM.
 
Old 07-16-2010, 02:30 PM   #9
adrigo
LQ Newbie
 
Registered: Oct 2007
Posts: 17

Original Poster
Rep: Reputation: 0
It work now very well I was trying for the LAN and it was not working I try from the Wan and it work fine

Thanks a lot my friend.
Gods Bless you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
with iptables, how-to redirect outgoing mail from port 25 to port 587 thumbelina Linux - Networking 12 03-19-2012 08:26 AM
IPTABLES PORT TRANSLATION / REDIRECT to a different address daveginorge Linux - Newbie 2 05-07-2010 01:59 PM
debian iptables squid - redirect port 80 to port 8080 on another machine nickleus Linux - Networking 1 08-17-2006 12:59 AM
iptables port redirect/forwarding izghitu Linux - Newbie 1 02-01-2006 09:26 PM
Redirect port with iptables |DeJoTa| Linux - Networking 0 07-11-2003 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:43 PM.

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