Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm having problems to create route/iptables rules for following configuration:

  1. I have an openVPN server (tun type) running on my raspberry machine at home
  2. At work i have company pc (behind proxy) that creates tunnel using openVPN to my home machine
  3. At work i have USB Wifi dongle (wlan0) connected to my company pc that should provide internet using the tunnel to machine at my home

Now i need to create rules for: 1. All traffic going via wlan0 to route to tunnel 2. Rest of the traffic route to eth0 - company network behind proxy

Default route rule at company pc (linuxmint 15) for all traffic going via eth0 - proxy:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.131.4.1 0.0.0.0 UG 0 0 0 eth0

--> that rule must stay on eth0

share|improve this question
    
Hello do you mind providing us a bit more info like the os you're using at work ? the list of your network interface ? and the IPs of your computer ? –  Kiwy Nov 28 '13 at 9:14
    
At work: linuxmint 15 eth0 : 10.131.4.74 wlan0: 172.16.1.1 tun0: 10.8.0.14 At home: raspbian running on raspberrypi tun0: 10.8.0.1 –  user53280 Nov 29 '13 at 13:48
add comment

2 Answers

So admitting that all private ip will be route to your work network, I would do something like this.

route add default gw tun0
route add 10.0.0.0/8 gw eth0
route add 172.16.0.0/12 gw eth0
route add 192.168.0.0/16  gw eth0

I do not have a linux to test this configuration but that's what it should look like I think. There's probably error in the exact synthax. but you get the idea

share|improve this answer
add comment

If you want to send traffic that comes in from wlan0 down tun0, but traffic that originates locally to go to eth0, the easiest way is to just use a separate routing table:

# enable IP forwarding
sysctl -w net.ipv4.ip_forward 1

# Add a "default rule" to a non-default routing table
ip route add default dev tun0 table 10

# Specify that this table is to be used for anything from the wlan interface
ip rule add iif wlan0 table 10

... and that should be it, really. This assumes you do not need NAT; if you control both the VPN server and the wlan IP address range, that should be straightforward.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.