L2TP static route

Hi there, I recently setup a site to site L2TP tunnel and everything works great, but every time the client reconnects the static route for the IP ranges on the server stops working as the interface was deleted while the client disconnected. Is there any way to automatically add this route when the client connects?

Thanks in advance and have a good day

There are multiple ways to achieve this:

  • use the routes field of ppp secret - if you put a comma-separated list of prefixes (subnets) there, routes to them will be automatically added (you can also add gateway address and distance to each prefix if needed, gateway address may be set to 0.0.0.0 if it acts just as a separator):
    routes=“172.16.0.0/24 0.0.0.0 1,172.31.20.0/24 0.0.0.0 1”
  • you can create a static name for the interface and link it to the ppp secret by its name:
    /interface l2tp-server add name=static-interface-name user=ppp-secret-name
    This way, if the client is not connected, the static name will be used instead of the dynamic one; if a connection already exists and a new one needs to be created (e.g. because the client wants to re-connect whilst the server still considers the old connection OK), the behavior depends on the only-one property of the ppp profile being used.
  • you can assign a fixed remote-address to the client and set the static routes to use this address as their gateway. The routes will become inactive while the gateway address will not be reachable but once the client reconnects, they will become active again.

Thanks Sindy, that worked beautifully. I really appreciate it.
Have a good day