Solved

I want to choose my source address

Posted on 2001-09-13
12
291 Views
Last Modified: 2010-03-18
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)
0
Comment
Question by:mnw21cam
  • 6
  • 6
12 Comments
 
LVL 16

Accepted Solution

by:
The--Captain earned 75 total points
ID: 6481814
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
 

Author Comment

by:mnw21cam
ID: 6481883
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
 

Author Comment

by:mnw21cam
ID: 6481889
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
 
LVL 16

Expert Comment

by:The--Captain
ID: 6481930
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
 

Author Comment

by:mnw21cam
ID: 6481942
Problem solved. Cheers.

I had actually been investigating tc for solving some other problems, but I'll deal with that later.
0
 
LVL 16

Expert Comment

by:The--Captain
ID: 6481944
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:mnw21cam
ID: 6481947
Problem solved. Cheers.

I had actually been investigating tc for solving some other problems, but I'll deal with that later.
0
 
LVL 16

Expert Comment

by:The--Captain
ID: 6481949
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
 

Author Comment

by:mnw21cam
ID: 6481956
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
 

Author Comment

by:mnw21cam
ID: 6481962
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
 
LVL 16

Expert Comment

by:The--Captain
ID: 6481966
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
 
LVL 16

Expert Comment

by:The--Captain
ID: 6481970
Glad you found your solution (and thx for the pts).

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

Cheers,
-Jon
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now