I want to choose my source address

I have a linux (kernel 2.4) machine with several network interfaces:

interface  IP address
lo         127.0.0.1
lo:0       10.0.3.9
ppp0       dynamic
ppp1       10.2.3.9
ppp2       10.252.3.9

Normally, when a program does something outgoing in the IP world, it chooses a source IP address from the interface that will route to the destination IP address. This causes problems for me, because ppp1 and ppp2 are unreliable, so a TCP connection may die because the machine suddenly no longer has the address 10.2.3.9, regardless of whether I can set up routing tables to get the packet to the right machine.

Instead, I want to have the source address chosen from the following table:

destination   source
10.x.x.x      10.0.3.9
127.x.x.x     127.0.0.1
x.x.x.x       dynamic (ppp0)

Is this possible under linux?

(Sorry, I only have 75 points at the moment - until next month)
mnw21camAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
The--CaptainConnect With a Mentor Commented:
Completely, even very, possible.  Check out the docs for the 'ip rule' command which is part of the iproute2 tools for linux.

Let me know if you need specific examples.

Ahh, the joys of policy routing - and to think folks shell out mucho bucks for cisco stuff when linux can do the same thing.

Cheers,
-Jon
0
 
mnw21camAuthor Commented:
Had a good long search yesterday after posting the question, and I think I have found the solution - and yes, it is iproute2.

Indeed - I have just been able to set it up so that it works. Now I just need to put it all into a script.
0
 
mnw21camAuthor Commented:
Though it took me absolutely ages to find any documentation at all on iproute2.

For anyone who is interested, it's available at http://snafu.freedom.org/linux2.2/docs/ip-cref/ip-cref.html
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
The--CaptainCommented:
Yeah, the docs kinda suck - be glad your solution doesn't call for the use of 'tc' traffic-shaping command (another super-cool, horribly documented tool in the iproute2 set).

IIRC, the advanced routing howto talks about iproute2 quite a bit...

Problem solved, or do you need some examples?

Cheers,
-Jon

0
 
mnw21camAuthor Commented:
Problem solved. Cheers.

I had actually been investigating tc for solving some other problems, but I'll deal with that later.
0
 
The--CaptainCommented:
BTW, the ip rule command isn't that bad - you just need to realize that you will prob want to have at least two routing tables, and use appropriate 'ip rule' commands to select between them.  You could also use fwmark as part of your criteria (in addition to the src address - actually, src address-based routing can also be realized with the appropriate use of the fwmark rule).  IMO, the biggest problem with the iproute2 tools is there are often a few different way to do what you want, but no one gives exmaples for any of them, or talks about why one way would be better than another.

-Jon

0
 
mnw21camAuthor Commented:
Problem solved. Cheers.

I had actually been investigating tc for solving some other problems, but I'll deal with that later.
0
 
The--CaptainCommented:
BTW, if you need some 'tc' examples, I think I can dig up some of those as well ('tc' is super-handy for dedicating a certain small amount of bandwidth for latency-sensitive apps like telnet or ssh).

Cheers,
-Jon

0
 
mnw21camAuthor Commented:
I only need one routing table at the moment, thank goodness, since I don't need to route according to source IP address. I only need to choose the source address I use.
0
 
mnw21camAuthor Commented:
Oh, here you go. I think I'm getting the hang of these new commands. They're not actually that bad - once you have found the doc.
0
 
The--CaptainCommented:
BTW, when you make adjustments to the routing config using 'ip rule', I've found that issuing this command:

echo 1 > /proc/sys/net/ipv4/route/flush

causes the changes to take effect immediately (don't worry - it doesn't flush the route table, just the route cache)

I've noticed that policy routing changes often take quite some time to take effect [presumably the route cache time out on its own] unless the route cache is cleared using the above command.

-Jon


0
 
The--CaptainCommented:
Glad you found your solution (and thx for the pts).

Feel free to post back here if you need additional help.

Cheers,
-Jon
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.