So I have one VPS (based on openvz) with VPN (openvpn) up and running. I'm connecting to this setup with laptop (archlinux) and everything seems to be working. Let's say that vps's ip is I can connect to it and see as my ip when I ask some other server. So traffic is going through vpn.

However, I'm still accessing mail and ssh via direct connection and not via vpn. I think I know why that is (default route to the to prevent loops in routing etc.) and in most use-cases this would be good enough. But not for me. One of the reasons for vpn is to circumvent port blocking in my workplace (cannot send mails via 587). And I cannot do it like this.

So, how to redirect traffic even to the via the vpn? I was thinking about routing everything to the which is not on port X (my vpn port) but not sure how to do this or if it's even possible.


Your VPS must have more than one IP address. The simplest solution is to connect to a different IP address. For example if the public IP of the VPS is and the VPN connection is using with the server on and client on, then you can let the client connect to the SMTP server using rather than

One drawback of this approach is, that using an internal IP will only work while the VPN connection is active. And putting the internal IP in DNS is suboptimal. Having multiple public IP addresses on the VPS should solve that problem.

Alternatively you can use routing policies, that match on protocol or port number and use different routing tables. The exact configuration of this depends on the OS on the client.

  • having trouble with routing policies, cannot get it working :/ acquiring another ip from my provider didn't occur to me but is the way I'll take. so thanks :) – graywolf Sep 17 '14 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.