Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
'Separating 2 gw functionally' problem [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
salmonix
Guru
Guru


Joined: 16 Jul 2006
Posts: 410

PostPosted: Mon Nov 30, 2009 12:10 pm    Post subject: 'Separating 2 gw functionally' problem [SOLVED] Reply with quote

Hi there,
I need some help to solve the following scenario:

Given a PCbox with 4 NICs (also a router and a firewall). They are:
eth0 - connected directly to the NET via a modem. It gets dynamic IP from the ISP and defined as default gw
eth1 - living on subnet 192.168.5.0, and also connected to the NET via a router (simply saying), and defined as gw for the subnet via 192.168.5.1 (the router)

Rest of the NICs are other LAN NICS, not important here.

Now, I would like to restrict some applications to listen to eth1 only and do traffic via that card - something like having 2 default gw: everything related to eth1 should be directed to 192.168.5.1, even if it is about reaching the outer world - eg. contacting a server out there or opening pages.
All the rest of apps should use eth0 to reach the net, as normal.
This is the present routing situation:

Quote:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.5.0 192.168.5.1 255.255.255.0 UG 0 0 0 eth1
192.168.5.0 * 255.255.255.0 U 0 0 0 eth1
10.99.40.0 * 255.255.255.0 U 0 0 0 eth5
192.168.10.0 * 255.255.255.0 U 0 0 0 pan0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth5
loopback * 255.0.0.0 U 0 0 0 lo
default 10.99.40.254 0.0.0.0 UG 0 0 0 eth5

_________________
Quis custodiet ipsos, custodes?


Last edited by salmonix on Mon Dec 07, 2009 4:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
luispa
Guru
Guru


Joined: 17 Mar 2006
Posts: 359
Location: España

PostPosted: Tue Dec 01, 2009 7:01 pm    Post subject: Reply with quote

You may try it using the "user id" and iptables mangle.

First, create a secondary routing table:
Code:
echo "200 MyTable" >> /etc/iproute2/rt_tables
ip route del 192.168.5.0/24 dev eth1 table MyTable
ip route add 0.0.0.0/0 via 192.168.5.1 table MyTable


Now, let's say you have a user which user id is 1500, then you force that each packet generated by such user will be marked with 1500, and that every packet market as such has to look first in this second routing table.

Code:
iptables -A OUTPUT -t mangle -m owner --uid-owner 1500 -j MARK --set-mark 1500 
ip rule add fwmark 1500 table MyTable


BTW, what you want is the option --pid-owner <processid>. I tried it in the past without success. Try yourself anyway, and report if you have success.

Luis
Back to top
View user's profile Send private message
salmonix
Guru
Guru


Joined: 16 Jul 2006
Posts: 410

PostPosted: Wed Dec 02, 2009 8:16 am    Post subject: Reply with quote

'm on it...
_________________
Quis custodiet ipsos, custodes?
Back to top
View user's profile Send private message
salmonix
Guru
Guru


Joined: 16 Jul 2006
Posts: 410

PostPosted: Mon Dec 07, 2009 4:08 pm    Post subject: Reply with quote

The solutions are described here:
http://linux-ip.net/html/adv-multi-internet.html
http://www.linuxquestions.org/questions/linux-networking-3/iptablesmarking-ip-rule-add-fwmark-1-table-200-ip-route-add-via-gw-table-200-500369/
An most probably this
http://lartc.org/howto/lartc.netfilter.html

I think luispa's problem is using the wrong chain : should be PREROUTING instead of OUTPUT.
_________________
Quis custodiet ipsos, custodes?
Back to top
View user's profile Send private message
luispa
Guru
Guru


Joined: 17 Mar 2006
Posts: 359
Location: España

PostPosted: Tue Dec 08, 2009 9:53 am    Post subject: Reply with quote

Hi, the problem I had was with "-m owner --pid-owner <n>" not working. Long I ago I tried it without sucess, no matter which CHAIN.

I've re-tried today but seen that this option has been removed from iptables.

Luis
Back to top
View user's profile Send private message
salmonix
Guru
Guru


Joined: 16 Jul 2006
Posts: 410

PostPosted: Tue Dec 08, 2009 12:54 pm    Post subject: Reply with quote

luispa wrote:
Hi, the problem I had was with "-m owner --pid-owner <n>" not working. Long I ago I tried it without sucess, no matter which CHAIN.

I've re-tried today but seen that this option has been removed from iptables.

Luis


Its man page states that -m owner --uid-owner etc. are valid in OUTPUT chain only and I see the 'owner' extension option in menuconfig - probably you have to explicitly mark it (2.6.2x kernel I use) and recompile the kernel. It is there at least for me.

The ideas above work partially, at least outgoing traffic is now routed to the desired destination. Unfortunately it is in OUTPUT chain and thus its source IP is set to main table default gw - so the packages go out one direction and would come back on an other, but it is silly for the apps are watching the output NIC only. (Checked with iptraf)
_________________
Quis custodiet ipsos, custodes?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum