I am desperately trying to setup a gateway-server that forwards all local traffic to a ppp0 connection but is still reachable via ssh on the local network.

The point-to-point connection establishes fine, IP-forwarding is enabled and with

route add -net ppp0
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

I almost achieve what I want. But once "route" is set, the gateway-server can no longer be reached via ssh.

I am pretty new to "route" and "iptables" and do not fully understand how they work yet but there has to be a super simple solution for my problem.

Please help!

A very similar question without proper solution: How can I route outgoing traffic through a PPTP VPN connection on a VPS without losing SSH access?

EDIT: A more detailed example below


GATEWAY shall be a local gateway to the internet via VPN. This is quite an easy setup as described above: Enable IP-forward, establish a PPTP connection between GATEWAY<>VPN and set a default route through ppp0 afterwards.

LOCALHOST can now use GATEWAY for internet access with VPN's IP-address but access to GATEWAY within the local network (192.168.0.X) via SSH does not work anymore once the PPTP connection is established.

EDIT2: ifconfig and route output ( is the 'regular' local gateway)

eth0      Link encap:Ethernet  Hardware Adresse 12:34:56:78:90:ab  
          inet Adresse:  Bcast:  Maske:

ppp0      Link encap:Punkt-zu-Punkt-Verbindung  
          inet Adresse:  P-z-P:  Maske:


Ziel            Router          Genmask         Flags Metric Ref    Use Iface
default         *              U     0      0        0 ppp0
default         UG    0      0        0 eth0 UGH   0      0        0 eth0   *      UH    0      0        0 ppp0
localnet        *        U     0      0        0 eth0
  • Please post details about networks: ip of local host running ssh client; ip of gateway server, on the lan-side; ip of default gateway used on the lan. These are needed to define the "route add" command that you need to substitute to the one you posted to solve your problem. – Damiano Verzulli Dec 28 '14 at 1:15
  • Can you show the output of ifconfig and route once everything is up ? – Marki Dec 29 '14 at 12:09




route add -net netmask gw dev eth0
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

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.