Modbus TCP Server on port 502

Hi .
I am trying to create a TCP modbus server on standard port 502, but when using this port , I do not know why but the system crash.
Does anyone have experience in this matter?


How are you trying to create the modbus TCP server? If you are using a node-red node then tell us which one (node-red-contrib-something possibly).
Assuming the question does involve node red then seeing the node-red log might be very helpful. How to get that depends on your operating system. If the mechanism that you use for running node-red shows you message starting with Welcome to Node Red then that is what we want. If you are not seeing that then possibly running, in a terminal window the commands


will show it. If not tell us the OS.
If you can see the log then first look to see if there are any messages that tell you what the problem is, otherwise copy/paste the log here down to the point that it crashes. If the log does not show any evidence of the crash explain exactly what you mean by crashing.

Not to bump an old thread, but for anyone who comes searching, the most likely culprit is needing root access to listen on a port less than 1024, assuming you're running Node-RED on a Linux device.

1 Like

I am using the node-red-contrib-modbus and every time I had a Modbus Server node and give it an IP it crashes. I have tried this on several PI 3B+ 32 systems.
Each time I have to delete the flow and reimport it to get the flow to work again.
It has nothing to do with ports less than 1024 either as I have used the default 10502 with it still crashing Node Red.

It sounds like a very useful node if it would work.

Since you say this is not related to the port then it is not related to this problem. Please start a new thread.
When you get a crash like this you can start node red using
node-red --safe
which will start it without running the flows. When you deploy, it will start the flows and you may well get further information on the problem in the console.
But as I said, please start a new thread after you have done this, if you still need help.

I notice that on both your previous posts you asked a question but then never replied to the attempts to help you. That does not make it more likely that others will try to help you here.

Thanks Colin,

I am fairly new to the whole forum thing and I consider your response to be most admirable.

Thanks again, and I will try to follow protocol a bit better in future :blush:

Hi again,

Turns out the problem it is a on port 502 and could potentially be resolved with @thatcadguy suggestion.
I don't really know how to give root access to individual nodes within Node Red?
This issue only conflicts with the Modbus server node, as I am able to use the read and write nodes on port 502

Why do you need to use that port?

Existing PLCs on the network are preconfigured to write to port 502. The code is all locked out with target IP address being the only editable text field in the HMI.

Nearly all Modbus clients are programmed to use port 502 for Modbus.

You need to permit non root user to bind to port < 1024. Search this forum and google. Been covered a few times.

something like sudo setcap 'cap_net_bind_service=+ep' `which node` or sudo setcap 'cap_net_bind_service=+ep' $(eval readlink -f `which node`) should do the trick

Read this thread

and this

Or configure your firewall to redirect that port to a higher one.

Thanks @StevecI,

But I was still unable to stop the crash from happening.
I tried to following suggested commands and still no luck.

pi@SESS:~ sudo setcap 'cap_net_bind_service=+ep' /usr/bin/node pi@SESS:~ sudo setcap -v 'cap_net_bind_service=+ep' /usr/local/bin/node
/usr/local/bin/node differs in [pe]
pi@SESS:~ sudo setcap 'cap_net_bind_service=+ep' (eval readlink -f /usr/bin/node)
pi@SESS:~ $


Ok cool!
It appears everything is now functioning properly and I am able to maintain a stable Modbus server.

Thanks for your assistance :slight_smile:

Tengo un problema similar de comunicion con modbus y no logro que el puerto 502 aparesca abierto a pesar que el firewall lo ha abierto.
Lei como lo soluciono Ud. pero no puedo entender nadas de lo que hizo.
Seria tan amable de explicarl mas ampliamente lo que hizo para lograr que funcionara ?