Community discussions

MikroTik App
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Static DNS Route with Dynamic Address

Sat Oct 10, 2020 7:05 pm

I am trying to set a static dns route. When entering the address, it will take a name rather than an IP address, but then it changes the name to an IP address. The issue is our server has a dynamic IP address like xxx.abc.com. Is there a way to enter a name rather than an IP address?

Thanks.
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 7:13 pm

I thought you meant /ip route add dst-address=<hostname>, which is not supported, but it also completely refuses it, it doesn't resolve it, so maybe you mean something else? In any case, the answer is probably some script that can resolve hostname and update any field you want.
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 7:24 pm

/ip dns static
add address=x.x.x.x name=anything
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 8:32 pm

And what's the point of that? If there's already hostname for server, why you want to use another pointing to it? Why not simply use the existing one?

In theory, you could use CNAME record. RouterOS 6.47+ allows to add it as static record, but the whole thing doesn't really work in any usable way.
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 8:40 pm

I'm not sure what you are talking about. The address is dynamic- it changes. It doesn't not allow you to enter the dynamic address.. well, it does, but it changes it to an actual IP address once you enter it. If the address changes a week later, it would have no way to knowing.
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 8:49 pm

As I understand it (correct me where I'm wrong), you have some server with dynamic IP address and you have existing DDNS hostname xxx.abc.com. You'd like to add "/ip dns static add address=xxx.abc.com name=someotherhostname", but what you get is "/ip dns static add address=1.2.3.4 name=someotherhostname", where 1.2.3.4 is address to which xxx.abc.com resolves now, but it can be something else tomorrow. My question is, if there's already xxx.abc.com, why don't you use that directly for whatever you need it, instead of someotherhostname?
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 8:52 pm

Either I or you don't know how this works. The "name" part has nothing to do with the hostname. Only the IP address can accept the hostname, and it changes it to an IP address.
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 9:06 pm

Then just assume that I'm complete idiot and try to explain to me in detail what exactly are you trying to do.

Because this:
/ip dns static
add address=1.2.3.4 name=host.example.net
adds static record host.example.net which points to IP address 1.2.3.4. If you then send dns query to router and ask for host.example.net, you'll get 1.2.3.4. And you want to do what?
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 9:10 pm

I'm trying to set up a static dns router for my ubiquiti access points so they know where to "phone home" when they are installed. The unifi server is at IP address"xxx.abc.com". The name is "unifi". I need a way to keep the IP address "xxx.abc.com" updated in the static route. It doesn't not allow you to permentanly enter domain names under IP address, it converts them to ip addresses.
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sat Oct 10, 2020 9:29 pm

I'm sorry, I don't get it. First you wrote about "static dns route", so I assumed something like:
/ip route add dst-address=xxx.abc.com gateway=x.x.x.x
Then you wrote that it's:
/ip dns static add address=x.x.x.x name=anything
And you'd like to do:
/ip dns static add address=xxx.abc.com name=anything
Correct? But it's static dns record and it does what I described in previous post. And now you're back to "static route". So what is it?

And again, if you already have "xxx.abc.com", then why not configure those APs to connect to this exact name?

I can imagine a scenario where you'd need to use different hostname, e.g. if there would be http server configured for that specific hostname and wouldn't return correct data for any other. Is that what you need? If so, you'd need a script to update your static dns record.
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sun Oct 11, 2020 12:21 am

I need to enter a hostname in the IP address area because the IP address can change. Is there a way to do this? I'm not sure how else to ask.
 
Sob
Forum Guru
Forum Guru
Posts: 6517
Joined: Mon Apr 20, 2009 9:11 pm

Re: Static DNS Route with Dynamic Address

Sun Oct 11, 2020 1:01 am

Short answer: No

Long answer: Not directly. If RouterOS doesn't support hostnames in some field, you can't force it to accept them. But you can use script to update numeric address. For example, you can add your record like this:
/ip dns static
add address=127.0.0.1 comment=myrecord name=anything
Then put this as script in scheduler:
:local host
:set host "xxx.abc.com"
:do {
  :local newip
  :set newip [:resolve $host]
  foreach i in=[/ip dns static find comment="myrecord"] do={
    if ($newip != [/ip dns static get $i address]) do={
      /ip dns static set $i address=$newip
      :log info ("dns record updated (host = $host, $host = $newip)")
    }
  }
} on-error={
  :log info "unable to resolve $host"
}
Set it to run as often as you want, and it will update the record with new address. Comment "myrecord" serves as unique identifier. Not the most elegant solution, but it works.

Whether it makes sense for entries in "/ip dns static", that's another question, so far you haven't convinced me of that.
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sun Oct 11, 2020 1:15 am

thanks for the help
 
sindy
Forum Guru
Forum Guru
Posts: 6899
Joined: Mon Dec 04, 2017 9:19 pm

Re: Static DNS Route with Dynamic Address

Sun Oct 11, 2020 11:47 am

@tabate47, do I assume right that the ultimate goal is to make sure that the ubnt boxes would use a different network path (starting by a different gateway) than the other traffic, regardless what the current IP number of the controller is?

If that is the case, the generic mechanism for this is called policy routing. You create a default route via that special gateway (i.e. with dst-address=0.0.0.0/0), but in a dedicated routing table, which is identified by an attribute of the route, called routing-mark. And then you use rules in chain prerouting of table mangle of /ip firewall to assign that routing-mark to packets matching some conditions.

If the ubnt boxes only talk to their controllers and nothing else, the criteria to assign the routing-mark may be just the source IP addresses of the controllers. If they need to talk to other resources as well, and should use the generic default route to do that, you can use the ability of /ip firewall address-list items to be configured for fqdns and track the changes of the associated IP numbers. You can combine multiple criteria (only packets from ubnt IP addresses to the controller's current address will get the routing-mark); if the ubnt boxes access another address, they will use the default (main) routing table, and so will other devices if accessing the controller's IP address.

In more detail the above is described here (but there it is for packets sent by the Mikrotik itself - for your purpose, the mangle rules need to be in mangle chain prerouting as mentioned above), as well as in tens of other similar topics on this forum.
Instead of writing novels, post /export hide-sensitive. Use find&replace in your favourite text editor to systematically replace all occurrences of each public IP address potentially identifying you by a distinctive pattern such as my.public.ip.1.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Thu Feb 18, 2021 10:31 pm

I upgraded to 6.47.9 and it now has the option for CNAME DNS static entry. I tried it, but it does not seem to work. When I use the A option and enter the numerical IP address, it works, but when I use CNAME with the xxx.abc.com address it does not work.

Am I doing something wrong?
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Thu Feb 18, 2021 10:37 pm

by the way, if you look at this post, this is what I am trying to accomplish but with CNAME if possible:

/ip dns static
add address=ControlerIPAddress name=unifi

see post:

viewtopic.php?t=91788
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Feb 20, 2021 12:46 pm

Can anyone help with this?
 
tdw
Forum Veteran
Forum Veteran
Posts: 713
Joined: Sat May 05, 2018 11:55 am

Re: Static DNS Route with Dynamic Address

Sat Feb 20, 2021 3:01 pm

If a static CNAME entry in 6.47.x does not work I would suspect the UniFi discovery implementation, in which case the scheduled script option suggested by @Sob would be a solution.

@Sob & @sindy the OP putting 'route' in the topic title is completely misleading. The UniFi devices have a number of mechanisms for out-of-the-box devices to discover a controller and announce themselves to it. When the device and controller are on the same network there is a layer 2 broadcast discovery protocol, however when they are on different networks the device can be given the controller address either by the local routers DHCP server providing DHCP option 43, or the local routers DNS server answering a request for "unifi" with no domain.

The discovery mechanism should only be required once, however I've not checked what the UniFi devices actually store internally when provisioned by the controller. I suspect that the default inform URL of http://unifi:8080/inform is replaced by http://A.B.C.D:8080/inform so connectivity would be lost when the IP address changes unless the Override inform host with controller hostname/IP option is enabled in the controller, and the Controller Hostname/IP field is sent to a name rather than IP address.
 
tabate47
Member
Member
Topic Author
Posts: 457
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Static DNS Route with Dynamic Address

Sat Feb 20, 2021 5:02 pm

Is it possible the CNAME is not working due to my 1 day TTL?

What should the TTL be set to when using a CNAME?

Does it auto lookup the CNAME as soon as you enter it, or does it wait until the TTL expires?

Thanks
 
klasstaffan
just joined
Posts: 1
Joined: Sun Feb 21, 2021 5:10 pm

Re: Static DNS Route with Dynamic Address

Sun Feb 21, 2021 7:49 pm

The syntax of the route add command is;

route add destination mask subnetmask gateway metric costmetric if interface

Where destination is either an IP address or host name for the network or host.

Example:

route add webservices.example.com mask 255.255.255.255 10.11.12.13

You have to keep in mind that the entry will be resolved to an IP address, so if the DNS for the host name changes, there will still be the original IP address in the routing table.

Who is online

Users browsing this forum: cgallery, Google [Bot], hpet, robo and 137 guests