Skip to contentSkip to conversation

redirection

DISCUSSION xchris 3 participants 5 messages Apr 8, 2003

lore
Share & tools
lore

xchris

author
#0 lore raw

i'd like to do this:

i have 2 pc
x.y.z.1
x.y.z.2

i would like to redirect connection on port 80 of x.y.z.1 to port 80 of x.y.z.2

i tried with DNAT but when someone tries to connect it goes in timeout?

Is there a solution?

Thank you
Chris

#1 lore raw
Quoted 10 lines · xchris

i'd like to do this:

i have 2 pc
x.y.z.1
x.y.z.2

i would like to redirect connection on port 80 of x.y.z.1 to port 80 of x.y.z.2

i tried with DNAT but when someone tries to connect it goes in timeout?

Do this

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -d x.y.z.1 -j DNAT --to x.y.z.2:80

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to x.y.z.1

I use a line similar to this to reroute non-local traffic to a different web server then our local users.

Eric

author
#2 lore raw
Quoted 7 lines · Eric Joe

Do this

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -d x.y.z.1 -j DNAT --to x.y.z.2:80

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to x.y.z.1

am i wrong or i loose the original connection source address?

if i check the log in x.y.z.2 i see connections from x.y.z.1. I really need to preserve the source address.
Thank you very much
xchris

#3 lore raw

I didnt catch the fact that you need the source address. Are you tracking this for a reason? You can probably have iptables log the source address. This does in fact work, been using it for about 6 months now. Let me post my exact rules (IPs are obsfucated)

iptables -t nat -A PREROUTING -i eth0 -s 192.168.1.0/24 -p tcp --dport 80 -d 192.168.1.7 -j DNAT --to 192.168.1.7

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -d 192.168.1.7 -j DNAT --to 192.168.1.11:80
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 192.168.1.7

Regards
Eric

Signature · 3 lines
Eric Joe
Network Operations
Journey's End Internet/Computer Connection Inc
Quoted 16 lines · Eric Joe
Quoted 8 lines

Do this

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -d x.y.z.1 -j DNAT --to x.y.z.2:80

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to x.y.z.1

am i wrong or i loose the original connection source address?

if i check the log in x.y.z.2 i see connections from x.y.z.1. I really need to preserve the source address.
Thank you very much
xchris

author
#4 lore raw

----- Original Message -----
From: "Eric Joe" <[email protected]>

Quoted 4 lines

I didnt catch the fact that you need the source address. Are you tracking this for a reason? You can probably have iptables log the source address. This does in fact work, been using it for about 6 months now. Let me post my exact rules (IPs are obsfucated)

i need it because i'm trying to do a simple load balancing between 2 local servers running opennap.
(and opennap needs to know the IP address otherwise downloads dont start) thnak you

xchris