LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-03-2017, 05:15 PM   #1
danmartinj
Member
 
Registered: Oct 2009
Posts: 117

Rep: Reputation: 1
IPtables Filter On Connection/ Load Balancer Question


Hello all,

I have been playing with an IPtables load balancer I found from this blog: https://www.webair.com/community/sim...ables-and-nat/

Anyhow, this guy created a load balancer where he can at the gateway filter packet by packet and evenly distribute packets to any set of targets. So the code basically looks like the below and I can confirm the idea does work.

Code:
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -m state --state NEW -m statistic --mode nth --every 4 --packet 0 -j DNAT --to-destination 10.0.0.3:80

# iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -m state --state NEW -m statistic --mode nth --every 4 --packet 1 -j DNAT --to-destination 10.0.0.4:80

# iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -m state --state NEW -m statistic --mode nth --every 4 --packet 2 -j DNAT --to-destination 10.0.0.5:80

# iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -m state --state NEW -m statistic --mode nth --every 4 --packet 3 -j DNAT --to-destination 10.0.0.6:80
So my question is now I have been playing around with this idea in different ways trying to make this concept stateful which I have had no luck so does anyone have any ideas? My thoughts are I cannot use the statistics module because it appears to only filter by packet and I need something that will filter by connection so hopefully someone might have some ideas as this must be possible.

Thanks in advance,

Joe
 
Old 02-06-2017, 03:39 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,482

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
A quick read or the article would indicate that the balancing is stateful for a single connection, however as http does not necessarily maintain a stateful connection (and indeed can create multiple connections concurrently even for the same page load) the method is not really suitable for "real world" balancing.

Indeed the second sentence of the article states "In practice we would use a daemon such as HAProxy allowing IP tables to check packets before forwarding them." which is sound advice.
 
Old 02-06-2017, 08:26 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,673
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
If I'm gonna use a load balancer, I design the back-end logic so that it is not "stateful." If multiple servers can handle my traffic, I have to design things so that they can coordinate their activities properly by themselves.
 
Old 02-07-2017, 11:38 AM   #4
danmartinj
Member
 
Registered: Oct 2009
Posts: 117

Original Poster
Rep: Reputation: 1
Hey guys,

Just to close out this thread I was able to find a way to build a simple load balancer using IPtables. I basically used the initial code from my first post and added/modified the commands with CONNMARK so it can be done.

I got most of my solution from the below link which shows examples of doing similar things.
https://blog.khax.net/2009/11/28/mul...-and-iproute2/

But thanks again for your input.

R
Joe
 
  


Reply



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
IPtables Load Balancer Investigation Question danmartinj Linux - Security 1 10-06-2016 12:54 PM
Load Balancer Question aevtech Linux - Newbie 3 11-27-2013 04:25 AM
iptables load balancer kikilinux Linux - Security 2 01-03-2013 09:33 AM
Intermittent Internet Connection after Setting up load balancer phani96 Linux - Networking 1 02-25-2011 03:56 AM
IPTables question, allow only traffic from load balancer... fxRichard Linux - Security 1 11-15-2009 12:35 PM

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

All times are GMT -5. The time now is 09:59 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
Open Source Consulting | Domain Registration