Skip to main content

IPv6: tunnel HE brokker

 

https://wiki.mikrotik.com/wiki/Manual:Hurricane_Electric_Tunnel_Broker_Example_for_Home

 

Si tu operador no te suministra un prefijo IPv6, puedes optar por no pensar en ello, o puedes optar por iniciarte ahora ya en tener habilitado IPv6 mediante un túnel con alguien que te lo suministre.

Si tu operador te suministra el prefijo asociado al servicio, simplemente salte este apartado y en los siguientes profundizaremos en ello.

Si te entregan una IP-Publica que está en un rango CGNAT, este capítulo tampoco podrás aplicarlo. Sabras que es CGNAT ip porque esta entre la 100.64.0.0 y la 100.127.255.255

Por el título del apartado ya imaginaras que voy a mostrarte el caso de HE, entra en https://tunnelbroker.net/, te registrars y pide tu tu prefijo, te asignarán un /64 de inicio y pides un /57 asociado a dicho prefijo.

Para la mentalidad IPv4 de ahorro, escasez y auditoría continua del uso de IPs semejante derroche de prefijos para absurdamente abundante, pero está así definido en los estándares, recomendaciones y buenas prácticas que hay por ahí.

Una vez te registres tendrás algo del estilo:

image.png

el /48 lo reclamas después de la petición inicial y con eso ya podemos seguir.

/interface 6to4 
add comment="Hurricane Electric IPv6 Tunnel Broker" disabled=no local-address=A.B.C.D mtu=1280 name=sit1 remote-address=216.66.84.42
/ipv6 route 
add comment="" disabled=no distance=1 dst-address=2000::/3 gateway=2001:470:1f12:zzzz::1 scope=30 target-scope=10
/ipv6 address 
add address=2001:470:1f12:zzzz::2/64 advertise=no disabled=no eui-64=no interface=sit1

 

.Captura de pantalla 2024-03-21 101700.png

En el interface sit1, debemos ver el estado "R"(running) si o es asi, debemos revisar que tenemos correctamente informada nuestra IP pública en HE, el mejor sitio para verificarlos en la opción IP->

Captura de pantalla 2024-03-21 102138.png

En este momento tenemos nuestro mikrotik conectado con el broker IPv6 y no está delegando (en este caso) un prefijo /48, ya en el siguiente capítulo seguimos habilitando el uso de estos prefijos para asignar  prefijo o ips a nuestros dispositivos.

 

DDNA automático con HE

Vamos a implantar el auto update de la ip del túnel cuando cambie, automáticamente se regenere el túnel, hay que reconfigurar la ip local y la informada en HE

https://gist.github.com/aaronk6/dfb2216ab98a1606fcc9094c76b4e5e8

https://gist.github.com/aaronk6/dfb2216ab98a1606fcc9094c76b4e5e8
# RouterOS dynamic DNS Update Script for he.net
# =============================================

# make global to preserve IP and IPv6 address across script executions
:global ipddns
:global ipv6ddns

:local ddnshost "myhost.example.com"
:local ddnspass "MY_SECURE_PASSWORD"
:local waninterfacev4 "V4_INTERFACE_NAME" # Interface to retrieve WAN IPv4 address from (i.e. pppoe-out1)
:local waninterfacev6 "V6_INTERFACE_NAME" # Interface to retrieve WAN IPv6 address from (i.e. bridge1)
:local ipv6pool "YOUR_IP6_POOL" # Pool that IPv6 address needs to be part of
:local url "https://dyn.dns.he.net/nic/update"

:local ipfresh ""
:local ipv6fresh ""
:local ipv4error false
:local ipv6error false

:do {
    # get current IP address from WAN interface
    :set ipfresh [/ip address get [find where interface=$waninterfacev4] value-name=address]
    # Check if ipfresh is empty
    :if ($ipfresh = "") do={
        :log error ("DDNS: Failed to get IP address from interface $waninterfacev4.")
        :set ipv4error true
    }
    :if ([ :typeof $ipfresh ] = nil ) do={
        :log error ("DDNS: No IP address on $waninterfacev4")
        :set ipv4error true
    }
} on-error={
    :log error "DDNS: An error occurred while getting the current IP address from WAN interface."
    :set ipv4error true
}

:do {
    # get current IPv6 address from LAN interface
    :set ipv6fresh [/ipv6/address get [find where from-pool="telekom-ipv6" interface=$waninterfacev6] address]
    # Check if ipv6fresh is empty
    :if ($ipv6fresh = "") do={
        :log error ("DDNS: Failed to get IPv6 address from interface $waninterfacev6.")
        :set ipv6error true
    }
    :if ([ :typeof $ipv6fresh ] = nil ) do={
        :log error ("DDNS: No IPv6 address on $waninterfacev6")
        :set ipv6error true
    }
} on-error={
    :log error "DDNS: An error occurred while getting the current IPv6 address from LAN interface."
    :set ipv6error true
}

# extract the portion of the IP address before the last / character
:do {
    # extract the portion of the IP address before the last / character
    :for i from=( [:len $ipfresh] - 1) to=0 do={ 
        :if ( [:pick $ipfresh $i] = "/") do={ 
            :set ipfresh [:pick $ipfresh 0 $i];
        } 
    }

    :for i from=( [:len $ipv6fresh] - 1) to=0 do={ 
        :if ( [:pick $ipv6fresh $i] = "/") do={ 
            :set ipv6fresh [:pick $ipv6fresh 0 $i];
        } 
    }
} on-error={
    :log error "DDNS: An error occurred while extracting the portion of the IP addresses."
}

:do {
    # Check and update IPv4 address
    :if ($ipv4error) do={
        :log warning "DDNS: Skipping IPv4 update due to previous error."
    } else {
        :if ($ipddns = $ipfresh) do={
            :log info ("DDNS: IP address is already up to date")
        } else {
            :log info ("DDNS: IP address has changed from $ipddns to $ipfresh, sending update...")
            :local body "hostname=$ddnshost&password=$ddnspass&myip=$ipfresh"
            :local result [/tool fetch mode=https output=user url=$url http-method=post http-data=$body as-value]

            :if ($result->"status" != "finished") do={
                :log error ("DDNS: Failed to send IPv4 update")
            } else {
                :log info ("DDNS: Response from server: " . $result->"data")
                :if (([:find ($result->"data") "good"] = 0) or ([:find ($result->"data") "nochg"] = 0)) do={
                    :set ipddns $ipfresh
                }
            }
        }
    }
} on-error={
    :log error "DDNS: An error occurred while checking and updating the IPv4 address."
}

:do {
    # Check and update IPv6 address
    :if ($ipv6error) do={
        :log warning "DDNS: Skipping IPv6 update due to previous error."
    } else {
        :if ($ipv6ddns = $ipv6fresh) do={
            :log info ("DDNS: IPv6 address is already up to date")
        } else {
            :log info ("DDNS: IPv6 address has changed from $ipv6ddns to $ipv6fresh, sending update...")
            :local body "hostname=$ddnshost&password=$ddnspass&myip=$ipv6fresh"
            :local result [/tool fetch mode=https output=user url=$url http-method=post http-data=$body as-value]

            :if ($result->"status" != "finished") do={
                :log error ("DDNS: Failed to send IPv6 update")
            } else {
                :log info ("DDNS: Response from server: " . $result->"data")
                :if (([:find ($result->"data") "good"] = 0) or ([:find ($result->"data") "nochg"] = 0)) do={
                    :set ipv6ddns $ipv6fresh
                }
            }
        }
    }
} on-error={
    :log error "DDNS: An error occurred while checking and updating the IPv6 address."
}