All,
I recently set up OpenVPN server . Works great.
172.18.100.115 is my machine that will connect to the VPN server, it works it i just use the "redirect gateway def0"..
Then I would like to play around with the ip route and rule. I would like to make this machine able to access internet via VPN with ip rule and route as below. I follow solution on
https://forums.openvpn.net/topic8682.html
# cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
10 vpn
# ip route show table vpn
0.0.0.0/1 via 10.8.0.5 dev tun0
10.8.0.0 via 10.8.0.5 dev tun0 metric 1
128.0.0.0/1 via 10.8.0.5 dev tun0
# cat /etc/openvpn/route-up.sh
#!/bin/sh
ip route add $ifconfig_remote dev $dev proto kernel scope link src $ifconfig_local
ip route add $route_network_1 via $ifconfig_remote dev $dev metric 1 table vpn
ip route add 0.0.0.0/1 via $ifconfig_remote dev $dev table vpn
ip route add 128.0.0.0/1 via $ifconfig_remote dev $dev table vpn
ip rule add from 172.18.100.115/32 table vpn
ip rule add to 172.18.100.115/32 table vpn
ip rule add from 10.8.0.0/24 table vpn
ip rule add to 10.8.0.0/24 table vpn
# cat /etc/openvpn/route-down.sh
#!/bin/sh
ip route flush table vpn
ip rule del from 172.18.100.115/32 table vpn
ip rule del to 172.18.100.115/32 table vpn
ip rule del from 10.8.0.0/24 table vpn
ip rule del to 10.8.0.0/24 table vpn
# ip rule show
0: from all lookup local
32758: from all to 10.8.0.0/24 lookup vpn
32759: from 10.8.0.0/24 lookup vpn
32760: from all to 172.18.100.115 lookup vpn
32761: from 172.18.100.115 lookup vpn
32766: from all lookup main
32767: from all lookup default
# eth0 Link encap:Ethernet HWaddr 08:00:27:29:73:0a
inet addr:172.18.100.115 Bcast:172.18.255.255 Mask:255.255.0.0
inet6 addr: fe80::a00:27ff:fe29:730a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9126 errors:0 dropped:0 overruns:0 frame:0
TX packets:940 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1012596 (1.0 MB) TX bytes:155843 (155.8 KB)
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:261 errors:0 dropped:0 overruns:0 frame:0
TX packets:261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:22619 (22.6 KB) TX bytes:22619 (22.6 KB)
tun0 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.6 P-t-P:10.8.0.5 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:912 (912.0 B)
Any idea why i cannot connect to the internet via VPN ? The machine that connect to the vpn is 172.18.100.115.