Community discussions

MikroTik App
 
alphatau87
just joined
Topic Author
Posts: 2
Joined: Mon Jan 11, 2021 11:53 am

forward requests from LAN IP to external server by domain name

Mon Jan 11, 2021 12:02 pm

I have a task where some IoT device needs to send emails (via some external email server, e.g. inbox.lv) and I plan on using LtAP Mini. Problem is this particular IoT device can reach external server only via IP address (it has no DNS client in it's OS). Question: is it possible in RouterOS to forward all requests to that come to LtAP IP address to specific URL (e.g. mail.inbox.lv) from this IoT device (specify IoT device IP address + destination port as condition)? If so, please point me in the right direction :-)
Many thanks in advance for help!
 
Sob
Forum Guru
Forum Guru
Posts: 6499
Joined: Mon Apr 20, 2009 9:11 pm

Re: forward requests from LAN IP to external server by domain name

Mon Jan 11, 2021 10:05 pm

You can set server address on device to some fake unused one (e.g. 10.10.10.10) and create dstnat rule:
/ip firewall nat
add chain=dstnat dst-address=10.10.10.10 protocol=tcp dst-port=25 action=dst-nat to-addresses=1.2.3.4 comment=someuniqueid
But you can't use hostname in to-addresses, so you need a script to update it (run it from scheduler with some reasonable frequency):
:local Host "mail.inbox.lv"
:do {
  :local NewIP [:resolve $Host]
  /ip firewall nat set [find comment="someuniqueid"] to-addresses=$NewIP
} on-error={
  :log info "unable to resolve $Host"
}
Excessive quoting is useless and annoying. If you use it, please consider if you could do without it.
 
alphatau87
just joined
Topic Author
Posts: 2
Joined: Mon Jan 11, 2021 11:53 am

Re: forward requests from LAN IP to external server by domain name

Tue Jan 12, 2021 10:07 pm

You can set server address on device to some fake unused one (e.g. 10.10.10.10) and create dstnat rule:
/ip firewall nat
add chain=dstnat dst-address=10.10.10.10 protocol=tcp dst-port=25 action=dst-nat to-addresses=1.2.3.4 comment=someuniqueid
But you can't use hostname in to-addresses, so you need a script to update it (run it from scheduler with some reasonable frequency):
:local Host "mail.inbox.lv"
:do {
  :local NewIP [:resolve $Host]
  /ip firewall nat set [find comment="someuniqueid"] to-addresses=$NewIP
} on-error={
  :log info "unable to resolve $Host"
}
Thank you very much for answer - will test this out and come back!

Who is online

Users browsing this forum: JimGrisham and 62 guests