Auto Redirect IP with Port

Hi Mikrotik members

I have setup MySpeed into container, for monitoring my Network speed. But when try to load into browser it need to insert with port 5216 which is default port on mySpeed portal. Is there some NAT settings that i can force this process to “auto enter” the port when MySpeed container IP is insesrted into browser? For ex. if i enter 192.168.35.2 in need to autoadd port to ip so final adress will be 192.168.35.2:5216 ? IS this possible? thanks for answers.

Add a dstnat firewall rule.

This is what the Docker/Podman --publish flag does for you automatically, which you must do by hand on RouterOS. Details.

Not really (@OP is asking how to instruct browser to connect to non-standard port). Whenever client app needs to access server app, it has to know which port to use. In your case client app is browser and they assume standard port for http (80) and lately they assume https (443). Browsers are perfectly capable of working with other ports, but they have to be instructed so. Your server app (myspeed) can “talk” http to clients but uses port which is not assuned (default) for http.

So browser has to be informed about using non-default port. Generally there are two ways and none has anything to do with router/firewall:

  1. user enters into browser’s address line server name (or IP address) and port number. If URL is saved as bookmark, then port number gets saved as well
  2. server runs a web server on standard http (and https due to browsers starting to assume https) port with sole task: to instruct browser to go (i.e. send response with code 302 or 303 or 307) to another URL (e.g. the one with non-standard port). The server can be a very trivial one (no need for full featured web server such as apache or nginx).

It’s the option #2 when e.g. user simply enters in address line … but in next second or so URL changes to https://www./us-en or something like that.
Some browsers try to adjust incomplete entries in address line (like prefixing entry with www and postfixing it with com) if they can’t resolve user’s input into IP/IPv6 address. But this kind of method will never try non-standard ports. And such behaviour was largely replaced by calling search engine of user’s choice (e.g. google) in recent years.

@mkx thanks for answer. So it seems that this cant be done in way i liked. No matter, will find another acceptable solution for this.

Well, if we assume that the final desired result is:
a. type the destination IP address in the browser without specifying port
b. somehow connect the browser on a specific port of the specific destination IP address

a dstnat port remapping seems like a possible solution, it should be something like:

/ip firewall nat
add action=dst-nat chain=dstnat dst-address=192.168.35.2 dst-port=80 protocol=tcp  to-ports=5216
add action=dst-nat chain=dstnat dst-address=192.168.35.2 dst-port=443 protocol=tcp  to-ports=5216

depending if the used port for the browser connection is normally 80 or 443, right?

A browser bookmark with the port number included seems to me a lot simpler, though :slight_smile: .

Very likely full hair-pin NAT is required as well if the non-standard port is to mapped to standard one for LAN access as well. And hair-pin NAT comes with a bag of annoyances (e.g. “why don’t I see real client IP addresses in server’s log, I can only see router IP”) so I try to avoid it (and managed so far on all of my locations :wink:).

This also makes sense. Thanks for this information. I first time have situation like this, and today learned something usefull.

Many thanks. The code:

add action=dst-nat chain=dstnat dst-address=192.168.35.2 dst-port=80 protocol=tcp  to-ports=5216

makes the trick. Now just enter the IP, and it load the container dashboard without any ports to insert. I have many containers (some on my Mikrotik) and others on Mini PC with Proxmox, so remember all that ports its nightmare for me. This makes the work easy.