eworm-de / routeros-scripts

a collection of scripts for MikroTik RouterOS
GNU General Public License v3.0
1.27k stars 285 forks source link

DNS records for Openvpn pears #44

Closed tomaskovacik closed 1 year ago

tomaskovacik commented 1 year ago

Hello, question, any plans for OpenVPN 2 DNS script?

eworm-de commented 1 year ago

No, currently this is not planned... A long time ago that I used OpenVPN - switched to IPSec with IKEv2 first (which is served by ipsec-to-dns), then to Wireguard (which uses static addressing, so you can use static DNS records just fine).

So I do not have a use case for this, not even a test case.

tomaskovacik commented 1 year ago

ok thx, I will do it then.

tomaskovacik commented 1 year ago

Just update, no complicated script is needed:

onUP:

:local remoteAddr $"remote-address"
:local comment [/ppp secret get [find where name=$user] comment]
:local host [:pick $comment ([:find $comment "="] + 1) [:len $comment]]

:if ( [ :typeof $host ] = "nil" )  do={
:set host $user
}

:local hostname ($host . ".domain.local")

/ip dns static remove [/ip dns static find name=$hostname]
/ip dns static add name=$hostname address= $remoteAddr
:log info "Add dns entry for $hostname with IP: $remoteAddr"

OnDown:

:local comment [/ppp secret get [find where name=$user] comment]
:local host [:pick $comment ([:find $comment "="] + 1) [:len $comment]]

:if ( [ :typeof $host ] = "nil" )  do={
:set host $user
}

:local hostname ($host . ".domain.local")

:log info "Removing dns entry for $hostname"
/ip dns static remove [/ip dns static find name=$hostname]

the only issue is that ppp username must be the same as the local hostname. I will work on this and probably will implement "hostname=" comment feature if the comment is exposed as a variable.