Using 2 linux boxs with dynamic Ip to set up Load balancing Servers

Hi all Expert!

I have a difficult question, I can't find solution though Google or any forum, so need your helo :D
I hav a website that running on a shared hosting, but now I want to use it (shared hosting) just for redirect from to Script using to redirect count how many request per time, then it redirect request to 1 of 2 linux webservers or both of them.

Problem is I already setup two web server, but I used dynamic IP, not statis IP. Can I set up Load Balance using 2 Linux Boxs with dynamic IP? and how? I'm running Ubuntu on both servers, using Apache 2.x.

Thank you for all of ur help!

Who is Participating?

Improve company productivity with a Business Account.Sign Up

edster9999Connect With a Mentor Commented:
Well.... If you have the two servers up and running and you are handling the dynamic scripting for the DNS then the changes are not done at that end at all.  Those two servers just sit there waiting for requests.
The clever stuff should be done at the shared host.

Do you want people to see the other URLs ?
If I go to and get to the shared host... do you want the url to stay the same at the top but the content to come from one of the other boxes or do you want it to change ?

If you want it to change then it is very easy to setup.  If you really want to land on that server first to count stats then you have an index page that updates the stats (adds one to a database maybe) and then does a 301 page redirection to www1.domain or www2.domain either by random or by counting connections etc.

Send out something like :
Header( "HTTP/1.1 301 Moved Permanently" );
if ($serverToUse == "1") {
    Header( "Location:" );
} else {
    Header( "Location:" );

Now if you are not so worried about counting stats you could do this far easier by using round robin cnames.  This would remove the need to have the shared servers at all -

If you don't want them to see the URL change then you could have the page on the server open an iframe with the url or www2.
Where are the two web servers you setup running?  Are they also on shared hosting?

Given your limitations of shared hosting and dynamic IP addresses, probably the best load balancing you can hope for is to configure DNS round robin (if possible)
By dynamic do you mean you have dhcp giving out internal addresses or you are using dynamic public addresses that change ?

If it is public ones then you can get round this using a service like
If it is internal addresses then reconfigure them as fixed.

You can have a single server that forwards to 2 different servers either in the same rack or elsewhere.  This does howver give you a single point of fail and means that this box still has to process every request so it is not really load balancing.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

binguyendlAuthor Commented:
I already setup 2 servers, using dynamic public Ip, 2 servers is public and anyone can access using and This is 2 servers, not shared hosting, I use dynamic dns.

Now I don't know how to use these servers to setup Load balancing, maybe when user type in address bar:, user will visite what hosted in one shared hosting, I user a php script to count how many request per time, then it redirect requests to 1 of 2 linux webservers or both of them.


Best bet.... get 2 fixed IPs.  It shouldn't cost much and then you can do simple load balancing very easily by doing a round robin DNS.
You can do this with (only with fixed IPs) or using your own dns service.

If you really can not do this then you have two options.

Option 1.   Have a third box as the landing sote and this then forwards to the other two boxes.  This will be expensive but gives you real load balancing and makes it compatible (see below).  This could be a server or a dedicated hardware load balancer.

Option 2.   Have one of the boxes serve as the landing site.  This will be on port 80 (or 443 if you are doing SSL).  When it lands there you use a script to redirect to the two boxes.   You will then need to move the real web server to a non standard port like 88 or 8080.  This will means one or two people will not be able to get to the site as they are behind proxies or using devices that will not work off port 80 (like some phones).  It also doesn't look as professional.
You could let the server go and get the traffic and pass it on using the first address but then you have lost all loadbalancing as this box is doing work for every request.

Michael WorshamInfrastructure / Solutions ArchitectCommented:
as stated above they will let you do it with static addresses but not dynamic ones
binguyendlAuthor Commented:
there is no solution with dynamic IP?
No not a real solution.  You should not use dynamic addesses for any hosting really.  If it is a little test you can use dynamic addresses just to get running but as you are talking about load balancing it is obviously more than a test so upgrade to real static IPs.  It really is the only path.
Michael WorshamInfrastructure / Solutions ArchitectCommented:
Shared hosting solutions weren't designed for high availability, load balancing or clustering solutions. If/when you are growing to that level of inbound traffic, I recommend to start looking at dedicated, co-location hosting sites where you aren't 'sharing' a server environment with someone else. Then you can look at Linux platforms like Red Hat Enterprise 5.x or CentOS 5.x which were designed for these types of environments.
binguyendlAuthor Commented:
You don't understand. I already had two servers which are running Linux, and every one can access to these boxes through Internet + 1 shared hosting.

I want this shared hosting act as a bridge to redirect requests to 1 or both 2 Linux Servers ( this 2 servers has dynamic "public IP").

@edster9999: Thank you, and explain my trouble:
I use everydns, points to server1, points to server2. I update dynamic IP by my own shell script, it's working well.

All I want is Load balancing between 2 servers using "Dynamic IP".

binguyendlAuthor Commented:
Maybe It's my solution. THank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.