VPN with Static Route

 

 


加 route 用 IF 的好處

 

Diagram

Client    -->    vpn.datahunter.org --> 192.168.130.0/24
(獲得IP:30.X)

Usage

route -p add a.b.c.d/<CIDR> 0.0.0.0 IF <interface number>

IF support interface is up / down => add / remove route

i.e.

# "20" 是 VPN NIC 的 ID, 在 VPN up 時可以用 route print 查看

route print

============================================
Interface List
 19...xx xx xx xx xx xx ......Realtek PCIe GbE Family Controller #3
 52...........................vpn.datahunter.org

Remark

  • xx 係佢的 MAC
  • NIC Num 與 VPN 連接的順序有關, 它們的 ID 係順序的, 所以不是固定

# VPN 後, 在 NIC 52 存在時

route add 192.168.130.0 mask 255.255.255.0 192.168.33.1 IF 52 -p

route print         # win10

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
    ...
    192.168.130.0    255.255.255.0     192.168.33.1    192.168.30.14     26
    ...
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
    ...
    192.168.130.0    255.255.255.0     192.168.33.1       1

On-link

route add 192.168.130.0 mask 255.255.255.0 192.168.30.1 IF 27

route print | findstr 192.168.130

192.168.130.0    255.255.255.0     192.168.30.1    192.168.30.14     26

route add 192.168.130.0 mask 255.255.255.0 0.0.0.0 IF 27

route print | findstr 192.168.130

    192.168.130.0    255.255.255.0         On-link     192.168.30.14     26
  192.168.130.255  255.255.255.255         On-link     192.168.30.14    281

On-link

It means that the destination network is directly attached to the interface

meaning traffic that matches this route entry will trigger an ARP request

that should be sent from this link to resolve the destination IP directly