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 11-28-2012, 09:52 AM   #1
palt
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Rep: Reputation: Disabled
routing based on port


Hello!

I have 2 internet connections on my Linux PC. One is through eth0 interface and one is through usb0 interface. Default gateway is reachable through eth0.
There is my routing table
Code:
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     0      0        0 usb0
192.168.12.0    *               255.255.252.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1000   0        0 eth0
default         192.168.12.129  0.0.0.0         UG    0      0        0 eth0
My eth0 IP is addr: 192.168.12.161 Mask:255.255.252.0
and usb0 IP is addr:192.168.0.201 Mask:255.255.255.0

I want that my HTTP connections work through usb0 interface. I have read this post http://www.linuxquestions.org/questi...not-ip-486823/ and did the same settings (I use http proxy with port 3128):
Code:
echo "200	http.out" >> /etc/iproute2/rt_tables
/sbin/ip route add default via 192.168.0.202 dev usb0 table http.out
ip rule add fwmark 1 table http.out

iptables -t mangle -A OUTPUT -p tcp --dport 3128 -j MARK --set-mark 1
After this I can see that HTTP output traffic with source address 192.168.12.161 (address of my eth0 interface) starts to go through usb0 interface. But I can't esteblish connection with http server. When my client sends [SYN] packet the server answer by [SYN,ACK] packet. But this answer doesn't reach my client. I have traced this [SYN,ACK] packet in the netfilter tables and found that this packet are losed after the chain mangle:PREROUTING. So it means this packet doesn't come into the mangle:INPUT chain. In the mangle:PREROUTING chain I have no any rules to drop this packet and default policy is ACCEPT.

And I don't know why [SYN,ACK] packet are losed after the mangle:PREROUTING. But I think the problem is that [SYN,ACK] packet comes through usb0 interface (with ip address 192.168.0.201) but destination address of packet is address of my eth0 interface (192.168.12.161). And the kernel doesn't know how to route this packet. So how can I pass this packet to the mangle:INPUT chain?
Thanks a lot for any help!
 
Old 11-29-2012, 04:25 AM   #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
I've not needed to do this myself, so there may be a subtler thing I'm not aware of, as I wouldn't have thought that LOCAL traffic would have a source IP until the route is identified, so should pick up usb0's IP from the get go (although how can it traverse iptables without it in the first place... maybe that explains it..) but clearly the traffic leaving usb0 needs to have the IP for usb0. As such you should be able to just add a MASQUERADE target on the outbound traffic:

# iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
 
Old 11-29-2012, 05:02 AM   #3
palt
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Chris, thanks for reply. I have also tryed to do masquerading on usb0 output but it didn't help Also I set rp_filter into 0 (echo 0 >/proc/sys/net/ipv4/conf/all/rp_filter) but it still doesn't work.
 
Old 11-29-2012, 05:22 AM   #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
what happens to the source with the MASQ entry? what does tcpdump show leaving the interface?
 
Old 11-29-2012, 06:16 AM   #5
palt
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
As I can see it is solved by swithcing of Reverse Path Filtering. At firts I tryed to do it for all of interfaces by command
Code:
echo 0 >/proc/sys/net/ipv4/conf/all/rp_filter
and it didn't help. Then I tryed to do it for usb0 interface by command
Code:
echo 0 >/proc/sys/net/ipv4/conf/usb0/rp_filter
and it helped.
Then I tryed to investigate what was realy helped, the firts or the second command. And I found that only both of these commands solve my issue.
 
Old 11-29-2012, 06:22 AM   #6
palt
LQ Newbie
 
Registered: Jul 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Chris, for your question about MASQ adresses. Source outcoming addresses and destination incoming addresses became as address of my usb0 interface.
 
  


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
Routing based on destination port rvo Linux - Networking 9 01-11-2011 09:48 AM
ip routing based on port number. hansemmanuel Linux - Networking 4 10-02-2010 12:46 AM
Port-policy based routing, not a gateway murmel Linux - Networking 0 09-13-2009 09:16 PM
Advanced routing based on outgoing port tenko20xx Linux - Networking 2 02-14-2009 11:18 AM
Port based routing neos Linux - Networking 1 09-21-2005 01:15 PM

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

All times are GMT -5. The time now is 01:13 PM.

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