TinyDNS serving WAN IP



  • Hi,

    I wanted tinydns to always serve my dynamic WAN-IP and just want to share some code
    for people having similar problems. The code is far from perfect and I know this is not the way to go,
    but I needed this running asap - thus didn't go through feature requests or create any ticket.

    So this is in a few steps what you can do:

    Step 1:

    Enable ssh in "System -> Advanced" and connect with your ssh-client.
    Open 2 sessions.

    Step 2:

    On first terminal press 12 - debug console:

    pfSense shell: conf_mount_rw();
    pfSense shell: exec

    On second terminal press 8 - console:

    open: vi /usr/local/pkg/tinydns.inc
    find: function tinydns_create_zone_file()
    insert after:

    
    $fd = fopen("{$g['varrun_path']}/service/tinydns/root/data", "w");      
    if(!$fd) {
    	log_error("Could not open {$g['varrun_path']}/service/tinydns/root/data for writing.");
    	return;
    }
    

    the following code:

    /* replace "wan" by wanip */ 
    for($x=0; $x< count($config['installedpackages']['tinydnsdomains']['config']); $x++) {
    	if(strtolower($config['installedpackages']['tinydnsdomains']['config'][$x]['ipaddress']) == "wan"){
    		$config['installedpackages']['tinydnsdomains']['config'][$x]['ipaddress'] = get_interface_ip("wan");
    	}
    }
    

    Step 3:

    open /etc/inc/services.inc

    insert before function definitions: require_once("/usr/local/pkg/tinydns.inc");
    find: function services_dyndns_configure($int = "")
    insert below:

            /* update tinydns service */
            tinydns_create_zone_file();  
            tinydns_setup_ping_items();
    

    Step 4:

    You might need to restart

    Step 5:

    You now can enter "wan" instead of an ip in
    "Services->DNSServer->Record Data" and it should server your wan-ip.

    I think that Step 2 should be placed in /etc/inc/pfsense-utils.inc at
    function reload_all_sync() - but I couldn't get it to work there.
    Thus I put it in the services_dyndns_configure function, which probably only works with configured dyndns.

    As it serves my needs I'm fine with it - if theres more interest it would definetly be worth opening a
    ticket and having a delevoper doing things right.

    Greets, Juel


Locked