LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-09-2012, 12:46 PM   #1
whoisit60
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Rep: Reputation: Disabled
source based routing question


Hi all,

I have the following problem:

1 Linux-host with 1 NIC 10.10.10.1

3 Gateways 10.10.10.50, 10.10.10.60, 10.10.10.70

I made the first gateway the default-gateway. IP-packets coming from the other gateways should be returned to them.
I tried
"ip rule add from 10.10.10.60 table 60"
"ip route add table 60 default via 10.10.10.60"
and
"ip rule add from 10.10.10.70 table 70"
"ip route add table 70 default via 10.10.10.70"

Unfortunately that does not work. But I have no idea why it does not work.

Any help is appreciated. Thanks.

Frank
 
Old 09-09-2012, 03:39 PM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
there are no hidden parameters, so it should work; if it does not, describe everything you did; in general, you have to define new route table, add rule(s) to route to that table and fill it out with necessary routing entries
 
Old 09-10-2012, 06:51 AM   #3
whoisit60
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
unfortunately it does not work.
The problem: ip traffic comes from outside via different routers (10.10.10.50, 10.10.10.60, 10.10.10.70). I don't know the source ip addresses of these clients. The incoming traffic to the server should be returned via the router which it came from. So what I did:

1. I added to /etc/iproute2/rt_tables "10 box1" (as an example for router 10.10.10.50)
2. I defined the default gateway for "box1" with: "ip route add default via 10.10.10.50 table box1
3. I defined the condition "if traffic comes via box1 routing table box1 with: "ip rule add from 10.10.10.50 table box1"
4. ip route flush cache

It seems that the condition "from 10.10.10.50" does not become true. But I cannot use the ip address of a real client, because I don't know them....

Who can help?

Thanks a lot
 
Old 09-10-2012, 06:45 PM   #4
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
well, in this case you know ethernet address of router that packet went through; set mark with iptables (mangle table) matching the ethernet source address and add iproute rule using fwmark selector; probably you need to mark connections as well as distinct packets
 
Old 09-11-2012, 06:23 AM   #5
whoisit60
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
thank you very much for the explanation. Yes I know the MAC-address of the "source-router" but I had never to do in detail with iptables.
So I will start reading. I appreciate any closer explanation of the steps.

Can you tell me how to mark a packet with the mac-address of the "source-router" it came from?

Thanks again

Last edited by whoisit60; 09-11-2012 at 06:36 AM.
 
Old 09-11-2012, 07:55 AM   #6
whoisit60
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
so what I did so far:

iptables -A PREROUTING -t mangle -m mac --mac-source XX:XX:XX:XX:XX:XX -j MARK --set-mark 1
ip rule add fwmark 1 table box1
(in table box1 is: "default via 10.10.10.50 dev eth0)

But again it seems that the rule-condition does not come true because it does not work....

Do you have any more ideas?

Thanks in advance.
 
Old 09-11-2012, 08:49 PM   #7
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
well, you are on the right way

mark incoming connections:
Code:
-t mangle -A PREROUTING -m mac --mac-source <...> -m state --state NEW,RELATED -j CONNMARK --set-mark <...>
then mark packets as well:
Code:
-t mangle -A -j CONNMARK --restore-mark
then your routing should work
 
Old 09-12-2012, 06:22 AM   #8
whoisit60
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi Ygrex, I really appreciate your patience but I'm stuck again. I've tried the follofwing:

ip rule add fwmark 1 table box1
iptables -A PREROUTING -t mangle -m mac --mac-source XX:XX:XX:XX:XX:XX -j MARK --set-mark 1
iptables -A PREROUTING -t mangle -m mac --mac-source XX:XX:XX:XX:XX:XX -m state --state NEW,RELATED -j CONNMARK --set-mark 1
iptables -A PREROUTING -t mangle -j CONNMARK --restore-mark

It still does not work....
 
Old 09-13-2012, 01:53 AM   #9
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
then there are should be conflicting settings; among things to check: icmp-redirects, routing cache, routing related parameters in sysctl;
also locally generated traffic does not traverse PREROUTING chain in mangle but OUTPUT
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IP Based Routing fedoraman General 2 04-21-2009 11:19 PM
name based routing brianhenson Linux - Server 3 03-21-2008 04:11 AM
Source based policy routing with one NIC ardora Linux - Networking 3 12-02-2007 08:02 AM
help with policy based routing GaijinPunch Linux - Networking 4 06-19-2005 06:35 PM
question on flow-based routing cainiao Linux - Networking 1 08-20-2004 06:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration