I am currently trying to route all incoming and outgoing network traffic to/from applications listening on an OpenVPN tunnel tun1 through said tunnel.
Here are my devices: tun0
is an OpenVPN server running on the machine that provides access to the machine's local network to remote machines. tun1
is an OpenVPN client to a remote server.
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:1c:c0:d7:98:1c
inet addr:192.168.178.9 Bcast:192.168.178.255 Mask:255.255.255.0
inet6 addr: fe80::21c:c0ff:fed7:981c/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:103987444 errors:0 dropped:0 overruns:0 frame:0
TX packets:161412265 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:583178850 (556.1 MiB) TX bytes:1006632339 (959.9 MiB)
Interrupt:43 Base address:0x8000
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:505197 errors:0 dropped:0 overruns:0 frame:0
TX packets:505197 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:91836367 (87.5 MiB) TX bytes:91836367 (87.5 MiB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.9.8.1 P-t-P:10.9.8.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:272 (272.0 B) TX bytes:960 (960.0 B)
tun1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.10 P-t-P:10.8.0.9 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:588 (588.0 B) TX bytes:588 (588.0 B)
Here are the currently active routes:
# ip route show table main
default via 192.168.178.1 dev eth0
10.8.0.1 via 10.8.0.9 dev tun1
10.8.0.9 dev tun1 proto kernel scope link src 10.8.0.10
10.9.8.0/24 via 10.9.8.2 dev tun0
10.9.8.2 dev tun0 proto kernel scope link src 10.9.8.1
192.168.178.0/24 dev eth0 proto kernel scope link src 192.168.178.9
After some research, I learned that I had to use "policy routing" to direct all traffic on tun1 through another gateway (10.8.0.1). So I created a new table "tun1" and tried to configure it.
# echo "1 tun1tbl" >> /etc/iproute2/rt_tables
# ip route add 10.8.0.0/24 dev tun1 src 10.8.0.10 table tun1tbl
# ip route add default via 10.8.0.1 dev tun1 table tun1tbl
RTNETLINK answers: No such process
Why can't I set the default route for this device/table?
—
edit: I just found another potential solution, using only route
, but it fails with a similar error:
# route add default gw 10.8.0.1 dev tun1
SIOCADDRT: No such process
Best Answer
In your command, you request to send packets via
tun1
via the next hop10.8.0.1
:But this network interface is not on a subnet, which would contain the target address:
Thus the commands refuse to add such route.
As
tun1
is a point-to-point interface, you do not need a gateway to send out packets. Just remove thevia
part from your command: