DNS Resolving for PPP Clients

Sometimes you will need to connect to a router that either has a dynamic IP or a domain name instead of directly to the IP address.  This is easily achieved using RouterOS  with a simple script.  Using the script below you will need to change PPP-INTERFACE to the name of your PPP interface and VPN.YOURDOMAIN.COM to the domain name of what you are trying to connect to.

/system script
    add name="CBrown-VPN DNS" policy=\
    ftp,reboot,read,write,policy,test,winbox,password source=":global pptpinte\
    rfacename \"PPP-INTERFACE\"\r\
    \n:global pptpdnsname \"VPN.YOURDOMAIN.COM\"\r\
    \n:global pptpdnsip [:resolve \$pptpdnsname]\r\
    \n:global currentip [/interface pptp-client get \$pptpinterfacename connec\
    \n:if (\$currentip != \$pptpdnsip) do={ /interface pptp-client set [find n\
    ame=\$pptpinterfacename] connect-to=\$pptpdnsip}\r\

Then you will need to schedule the script to run at a given interval.  I generally set this to a couple minutes to be sure I am always using the correct address.

/system scheduler
add interval=2m name=DNS on-event="/system script run \"CBrown-VPN DNS\"" policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-time=startup

Leave a Reply

Your email address will not be published. Required fields are marked *