Community discussions

 
naxxfish
just joined
Topic Author
Posts: 1
Joined: Fri Jan 11, 2019 10:33 am

Suggestions for getting WAN IP from interface with multiple IPs

Fri Jan 11, 2019 10:38 am

Hi

I'm trying to get some DDNS updater scripts working, and have come across a common issue. Where there is code such as this:

Code: Select all

:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
This doesn't work for me, as my interface has two IP addresses (one for the WAN, another for the cable modem management interface), so find interface is getting an array.

Is there a common way of getting whichever of these addresses is the public routable IP instead of the internal one?

Cheers!
 
Frostbyte
newbie
Posts: 38
Joined: Mon Dec 25, 2017 1:42 am

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sat Jan 12, 2019 4:06 am

Assuming you have configured at least one DNS server on your RouterBOARD, you may use this:
local currWANAddress [toip [resolve myip.opendns.com server=resolver1.opendns.com]]

It will give you the WAN address of your current default gateway (least distance 0.0.0.0/0 route). Source
(You can use the provision and dyndns modules of RouterSCRIPTS as well - they're pretty reliable)
 
User avatar
Jotne
Forum Veteran
Forum Veteran
Posts: 810
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sat Jan 12, 2019 10:54 am

@Frostbyte
Problem is that he try to update a DNS system, so you assume he has already a working DDNS, some he does not have.

@naxxfish
Have you looked at Cloud (IP->Cloud) on the Router? It's a free dynamic DNS updater from Miktrotik so you do not need other script.

Try this to get public IP (This will only get outside IP, so if you are behind another NAT, you do not get the public IP)
:put [/ip address get [find interface=[/ip route get [find dst-address=0.0.0.0/0] vrf-interface]] address]
or this using the cloud function. (It will get the public ip, even if its behind other NAT)
:put [/ip cloud get public-address]
.
Use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
User avatar
sebastia
Forum Veteran
Forum Veteran
Posts: 972
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sat Jan 12, 2019 1:33 pm

Hey @Jotne, I would suggest to read the question and answer again.

problem: update DDNS
there was nothing said about DNS, but one can only assume that it's working...

and there was also no mentioning of VRF routing, so that won't work either

AND
if I run ":put [toip [resolve myip.opendns.com server=resolver1.opendns.com]]" it does exactly what requester is asking... -> Frostbyte give the right solution IMHO
 
User avatar
Jotne
Forum Veteran
Forum Veteran
Posts: 810
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sat Jan 12, 2019 4:36 pm

Ok I read it again,
Suggestions for getting WAN IP from interface with multiple IPs
I'm trying to get some DDNS updater scripts working,
DDNS = Dynamic DNS https://en.wikipedia.org/wiki/Dynamic_DNS

From what I do read. He need to get the public IP, the one that its routed to the internt, so that he can make a script to update for example no-ip.com site with his IP, so that he can reach his Router using a public DNS service form other side of the internet.

If you ask to resolve myip.opendns.com, you already has updated the opendns.com with your IP. He has not done that yet.
.
Use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
User avatar
sebastia
Forum Veteran
Forum Veteran
Posts: 972
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sat Jan 12, 2019 11:11 pm

Ok, I understand now.

myip.opendns.com is a special feature of opendns servers to give the requester's ip back. That's a then a way to determine the routeable ip.
 
User avatar
Jotne
Forum Veteran
Forum Veteran
Posts: 810
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Suggestions for getting WAN IP from interface with multiple IPs

Sun Jan 13, 2019 10:13 am

myip.opendns.com
Does not work, at leas for me for some reason
This works
http://whatismyip.com

But as I posted above, you can use the built in cloud function to get the IP.
.
Use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
Frostbyte
newbie
Posts: 38
Joined: Mon Dec 25, 2017 1:42 am

Re: Suggestions for getting WAN IP from interface with multiple IPs

Mon Jan 21, 2019 1:01 pm

When you resolve myip.opendns.com you also need to supply server=resolver1.opendns.com to the command.
sebastia is correct that this is a special feature which replies back to you, with your WAN IP address.
This feature can be used regardless of which Dynamic DNS service you're using. We assume that this has been dealt with, as it's out of scope for this topic.
This feature does not update your Dynamic DNS service, as that requires credentials to do so (explained right below).

The script must then do a fetch (HTTP POST Request) to the corresponding API of the Dynamic DNS (i.e. NoIP, DynDNS) service that is being used, with the:
  • Username
  • Password
  • Hostname
  • WAN IP address (that we just determined with said resolve command).

The problem was, as the user described it, that he had no way to determine his WAN/Internet address - and the excerpt which I supplied does exactly that.

Who is online

Users browsing this forum: petertosh and 11 guests