Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Nov 05, 2009 7:06 pm 
Offline
Senior Member
User avatar

Joined: Wed Jan 24, 2007 12:04 am
Posts: 90
Website: http://www.smiffysplace.com
Location: Rural South Australia
If I have a Linode with multiple IP addresses, is there any way that I can route traffic through a specific interface/IP address, on a dynamic basis?

My scenario is that I need to access a service that has a per IP queries per hour limit. The legitimate way to overcome this limit, since the providers can't be bothered to do whitelisting, is to use multiple IP addresses.

I want, therefore, to create a round-robin system whereby I can say:

query 1 - use eth0
query 2 - use eth0:1
query 3 - use eth0:2
...etcetera.

The query will be coming from a Perl programme using IO::Socket.


Top
   
 Post subject:
PostPosted: Thu Nov 05, 2009 11:11 pm 
Offline
Senior Member

Joined: Fri Dec 07, 2007 1:37 am
Posts: 385
Location: NC, USA
Maybe use IO::Socket::INET and set LocalAddr?

I'm not a perl programmer, so just guessing.


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 12:31 am 
Offline
Senior Member
User avatar

Joined: Wed Jan 24, 2007 12:04 am
Posts: 90
Website: http://www.smiffysplace.com
Location: Rural South Australia
Thanks - I'll see if that works.

Failing that, someone (via another source) has suggested a trick using iptables.

I'll post my results in case anyone else comes up against the same issue.


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 1:56 am 
Offline
Senior Member

Joined: Mon Feb 02, 2009 1:43 am
Posts: 67
Website: http://fukawi2.nl
Location: Melbourne, Australia
Code:
iptables -t nat -A POSTROUTING -m statistic --mode random --probability 0.5 -m state --state NEW -j SNAT --to-source X.X.X.X
iptables -t nat -A POSTROUTING -m state --state NEW -j SNAT --to-source Y.Y.Y.Y


Each new outgoing connection will "randomly" be Source NAT'ed to either X.X.X.X or Y.Y.Y.Y

This is assuming you have 2 IP addresses. If you have 3, you'll need to:
1) duplicate the 1st rule
2) adjust the source IP in the new rule
3) adjust all instances of 0.5 to be 0.333333333333 etc

You may wish to include a -d argument in there too so only outgoing connections to the host that's causing you problems is randomized ;)


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 2:15 am 
Offline
Senior Member
User avatar

Joined: Wed Jan 24, 2007 12:04 am
Posts: 90
Website: http://www.smiffysplace.com
Location: Rural South Australia
Cool - that's one for the "useful" information file!

Cheers for that.


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 2:18 am 
Offline
Senior Member

Joined: Mon Feb 02, 2009 1:43 am
Posts: 67
Website: http://fukawi2.nl
Location: Melbourne, Australia
I love the random module, especially when my friend leaves his firewall logged in as root and unattended....

Code:
iptables -I FORWARD -i eth1 -o eth0 -m statistic --mode random --probability 0.5 -j DROP

:P


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 12:06 pm 
Offline
Senior Member

Joined: Sat Mar 28, 2009 4:23 pm
Posts: 415
Website: http://jedsmith.org/
Location: Out of his depth and job-hopping without a clue about network security fundamentals
fukawi2 wrote:
Code:
iptables -t nat -A POSTROUTING -m statistic --mode random --probability 0.5 -m state --state NEW -j SNAT --to-source X.X.X.X
iptables -t nat -A POSTROUTING -m state --state NEW -j SNAT --to-source Y.Y.Y.Y


Each new outgoing connection will "randomly" be Source NAT'ed to either X.X.X.X or Y.Y.Y.Y

That's really interesting. Didn't know about statistic.

_________________
Disclaimer: I am no longer employed by Linode; opinions are my own alone.


Top
   
 Post subject:
PostPosted: Fri Nov 06, 2009 5:09 pm 
Offline
Senior Member
User avatar

Joined: Mon Dec 10, 2007 4:30 pm
Posts: 341
Website: http://markwalling.org
fukawi2 wrote:
code]iptables -I FORWARD -i eth1 -o eth0 -m statistic --mode random --probability 0.5 -j DROP[/code]


If this was StackExchange, I'd upvote you.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group