Results 1 to 4 of 4
Hello! I was wondering if anyone had a solution to forwarding to a range. To elaborate, I run a daemon that is unable to handle the userload on one port, ...
- 12-16-2007 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 4
Port forwarding to random port range
Hello! I was wondering if anyone had a solution to forwarding to a range. To elaborate, I run a daemon that is unable to handle the userload on one port, so I run 25 processes on 25 different ports, port 1000 -> 1025. I would like to have one stable port number to give out however, so I would like port 800 to randomly forward to 1000 -> 1025 per connection. Any help would make my day!
- 12-16-2007 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
How about balance, a command line load balancing app.
Grab, compile and then tell it to load balance everything coming into port 800 to many localhost ports.
and so on. It goes on a round-robin rather than random, but if that is a problem you could probably hack the source to make it do exactly what you want.Code:balance 800 localhost:1000 localhost:1001 <snipped> localhost:1025
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 12-16-2007 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 4
Almost!
Excellent suggestion Chris! It does work however the only problem is now I lose the users IP address when it hits the daemon.
Any thoughts on how to do this and keep the users IP address in tact?
Thank you for your help!
- 12-17-2007 #4Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
OK, scratch the easy option.
Plan B is use some of the load balancing in the firewall. This may not work, some of these features are pretty new, my distro won't do it without some patching for example.
Anyway, take a look at this advanced iptables article.
The interesting part would look like this:
This should set things up for four ports if you adapt the obvious points to match your setup.Code:iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 800 -m state --state NEW -m nth --counter 0 --every 4 --packet 0 -j DNAT --to-destination 192.168.0.5:1000 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 800 -m state --state NEW -m nth --counter 0 --every 4 --packet 1 -j DNAT --to-destination 192.168.0.6:1001 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 800 -m state --state NEW -m nth --counter 0 --every 4 --packet 2 -j DNAT --to-destination 192.168.0.7:1002 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 800 -m state --state NEW -m nth --counter 0 --every 4 --packet 3 -j DNAT --to-destination 192.168.0.8:1003
If you get any errors then post them here and we'll see what we can make of them.
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.


Reply With Quote
