Linux Administrator - Forward traffic for one IP to another IP

Linux Administrator

Privacy Policy

RSS Feed

Acoustic Guitar Tips
Anna Kendrick
Beekeeping Tips
Catherine Zeta Jones
My View On Things
Cheap Auto Insurance
Cheap Places to Live
Delta Shaper
Easy Wood Projects
Felicity Jones
Free Sheet Music
Funny Clean Jokes
Healthy Carbs
Heidi Klum
Improve Your Credit
Ivory Tower Group
Keke Palmer
Linda Ronstadt
Linux Administrator
Money Spigot
Nicole Kidman
Planet Cabinet
Quality Dating Advice
Rustic Cabinets
Sacramento Hiking
Sandra Bullock
Spintax Tool
The Actress
Tristan Prettyman
Viola Davis
Who Are The Beatles

Forward traffic for one IP to another IP

Forward traffic for one IP to another IP

In some situations, the service you had on one ip address might have moved. Maybe it's something beyond your control. Or maybe, you wanted to put the service on a better, faster machine, but you couldn't move the ip address to the new machine. And, since everyone connects via the IP address and not a domain name, you're pretty much stuck in making sure that IP address continues to work. What do you do? The simple solution is to forward the traffic intended for that IP address to the new destination. You can even map the source port to a new destination port if necessary. Here's a sample script you can run on the old machine to do the trick:


# turn on ip forwarding, if it's not on already echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A PREROUTING -p tcp -d $OLDIP --dport $OLDPORT -j DNAT --to-destination $NEWIP:$NEWPORT /sbin/iptables -t nat -A POSTROUTING -p tcp --dport $OLDPORT -j MASQUERADE

Return To Main Page