Community discussions

Member Candidate
Member Candidate
Topic Author
Posts: 190
Joined: Sat Nov 12, 2011 2:30 am
Reputation: 3
Location: UK

No-IP and HE Tunnel Scripts for v5.11

Wed Jan 11, 2012 8:30 pm

Had a lot of trouble getting existing scripts working, so I have put bits and pieces from the Forum and Wiki together to make scripts that work. These work for definate on v5.11 . I have kept them seperate incase you don't need one or the other.

Finished them now. I have them setup so the DDNS one is called every 5 minutes by scheduler, and when it detects the wan IP needs updating to no-ip, it will do that, and THEN call the seperate HE-NET script. You can comment out the logs as needed. I found them useful when I was trying to make the scripts.

Name: DDNS
Site1 Site2 etc is handy for deploying the script to multiple sites. The script sets the hostname depending on what the RB Identity is. I use it for setting different DNS hosts for VPN.

# Set needed variables
:global username "USERNAME"
:global password "PASSWORD"
:global hostname "nohostset"
:global wanInt "WAN INTERFACE NAME"
:global systemname [/system identity get name]

:if ($systemname  = "Site1" ) do= {
:set hostname ""
:if ($systemname  = "Site2" ) do= {
:set hostname ""
:if ($systemname  = "Site3" ) do= {
:set hostname ""

:global noipForce
:global previousIP

# print some debug info
#:log info ("DDNS: username = $username")
#:log info ("DDNS: password = $password")
:log info ("DDNS: hostname = $hostname")
:log info ("DDNS: previousIP = $previousIP")

# Grab the current IP address on that interface.
:global ddnsip [/ip address get [/ip address find interface="$wanInt"] address]
:global currentIP [:pick $ddnsip 0 [:find $ddnsip "/"]]

#:log info ("DDNS: ddnsip = $ddnsip")
:log info ("DDNS: currentIP = $currentIP")

# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by No-IP!
#:set noipForce true

# Determine if no-ip update is needed
# more no-ip updater request details available at
:if (($currentIP != $previousIP) || ($noipForce = true)) do={
    :set noipForce false
    :set previousIP $currentIP
    :log info ("DDNS: No-IP update needed")
    :log info ("DDNS: Start of Fetch")
global tmp [/tool fetch mode=http port=80 src-path="/nic/update?hostname=$hostname&myip=$currentIP" user=$username password=$password dst-path="/noip.txt"]
    :log info ("DDNS: End of Fetch")
    :global result [/file get noip.txt contents]
    :log info ("DDNS: No-IP Update Result: $result")
    :put ("No-IP Update Result: $result")
# Update Tunnel
    :execute script=HE-NET
} else={
    :log info ("DDNS: No No-IP update needed")

Script name: HE-NET
:global HEusername "HE USER ID (LONG MD5 HASH VERSION)"
:global HEpassword "PASSWORD IN MD5"
:global HEtid "TUNNEL UID"
:global HEint "6TO4 INTERFACE NAME"
:log info ("HE-UPD: Finding bt-wan IP")
:global HEcurrentIP [/ip address get [/ip address find interface="$HEwan"] address]
:log info ("HE-UPD: $HEcurrentIP")
:set HEcurrentIP [:pick $HEcurrentIP 0 [:find $HEcurrentIP "/"]]
:log info ("HE-UPD: $HEcurrentIP")
:log info ("HE-UPD: ---6to4 update being attempted interface---")
/interface 6to4 set "$HEint" disabled=yes
:log info ("HE-UPD: sit1 disabled")
/interface 6to4 set "$HEint" disabled=no local-address=$HEcurrentIP
:log info ("HE-UPD: 6to4 new v4addr set and re-enabled")
:log info ("HE-UPD: Start Fetch")
/tool fetch mode=http port=80 src-path="/ipv4_end.php\?ipv4b=$HEcurrentIP&pass=$HEpassword&user_id=$HEusername&tunnel_id=$HEtid" dst-path="henet.txt"
:delay 1
:log info ("HE-UPD: Fetch done")
:global 6to4OUT [/file get henet.txt contents]
:log info "HE-UPD: 6to4 update result was '$6to4OUT'"
:log info ("HE-UPD: Advertise eth2 again")
# Re-advertise IPv6 on internal interface 1
:local tmpHE1 [/ipv6 address find address="2001:470:xxxx:1::1/64"]
/ipv6 address set $tmpHE1 advertise=no
/ipv6 address set $tmpHE1 advertise=yes
:log info ("HE-UPD: Advertise eth3 again")
# Re-advertise IPv6 on internal interface 2
:local tmpHE2 [/ipv6 address find address="2001:470:xxxx:2::1/64"]
/ipv6 address set $tmpHE2 advertise=no
/ipv6 address set $tmpHE2 advertise=yes
# Refresh default route
:log info ("HE-UPD: Refresh default route")
   /ipv6 route remove [/ipv6 route find dst-address="2000::/3"]
   /ipv6 route add comment="" disabled=no distance=1 dst-address=2000::/3 gateway=2001:470:xxxx:xxxx::1 scope=30 target-scope=10
:log info ("HE-UPD: 6to4 update complete")

I need to comment the scripts more and make them tidier, but they work for now so I will leave them until they break. If you want anything explaining, let me know.

Member Candidate
Member Candidate
Topic Author
Posts: 190
Joined: Sat Nov 12, 2011 2:30 am
Reputation: 3
Location: UK

Re: No-IP and HE Tunnel Scripts for v5.11

Fri Jan 13, 2012 7:11 am

The HE-NET script does not completely restore IPv6 connectivity upon IP address change of the WAN interface. I have just found out that all IPv6 addresses need to be disabled and then re-enabled. This immediately restores IPv6 connectivity. I will amend the script when I have time and post another reply when it has been updated.


Who is online

Users browsing this forum: gianniasini and 3 guests