VPN works similarly on both Windows and Linux: It creates a virtual TAP
network adapter for which it installs a driver.
The driver is in constant contact with the servers of
the VPN provider and handles outgoing and incoming connections
on this virtual adapter. It will by default add a default rule to the
routing table on your computer, which will make all outgoing connections
pass by default through the VPN.
The VPN provider functions very similar to your ISP: It owns a range of
IP addresses from which it allocates one address for your computer.
All connections employing this IP address pass through the VPN provider.
This means that your computer now has two IP addresses, one through your ISP
and one through the VPN provider.
Any incoming connection to the VPN IP address will arrive through the
virtual TAP network adapter (requires the caller to use correctly
a compatible VPN client).
Any incoming connection to the ISP IP address will arrive at your router which
will pass on the connection to the physical adapter. The router knows nothing
about a VPN that is created on your computer (unless the router itself is the
one that connects to the VPN).
This means that by default the situation is exactly as you want:
Outgoing connections will by default pass through the VPN's TAP adapter,
while incoming connections using your public address will end up on the
The only problem is then enabling your specific program to listen on the
physical adapter for incoming connections. This can be achieved by two
- Start this program before starting the VPN client may work (or not)
- Bind this program to the physical interface. If you are not its developer,
you could try the free
a freeware Windows application that injects itself into another application
and alters how certain Windows socket calls are made, allowing you to force the
application to use a specific network interface / IP address.
See also the article
3 ForceBindIP GUI to Easily Bind Windows Application to Specific Network Adapter.
The viability of this solution depends a lot on your hardware (chiefly the
router) and the software (VPN driver and operating system).