LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-02-2006, 02:13 PM   #1
Xeta
LQ Newbie
 
Registered: Apr 2006
Posts: 17

Rep: Reputation: 0
Question Iptables / routing to destination address through interface


hey all,

this is the scenario, i have a squid transparent proxy set up thats working rather nicely. Now i have 4 network adapters, 3 of which connect me to the internet. My question is, is it possible to let a particular interface (network card) handle the connection to an address say yahoo.com ?

So, from the user end, they type in "yahoo.com" it goes to the squid proxy, checks the cache, goes to the iptable /route , sees that destination yahoo.com is to go through eth1.

Is that possible?


Thanks.
 
Old 05-02-2006, 02:33 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
You know... i'd just written a post that said that that was dumb and pointless and impossible. then i go away and actaully see if it is possible, and lo.. looks like it is to some extent. i'm not a great iptables fan, so i can't provide actual examples, but grepping through the iptables manpage shows that you can use a string match target and then there is the route destination to point it in a certain direction. here's a link to an OLD doc about the string match http://www.securityfocus.com/infocus/1531 and the syntax looks fairly logical, assuming it's still correct. and the route side is here: http://www.netfilter.org/patch-o-mat...om-extra-ROUTE impressive huh?
 
Old 05-02-2006, 02:44 PM   #3
Xeta
LQ Newbie
 
Registered: Apr 2006
Posts: 17

Original Poster
Rep: Reputation: 0
hmm, thanks alot for your quick response, will check it out

greatly appreciate your help
 
Old 05-02-2006, 03:36 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i will say that neither these modules appear to be part of my default fc5 kernel, but do seem to be in the source headers.
 
Old 05-03-2006, 06:14 PM   #5
Xeta
LQ Newbie
 
Registered: Apr 2006
Posts: 17

Original Poster
Rep: Reputation: 0
I played around with the netfilter extras (patch-o-matic) but couldnt get it to compile cleanly on my kernel (2.6.16.11), but i dont think the iptables will work because i already have transparent proxy set up that takes all incoming port 80 requests and forwards them to port 3128, if i put a next rule just under that it wont match it since they're gonna mathc the transparent proxy rule.

Now for squid to handle requests, it has to go through a gateway rite, now is there any table that i can manipulate to handle the outgoing connections?

Im thinkin in the direction of ip rule/ip route commands, but not too sure about this.

Any Suggestions?

Thanks.
 
Old 05-04-2006, 01:17 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well it's not squids place to decide how to route. you could set static routes on your system for different destinations, which is what i was originally going to suggest, but be clear of the levels of seperate between a proxy and a router. as for the iptables rules, if you can get the extras working, i don't see an issue, just as long as you match the right traffic, i.e. packets from your local address, i.e.g squid going out to the web with a string match for a yahoo url or whatever. note that the string match would find the url, which would never be changed in a transparent proxy.
 
Old 05-09-2006, 05:44 PM   #7
Xeta
LQ Newbie
 
Registered: Apr 2006
Posts: 17

Original Poster
Rep: Reputation: 0
Well i did some playing around and got the string matching part to work, but not the ROUTE part
for those of you who want to do this, heres what i did:

i got a source (2.6.16.5) from kernel.org
untared to folder, got a copy of iptables (1.3.5) and
untared that too, got me a copy of patch-o-matic-ng
and untared also. I ran the p-o-m (./runme extras) giving the folders with kernel source and iptables
source and apply the patch i want (ROUTE). Next, i
start a xmenuconfig and compile the kernel making sure
the "string" match option and "ROUTE" option are being
installed as modules. Compilation and install goes
fine, i reboot to the new kernel, and then install the iptables
that was patched earlier, now i test the new commands :

iptables -m string -h

which displays a little help on the string match, just to be sure its installed properly, next i try a command out:

iptables -A PREROUTING -t mangle -m string --algo bm --string "yahoo.com" -j ROUTE --gw 192.168.0.1

now the string matching works because i tried it out with a different -j option
but apparently the ROUTE target is unknown. Can anyone help me set this up
properly?

Thanks.
 
Old 05-10-2006, 03:17 PM   #8
Xeta
LQ Newbie
 
Registered: Apr 2006
Posts: 17

Original Poster
Rep: Reputation: 0
Ok so i've given up tryin to get the "-j ROUTE" to work, Instead im gonna mark the packets and use the kernel routing table to get the packets to go where i want. The problem that i have with this is that even thought the packets are being marked (I checked using "iptables -t mangle -vnL") it doesnt seem to be going through the correct route. I;ve followed this guide :

http://edseek.com/archives/2006/05/0...out-balancing/

but all traffic goes through the default route and not the marked one.

# ip rule gives:
0: from all lookup local
200: from all fwmark 0x4 lookup 201
32766: from all lookup main
32767: from all lookup default

# ip route show table 201
default via 192.168.77.2 dev eth3

the iptables command i use to mark is:
# iptables -t mangle -A PREROUTING -m string --algo bm --string "yahoo.com" -j MARK --set-mark 0×4

i've also flushed the route cache,....any help? I did some playing around with iptables and found that the packets are being marked, but dont know why they arent matching the routing table.

Thanks.


Edit : Figured out the prob was squid didnt support these marks, so changed PREROUTING chain to OUTPUT and it works fine.
Thanks all.

Last edited by Xeta; 05-11-2006 at 07:17 AM.
 
  


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
Port/Address forwarding with iptables with one network interface. Nextrastus Linux - Networking 5 09-18-2013 09:55 AM
How to routing same destination and ..... help ERBRMN Linux - Networking 2 02-23-2006 07:32 PM
iptables logging destination Strikeman Linux - Security 1 03-12-2004 12:45 PM
problem to print source address and destination address jooboo Programming 2 11-26-2003 03:24 PM
iptables - source ? destination ? From where ? Dek Linux - Networking 3 04-30-2003 11:43 PM

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

All times are GMT -5. The time now is 02:25 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