Iptables – Routing OpenVPN exit traffic to multiple interfaces

firewalliptablesopenvpnroutingufw

I have two Debian servers that I am trying to configure, one is an OpenVPN server and the second is a mail server.

I would like to configure the OpenVPN server so that it routes traffic from my laptop either to the internet (eth0) or to an intranet (eth1) depending on whether I am trying to access a website (eth0) or my private email server (eth1).

Right now I can connect my laptop to the OpenVPN server, and I can browse websites. In other words, the VPN server is currently routing all traffic out eth0.

I have the intranet configured, and I can use telnet to connect from the vpn server to the mail server and visa versa.

Is it possible for OpenVPN traffic to be routed through different interfaces based on the destination IP address?

If so, how might I configure this?

Thanks so much!

Edit:
I have been trying to learn more about iptables, and I believe that more information about them and OpenVPN will help me solve my problem.

Based on my ongoing research, I think it would be possible for me to further increase security by directing all internet and intranet connections through VPN tunnels.

Based on my research, I have the following questions:

  1. Do I need to run my private OpenVPN server as a bridge to facilitate tunneled communication between my laptop and my email server, or is this something that can be accomplished using iptables.

  2. How can I use iptables and OpenVPN to allow incoming internet traffic to port 443 on my private OpenVPN server, while directing all outbound traffic on the OpenVPN server through a tunnel to a secondary public OpenVPN server (e.g., Private Internet Access)?

  3. How can I configure my email server to allow incoming and outgoing internet connections on port 25, while directing all other traffic through my private OpenVPN server (which will then route it through a tunnel to either my laptop or a secondary public VPN server)?

I have attached an image describing my ideal configuration:

Ideal Configuration

Best Answer

How is routing configured between the VPN server and the intra-net servers? You should check the iptables on your VPN box to see if it's setup to forward VPN traffic towards the intranet.

Look at this RedHat article for more info