LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-19-2014, 11:13 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 454

Rep: Reputation: Disabled
How to redirect an IP to a new IP


Hello,

i have an CentOS (Redhat) Linux server and on it is installed OpenVZ which allows creating virtual machines there.

Now to my CentOS host server is pointed a few IP-RIPE addresses, these IPs are mentioned in several domains nameservers, i want to migrate virtual machines to another server and my question is how i can achieve that websites which domains pointing to old server will resolve and work and load from a new server? (meaning there will be redirection on server which redirect old ip request to a new IP of new server) If it would be possible, redirecting all kind of requests, but for simplicity, HTTP most important

Thank you

Last edited by postcd; 02-19-2014 at 11:15 AM.
 
Old 02-19-2014, 01:53 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
You could use a dnat rule and masquerade in iptables to do the redirect.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <new_ip>:80
iptables -t nat -A POSTROUTING -p tcp --dport 80 -d <new_ip> -j MASQUERADE

You'll have to turn on forwarding as well. Usually there is a sysctl.conf file you can turn it on permanently in (/etc/sysctl.conf). The entry will look something like net.ipv4.ip_forward=1

You can turn it on temporarily by doing: echo 1 > /proc/sys/net/ipv4/ip_forward
 
Old 02-19-2014, 02:13 PM   #3
postcd
Member
 
Registered: Oct 2013
Posts: 454

Original Poster
Rep: Reputation: Disabled
thanks, your IP tables rules should be done probably on each Virtual Machine.

i meant to do it from VM host server, but such iptables rule would need to contain probably two IPs, old and new.. each rule for each VM? Is it possible to do from host server, how such command can look like?
 
Old 02-20-2014, 09:29 AM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Those rules only need to be done on the server that originally hosted the service.

With regards to using the VM host server. If it has the original (old) ip then the rules would go on it. If those ips are externally routable then easiest would probably be to update your dns to use the new ips.

You'd need a rule for each service you were redirecting, the only thing that'd change is the port and new ip
 
  


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
redirect please Linux - Networking 5 06-22-2009 04:21 AM
redirect IP's ?? snoply Linux - Networking 1 03-26-2006 05:07 AM
redirect matt1982 Programming 2 12-20-2004 10:53 AM
Redirect wonderland Linux - Newbie 3 05-25-2004 12:50 AM
Redirect sheek Programming 1 07-25-2003 01:53 PM

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

All times are GMT -5. The time now is 03:22 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration