pfSense: patch for DynDNS when the WAN interface does not have the public IP

Translation of the original in Catalan. Read it in: CatalàCastellano

If for whatever reason you have a pfSense with the Dynamic DNS service and your WAN interface does not have the public IP with which you want to update the dynamic IP service you use, here you will find the solution. This can happen for several reasons:

  • There is more than one WAN

  • The WAN has a private IP that links to the router

  • Internet access through a VPN

  • etc

Well, specifically in my case I have two WAN outputs and, to make things worse, the one with the dynamic IP does not have the IP assigned by the provider but a private IP. So, looking through the pfSense forums I found this solution to the problem.

It is about modifying the /etc/inc/dyndns.class file. First of all we add this new method (function) to the class:

/* Private function for getting real IP */
/* Author: Tri Tu */
function _checkip() {
   log_error("DynDns: Running _checkip() for real WAN IP");
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, 'http://checkip.dyndns.com');
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   $data = curl_exec($ch);
   curl_close($ch);
   list($part1, $part2) = split(': ', $data, 2);
   list($ip, $junk) = split('<', $part2);
   return $ip;
}

Then, inside the same file, we look for all the places where this appears:

$wan_ip = get_current_wan_address();

and we change it to:

$wan_ip = $this->_checkip();

If you look closely, the whole thing is as simple as telling the class that, in order to know which its WAN IP is, it must call the previous function; this function connects to the typical website that returns the IP we have and from there we capture that IP and assign it to the variable used to know whether our IP has changed.

4 comments

Comments from the old blog, as they were written. Comments are closed.

  1. quetzal

    Mussol! El teu captcha em te banejat i no puc mandar-te un correu pel formulari, revisa'l!

    Manda'm un correu a quetzal _arrob_ eslack.org

  2. —

    [1]

    Solucionat el tema del captcha no és que tu no poguessis no podia ningú. Ja que tenia un error d'html súper xorra i molts cops m'ho deien però jo ho probava i a mi no em petava ara ja ho he solucinat i funciona bé tan si tens o no tens compte d'usuari registrat.

  3. Lluis

    Tb hi ha un patch pel ez-ipupdate (3a nota a http://wiki.openwrt.org/DDNSHowTo#head-875181c89706a41197e8f38e4d11cc6008937f56...), que ho suporta de forma molt facil, i pel OpenWRT recordo haver trobat tb no se quin altre paquet que ho suporta de serie.

    apa!

  4. —

    [3]

    Si però el problema no el tinc amb el ez-ipudate ni amb el openwrt sinó amb el pfsense que és el que fa de firewall.