All of lore.kernel.org
 help / color / mirror / Atom feed
* load-balancing with netfilter: round robin or what??
@ 2003-10-06  9:59 Pedro Salazar
  2003-10-06 11:23 ` Jonathan G - Mailing List
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Pedro Salazar @ 2003-10-06  9:59 UTC (permalink / raw)
  To: netfilter

Greetings,

I pretend to load-balancing to two servers but apparently I think only
one machine is getting the requests.

These are the rules I run in iptables:

/sbin/iptables -v -P INPUT ACCEPT
/sbin/iptables -v -P OUTPUT ACCEPT
/sbin/iptables -v -P FORWARD ACCEPT
/sbin/iptables -v -t nat -A PREROUTING --dst 192.168.89.44 -p tcp \
 --dport 9000 -j DNAT --to-destination 192.168.89.158:80 \
 --to-destination 192.168.89.159:80
/sbin/iptables -v -t nat -A POSTROUTING --dst 192.168.89.158/31 \ 
-p tcp --dport 80 -j SNAT --to-source 192.168.89.44
/sbin/iptables -v -t nat -A OUTPUT -p tcp -m tcp --dport 9000 \ 
--dst 192.168.89.44 -j DNAT --to-destination 192.168.89.158:80 \
 --to-destination 192.168.89.159:80

As you can see, I have two destinations hosts, 192.168.89.158/31. The
192.168.89.44 is the gateway itself that is redirecting requests on port
9000 to the two http servers. All of them are in the same network.

However, I think only the .158 is getting the requests (I have verified
that with tcpdump).

So, what is wrong or what is needed? I supposed the requests would be
load-balanced...

I'm using a linux redhat 7.3 box with default kernel 2.4.18-3. 

thanks,
Pedro Salazar.
-- 
PS
pedro-b-salazar@ptinovacao.pt
PGP:0E129E31D803BC61



^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: load-balancing with netfilter: round robin or what??
@ 2003-10-06 22:52 George Vieira
  0 siblings, 0 replies; 10+ messages in thread
From: George Vieira @ 2003-10-06 22:52 UTC (permalink / raw)
  To: Pedro Salazar, netfilter

Round robin DNS isn't so bad, I mean www.microsoft.com ,www.ibm.com and other large sites do it so depending on the scale of your site and estimate number of hits your going to get, use a combination of round robin and possibly 2 firewalls with multiple webservers behind it (web farm)..

The only way for iptables to do it without using some sort of proxy or RRDNS is to use the p-o-m NTH patch and possibly CONNMARK to do it..

Here's a snip from a past post by Ramin Dousti which may give you some guidance..

<snip>
> Any more suggestions??? any other ideas????
Yes. CONNMARK the conn's and route them accordingly:

iptables -t nat -A POSTROUTING -o ppp0 -j SNAT --to-source <ppp0-ip-addr>
iptables -t nat -A POSTROUTING -o ppp1 -j SNAT --to-source <ppp1-ip-addr>
iptables -t nat -A POSTROUTING -o ppp2 -j SNAT --to-source <ppp2-ip-addr>
iptables -t nat -A POSTROUTING -o ppp3 -j SNAT --to-source <ppp3-ip-addr>

iptables -t mangle -A PREROUTING -m nth --every 4 --packet 1 -m state --state new  -j CONNMARK --set-mark 1
iptables -t mangle -A PREROUTING -m nth --every 4 --packet 2 -m state --state new  -j CONNMARK --set-mark 2
iptables -t mangle -A PREROUTING -m nth --every 4 --packet 3 -m state --state new  -j CONNMARK --set-mark 3
iptables -t mangle -A PREROUTING -m nth --every 4 --packet 0 -m state --state new  -j CONNMARK --set-mark 4

iptables -t mangle -A OUTPUT     -m nth --every 4 --packet 1 -m state --state new  -j CONNMARK --set-mark 1
iptables -t mangle -A OUTPUT     -m nth --every 4 --packet 2 -m state --state new  -j CONNMARK --set-mark 2
iptables -t mangle -A OUTPUT     -m nth --every 4 --packet 3 -m state --state new  -j CONNMARK --set-mark 3
iptables -t mangle -A OUTPUT     -m nth --every 4 --packet 0 -m state --state new  -j CONNMARK --set-mark 4

iptables -t mangle -A POSTROUTING -m connmark --mark 1 -j ROUTE --oif ppp1
iptables -t mangle -A POSTROUTING -m connmark --mark 2 -j ROUTE --oif ppp2
iptables -t mangle -A POSTROUTING -m connmark --mark 3 -j ROUTE --oif ppp3
iptables -t mangle -A POSTROUTING -m connmark --mark 4 -j ROUTE --oif ppp0

Haven't had the chance to test it, though.

Ramin
</snip>

Thanks,
____________________________________________
George Vieira
Systems Manager
georgev@citadelcomputer.com.au

Citadel Computer Systems Pty Ltd
http://www.citadelcomputer.com.au

Phone   : +61 2 9955 2644
HelpDesk: +61 2 9955 2698
 

> -----Original Message-----
> From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt]
> Sent: Monday, 6 October 2003 8:00 PM
> To: netfilter@lists.netfilter.org
> Subject: load-balancing with netfilter: round robin or what??
> 
> 
> Greetings,
> 
> I pretend to load-balancing to two servers but apparently I think only
> one machine is getting the requests.
> 
> These are the rules I run in iptables:
> 
> /sbin/iptables -v -P INPUT ACCEPT
> /sbin/iptables -v -P OUTPUT ACCEPT
> /sbin/iptables -v -P FORWARD ACCEPT
> /sbin/iptables -v -t nat -A PREROUTING --dst 192.168.89.44 -p 
> tcp --dport 9000 -j DNAT --to-destination 192.168.89.158:80 
> --to-destination 192.168.89.159:80
> /sbin/iptables -v -t nat -A POSTROUTING --dst 
> 192.168.89.158/31 -p tcp --dport 80 -j SNAT --to-source 192.168.89.44
> /sbin/iptables -v -t nat -A OUTPUT -p tcp -m tcp --dport 9000 
> --dst 192.168.89.44 -j DNAT --to-destination 
> 192.168.89.158:80 --to-destination 192.168.89.159:80
> 
> As you can see, I have two destinations hosts, 192.168.89.158/31. The
> 192.168.89.44 is the gateway itself that is redirecting 
> requests on port
> 9000 to the two http servers. All of them are in the same network.
> 
> However, I think only the .158 is getting the requests (I 
> have verified
> that with tcpdump).
> 
> So, what is wrong or what is needed? I supposed the requests would be
> load-balanced...
> 
> I'm using a linux redhat 7.3 box with default kernel 2.4.18-3. 
> 
> thanks,
> Pedro Salazar.
> -- 
> PS
> pedro-b-salazar@ptinovacao.pt
> PGP:0E129E31D803BC61
> 
> 
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE: load-balancing with netfilter: round robin or what??
@ 2003-10-07  9:41 Khan, Arshad
  2003-10-07  9:58 ` Pedro Salazar
  0 siblings, 1 reply; 10+ messages in thread
From: Khan, Arshad @ 2003-10-07  9:41 UTC (permalink / raw)
  To: 'Pedro Salazar'; +Cc: netfilter

how does this compare with the Linux Virtual Server project?

Arshad

-----Original Message-----
From: Pedro Salazar [mailto:pedro-b-salazar@ptinovacao.pt]
Sent: 07 October 2003 10:36
To: newkirk@newkirk.us
Cc: netfilter@lists.netfilter.org
Subject: Re: load-balancing with netfilter: round robin or what??


> But the rule performing the balancing is in OUTPUT table, and so only
> affects connections from the NAT box itself...  Also, I think your
> double --to construction is invalid, iptables accepts it but it appears
> never to work.
> 
> Try this rule:
> 
> /sbin/iptables -t nat -A PREROUTING -d 192.168.89.44 -p tcp --dport  \
> 9000 -j DNAT --to 192.168.89.158-192.168.89.159:80
> 
> It will distribute new connections 'randomly' across the DNAT ip space,
> in this case two IPs.  This isn't 'real' load-balancing, but it's a
> quick and easy substitute that is sufficient for many purposes.
> 

Apparently you have right. I changed to a simple "--to" as you said, and
now I noticed that the requests are quite "round-robin". However, the 2
"--to" have worked also but weren't so *load-balanced* as with a simple
"--to" (I verified with a large massive requests). But don't forget that
my IP addresses are sequencial and in another scenario I probably must
use the rule with 2 "--to", no?

Thanks! (to all of you)

Pedro Salazar. 
-- 
PS
pedro-b-salazar@ptinovacao.pt
PGP:0E129E31D803BC61



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-10-07  9:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-06  9:59 load-balancing with netfilter: round robin or what?? Pedro Salazar
2003-10-06 11:23 ` Jonathan G - Mailing List
2003-10-06 13:38   ` Pedro Salazar
2003-10-06 14:07     ` Pedro Salazar
2003-10-06 20:34 ` Joel Newkirk
2003-10-07  9:35   ` Pedro Salazar
2003-10-06 20:43 ` Joel Newkirk
  -- strict thread matches above, loose matches on Subject: below --
2003-10-06 22:52 George Vieira
2003-10-07  9:41 Khan, Arshad
2003-10-07  9:58 ` Pedro Salazar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.