LinuxQuestions.org
Register a domain and help support LQ
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 08-21-2010, 12:49 PM   #1
sab0teur
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Rep: Reputation: 0
How do I route traffic from a single host through a specific interface?


I have a linux router with 2 physical ISPs and a VPN tunnel that all my traffic passes through. I would like to setup a rule to redirect all traffic from one internal IP address (10.0.0.x) through the physical link only. My current script is as follows.

iptables -F

iptables -X

echo 1 > /proc/sys/net/ipv4/ip_forward



/sbin/iptables -t nat -A POSTROUTING -o tun1 -j MASQUERADE

/sbin/iptables -A FORWARD -i tun1 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT

/sbin/iptables -A FORWARD -i eth1 -o tun1 -j ACCEPT



/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

/sbin/iptables -A INPUT -i ! lo -j DROP



/sbin/iptables -I INPUT -p tcp --dport 22 -s 10.0.0.11 -j ACCEPT

/sbin/iptables -I INPUT -p udp --dport 5000 -s 10.0.0.11 -j ACCEPT

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT



/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner debian-tor -j MARK --set-xmark 0xa

/sbin/iptables -t nat -A POSTROUTING -o eth0 -m mark --mark 0xa -j MASQUERADE



My goal is to do something similar to the mangle on the tor traffic, but for an entire host. Any input would be appreciated.
 
Old 08-21-2010, 05:50 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
iproute2 stuff would work fine

add a table /etc/iproute2/rt_tables
10 special

add a route for that table
ip route add default via <ip of gateway> table special

add a rule for your that host

ip rule add from 10.0.0.x table special

then anything from that ip will use the routing information from table special instead of the default route tables
 
Old 08-21-2010, 06:40 PM   #3
sab0teur
LQ Newbie
 
Registered: Aug 2010
Posts: 5

Original Poster
Rep: Reputation: 0
echo "10 special" >> /etc/iproute2/rt_tables
ip route add default via <gateway> table special
ip rule add from 10.0.0.x table special

works perfectly. Thanks.
 
Old 07-23-2014, 05:14 AM   #4
yujiliang
LQ Newbie
 
Registered: Jul 2010
Location: Beijing,China
Posts: 4

Rep: Reputation: 1
Question two interface same host-route packet routing

(no right create new, post here, thank you)
config as below:
ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:B47:4E
inet addr:192.168.77.7 Bcast:192.168.77.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb4:d74e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:858724 errors:0 dropped:0 overruns:0 frame:0
TX packets:52144 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:143008227 (136.3 MiB) TX bytes:6840809 (6.5 MiB)
Interrupt:67 Base address:0x2024

eth1 Link encap:Ethernet HWaddr 00:0C:29:B47:58
inet addr:192.168.88.7 Bcast:192.168.88.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feb4:d758/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:759 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:131957 (128.8 KiB) TX bytes:1872 (1.8 KiB)
Interrupt:75 Base address:0x20a4

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:14723 errors:0 dropped:0 overruns:0 frame:0
TX packets:14723 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3346612 (3.1 MiB) TX bytes:3346612 (3.1 MiB)

route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.1 192.168.88.1 255.255.255.255 UGH 0 0 0 eth1
192.168.0.1 192.168.77.1 255.255.255.255 UGH 0 0 0 eth0
192.168.77.0 * 255.255.255.0 U 0 0 0 eth0
192.168.88.0 * 255.255.255.0 U 0 0 0 eth1


i want to confirm if i bind a socket to ipaddr 192.168.77.7 and use it to send unicast packet to 192.168.0.1, the packet routing path must be socket->eth0->192.168.0.1(right way)???
can the path be socket->eth1->192.168.0.1(undesirable way)?
hope u give right routing priority, 3ks
 
  


Reply

Tags
iptables, nat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
route add with specific interface jonaskellens Linux - Networking 4 04-21-2009 12:51 AM
Add a single wireless host in route novis Linux - Wireless Networking 4 06-14-2006 11:06 AM
Need to route traffic through specific nic cards... Thaidog Linux - Networking 4 07-01-2005 07:31 PM
Route all traffic of a given type to an interface tsweatt Linux - Networking 0 09-01-2003 12:24 PM
internet to a single host through route; and samba :) Mux Linux - Networking 3 05-08-2002 12:54 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration