LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack 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,051
Blog Entries: 2

Rep: Reputation: 93
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.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 05:39 AM.

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
Open Source Consulting | Domain Registration