Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today!
Try Our New Product Showcase!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Networking > Load balancing with Iptables and packet tagging

Forgot Password?
 Linux Networking   Hardware/Software related, Modems, Internet connection sharing, IPTables etc.

Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications




Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 01-26-2005   #1 (permalink)
Just Joined!
 
Join Date: Jan 2005
Posts: 4
Load balancing with Iptables and packet tagging

Hello everyone !

I am working on a redhat enterprise ( pretty much like a fedora core ).


I have about 20 stations/users behind an iptables firewall.

I have been able to do some sort of load balancing ( it is actually not load balancing but I don't really know how to call that ).

I have eth0 : internal network
eth1 : cable modem
eth2 : wireless card connected to a wireless router that is hooked up to a cable modem as well

So basically I have 2 external interfaces and one internal.


The idea is to have the the serious stuff: web / mail / ssh access going through eth1 and the rest ( all the junk such as bittorrent, aim ) go through eth2.


I use a combination of routing, iptables and packet "marking" to do this.

I will provide my configurations at the end of the post so that you can see what I'm doing.


I actually know that the "load balancing" works because for test purposes I decided to have the web go through eth2 and the mail through eth1 and it worked like a charm !

Now, when I have people using bittorrent for some reason traffic goes through eth2 but also eth1 .
Here's my routing rule :
$IPTABLES -t mangle -A OUTPUT -p tcp --dport 6881:6999 -j MARK --set-mark 2
$IPTABLES -t mangle -A PREROUTING -p tcp --dport 6881:6999 -j MARK --set-mark 2

6881:6999 is the range that I assume bittorrent uses.
set-mark 2 means that I'm tagging the packets with a 2 that informs the kernel to route packet to eth2.


I know that this is not something that people usually do but as anybody have an idea ?


Thanks

part of the rc.firewall
-------------
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source $INET_IP
# bittorrent redirection to eth2
$IPTABLES -t mangle -A OUTPUT -p tcp --dport 6881:6999 -j MARK --set-mark 2
$IPTABLES -t mangle -A PREROUTING -p tcp --dport 6881:6999 -j MARK --set-mark 2
$IPTABLES -A FORWARD -j ACCEPT
-----------------

script I execute to create routing rules ( aet is the wireless network, insight is my cable modem )
-------------
ip route flush cache;
ip route add default via 192.168.1.1 table aet;
ip route add default via xx.xx.xx.xxx table insight;
ip rule add fwmark 1 table insight;
ip rule add fwmark 2 table aet
----------

ip route show table aet
----
default via 192.168.1.1 dev eth2
----

ip route show table insight
---
default via xx.xx.xx.1 dev eth1
---

ip route
-------
10.0.1.0/24 dev eth0 proto kernel scope link src 10.0.1.254
192.168.1.0/24 dev eth2 proto kernel scope link src 192.168.1.110
xx.xx.xx.0/23 dev eth1 proto kernel scope link src xx.xx.xx.162
169.254.0.0/16 dev eth2 scope link
default via xx.xx.xx.1 dev eth1
------
bluntman is offline  



Reply With Quote
Old 01-26-2005   #2 (permalink)
Just Joined!
 
Join Date: Jan 2005
Location: Toronto, ON, Canada
Posts: 79
First of all a think you are doing policy routing instead of load balancing as you are
setting up rules to route data in different routes on protocol and source/destination
info basis. Load balancing is traffic shaping and bandwidth management based also on
protocol and source/destination info basis. There are also some
(commercials as far as I know) that do dynamic NAT in real time based on bandwidth
availability on the external lines.


If it works like a charm for the test you did. It should work the same way for bitorrent.
Except if some of your LAN bitorrent clients have registerd as their external IP the one
assigned to eth1 and some external bittorrent peers are looking foe them.

Are the packets you have sniffed in eth1 incoming to your LAN from
internet(SYN is from internet)?

afrolinux
afrolinux is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Implementing Detailed User-Level Auditing of UNIX & Linux Systems
Enhance regulatory compliance and troubleshooting through detailed auditing, logging and real-time monitoring of UNIX/Linux user activity.
subscribe
Linux from Scratch - Receive Your Complimentary eBook NOW!
Linux from Scratch describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the source code of software that you need.
subscribe
A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)
Getting Started with Ubuntu 10.04 (Lucid Lynx) is a comprehensive beginners guide for the Ubuntu operating system; it features comprehensive guides, How Tos and information on anything you need to know after first installing Ubuntu.
subscribe
The Incredible Guide to NEW Ubuntu (Karmic Koala)
There are a lot of people still stuck with Windows because it's the ‘easier alternative'. Linux is both cheaper and more versatile than Microsoft's operating system, but the learning curve has frightened off many people.
subscribe
The GNU/Linux Advanced Administration
The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.
subscribe
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe



All times are GMT. The time now is 02:02 AM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1