Community discussions

 
User avatar
pcunite
Forum Veteran
Forum Veteran
Topic Author
Posts: 945
Joined: Sat May 25, 2013 5:13 am
Location: USA

Proper DNS setting to resolve static or local search domain

Wed Oct 09, 2013 6:08 pm

I have a small LAN with a MikroTik v6.4 box providing DHCP and DNS services. However, Windows 7 clients are unable to ping the MikroTik via its hostname or each other via their hostnames. They can only get ping replies by specifying the actual IP address.

In the DNS cache window I see the attempts to ping showing up negative with a hostname.home (home is my local domain suffix) 0.0.0.0 value. This is true for clients that are given dynamic DHCP leases or static ones too.

Naturally, for DNS static entries I could add the .home suffix and it resolves, however, how to do this for all the DHCP clients? This should happen automatically and it's not.

GUI Settings:
Image
 
inten
just joined
Posts: 8
Joined: Tue Oct 16, 2012 3:54 pm

Re: Proper DNS setting to resolve static or local search dom

Wed Oct 09, 2013 7:11 pm

Create all DNS records manually or take a loot at http://wiki.mikrotik.com/wiki/Setting_s ... DHCP_lease
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Proper DNS setting to resolve static or local search dom

Wed Oct 09, 2013 7:33 pm

Create all DNS records manually or take a loot at http://wiki.mikrotik.com/wiki/Setting_s ... DHCP_lease
MikroTik does not automatically add entries for DHCP to the static list. Also I don't think you want 192.168.0.1 in your list of DNS servers for the DNS server config itself. As he said... you need to use a script to do it.
 
User avatar
pcunite
Forum Veteran
Forum Veteran
Topic Author
Posts: 945
Joined: Sat May 25, 2013 5:13 am
Location: USA

Re: Proper DNS setting to resolve static or local search dom

Wed Oct 09, 2013 7:39 pm

MikroTik does not automatically add entries for DHCP to the static list. As inten said ... you need to use a script to do it.
This should happen automatically without needing to use a script. Thank you both for the confirmation.
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Proper DNS setting to resolve static or local search dom

Wed Oct 09, 2013 7:47 pm

MikroTik does not automatically add entries for DHCP to the static list. As inten said ... you need to use a script to do it.
This should happen automatically without needing to use a script. Thank you both for the confirmation.
Should is relative. I agree it should be an option, but you can do it easily with scripts.

If you want more DNS/DHCP functionality you could also run a raspberry pi or something else with linux and use bind/DHCPd/DNSMasq/etc.... Not saying its necessary, but its an option.

But yeah. None of that is actually built into RouterOS.

Here is the script I use. It either will add the entries by hostname or by the comment field if you add "+hostname" to the end of your comment. It sets the TTL to all entries it adds and marks all of the "Dynamic" entries with a specific comment so it can remove them later. You can use it as a starting point..

ros code

#.* by RouterOS
#
# DHCP Leases to Static DNS
#

#
# Variables
#
:local tld "lan"
:local addtld false

:local scriptTTL "01:00:00"
:local scriptComment "DHCP"

:local byComment true
:local byHostname false

#
# Script
#
:set scriptComment ("+" . $scriptComment)

# Flush Old Dynamic Entries
/ip dns static {
	remove [find comment~("^" . $scriptComment . ".*\$")]
}

# Insert by Comment
:if ($byComment) do={
	:local currentComment ($scriptComment . "-Comment")
	/ip dhcp-server lease {
		:foreach i in=[find comment~"^([^+])*\\+([^+])*\$"] do={
			:local leaseComment [get $i comment]
			:local currentHostname [:pick $leaseComment ([:find $leaseComment "+"]+1) [:len $leaseComment]] 

			:if ($addtld) do={
				:set currentHostname ($currentHostname . "." . $tld)
			}

			:local currentAddress [get $i address]
			
			:local free true
				
			/ip dns static {
				:foreach j in [find name=$currentHostname] do={
					:set free false
				}

				:if ($free) do={
					/ip dns static add name=$currentHostname address=$currentAddress ttl=$scriptTTL comment=$currentComment
				}
			}   
		}
	}
}

# Insert by Hostname
:if ($byHostname) do={
	:local currentComment ($scriptComment . "-Hostname")
	/ip dhcp-server lease {
		:foreach i in=[find] do={
			:if ([:len [get $i host-name]] > 0) do={
				:local currentHostname [get $i host-name]
				
				:if ($addtld) do={
					:set currentHostname ($currentHostname . "." . $tld)
				}
		
				:local currentAddress [get $i address]
			
				:local free true
				
				/ip dns static {
					:foreach j in [find name=$currentHostname] do={
						:set free false
					}

					:if ($free) do={
						/ip dns static add name=$currentHostname address=$currentAddress ttl=$scriptTTL comment=$currentComment
					}   
				}
			}
		}
	}
}
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Proper DNS setting to resolve static or local search dom

Wed Oct 09, 2013 7:52 pm

You could also use the "lease-script" function as well... I can help you write a script to do that if you want.
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Proper DNS setting to resolve static or local search dom

Thu Oct 10, 2013 10:22 pm

So I re-wrote the script to be run as a lease script.... NOTE: I HAVE NOT TESTED THIS YET. It is theoretical. It works the same way as the one above, e.g. by comment or by hostname, except that it is designed to be run by the DHCP server as a lease script.

ros code

# *. by RouterOS
#
# DHCP Leases to Static DNS
# On-Lease Script
#

#
# Variables
#
:local tld "lan"
:local addtld false

:local scriptTTL "01:00:00"
:local scriptComment "DHCPOnLease"

:local byComment true
:local byHostname false

#
# Globals
#
:global leaseBound
:global leaseServerName
:global leaseActMAC
:global leaseActIP

#
# Script
# 
:set scriptComment ("+" . $scriptComment)

:if ($leaseBound = 1) do={ 
# Insert by Comment
	:if ($byComment) do={
		:local currentComment ($scriptComment . "-Comment")
		/ip dhcp-server lease {
			:foreach i in=[find comment~"^([^+])*\\+([^+])*\$" address=$leaseActIP] do={
				:local leaseComment [get $i comment]
				:local currentHostname [:pick $leaseComment ([:find $leaseComment "+"]+1) [:len $leaseComment]] 

				:if ($addtld) do={
					:set currentHostname ($currentHostname . "." . $tld)
				}

				:local free true
			
				/ip dns static {
					:foreach j in [find name=$currentHostname] do={
						:set free false
					}

					:if ($free) do={
						add name=$currentHostname address=$leaseActIP ttl=$scriptTTL comment=$currentComment
					}
				}   
			}
		}
	}

# Insert by Hostname
	:if ($byHostname) do={
		:local currentComment ($scriptComment . "-Hostname")
		/ip dhcp-server lease {
			:foreach i in=[find address=$leaseActIP] do={
				:if ([:len [get $i host-name]] > 0) do={
					:local currentHostname [get $i host-name]
				
					:if ($addtld) do={
						:set currentHostname ($currentHostname . "." . $tld)
					}
	
					:local free true
			
					/ip dns static {
						:foreach j in [find name=$currentHostname] do={
							:set free false
						}

						:if ($free) do={
							add name=$currentHostname address=$leaseActAddress ttl=$scriptTTL comment=$currentComment
						}   
					}
				}
			}
		}
	}
} else={
	/ip dns static {
		remove [find address=$leaseActIP comment~("^" . $scriptComment . ".*\$")]
	}
}
 
poi90
just joined
Posts: 2
Joined: Tue Aug 02, 2016 5:41 am

Re: Proper DNS setting to resolve static or local search domain

Tue Aug 02, 2016 5:51 am

I ask for help

an example of a static ip script?

an example

No one device is connected to the server, the corresponding IP can not be changed anymore

Who is online

Users browsing this forum: No registered users and 27 guests