Modbus TCP/IP Port 502 Explained: Setup, Security, and Troubleshooting

By | November 16, 2025

Every Modbus TCP/IP device listens on TCP port 502. This single port carries all Modbus communication over Ethernet — read requests, write commands, exception responses, and diagnostics.

Port 502 is registered with IANA (Internet Assigned Numbers Authority) under the service name “mbap” (Modbus Application Protocol). It has been the standard since the Modbus TCP specification was published in 1999.

Despite being one number, port 502 is at the center of most Modbus TCP problems: firewalls blocking it, connection limits being exceeded, security vulnerabilities being exploited, and configuration mismatches causing timeouts.

This guide covers everything about port 502 — how it works, how to configure it, how to secure it, how to troubleshoot it, and how the new Modbus/TCP Security specification adds TLS encryption on port 802.

1. Port 502: The IANA Registration

Port 502 is officially registered with IANA:

FieldValue
Service Namembap
Port Number502
Transport ProtocolTCP
DescriptionModbus Application Protocol
AssigneeSchneider Electric
Registration Date1999

The registration covers TCP only. Modbus TCP does not use UDP port 502. Some implementations support Modbus over UDP, but this is not part of the official specification and is not recommended for production systems.

The name “mbap” refers to the MBAP header (Modbus Application Protocol header) — the 7-byte header that wraps every Modbus PDU in a TCP frame.

2. How Modbus TCP Communication Works on Port 502

Modbus TCP uses a client-server model over TCP/IP:

  • The server (slave) listens on TCP port 502 and waits for incoming connections.
  • The client (master) opens a TCP connection to the server’s IP address on port 502.
  • The client sends Modbus requests (read registers, write coils, etc.).
  • The server processes each request and sends a response.
  • The TCP connection stays open for subsequent requests.

The client uses an ephemeral port (typically 49152–65535) on its side. The server always listens on port 502.

Example: A SCADA system at 192.168.1.10 connects to an energy meter at 192.168.1.100:502. The SCADA uses ephemeral port 52341. All Modbus frames flow between 192.168.1.10:52341 and 192.168.1.100:502.

3. The TCP Connection Lifecycle

Understanding the connection lifecycle helps with troubleshooting.

Step 1 — TCP Three-Way Handshake Client sends SYN to server port 502. Server responds with SYN-ACK. Client sends ACK. Connection established.

Step 2 — Modbus Transactions Client sends a Modbus request inside the MBAP header. Server processes and responds. This repeats for every poll cycle.

Step 3 — Connection Stays Open The Modbus specification recommends keeping TCP connections open rather than reconnecting for each transaction. Opening and closing connections wastes time and resources.

Step 4 — Connection Close The client closes the connection when it no longer needs to poll the device. Either side can close with a TCP FIN.

Step 5 — Connection Timeout If no traffic flows for a configurable period, many servers close idle connections automatically. Typical idle timeout: 30–120 seconds (device-dependent).

4. MBAP Header: What Gets Sent on Port 502

Every Modbus TCP message starts with a 7-byte MBAP header followed by the Modbus PDU.

FieldSizeExampleMeaning
Transaction ID2 bytes00 01Unique ID matching request to response
Protocol ID2 bytes00 00Always 0x0000 for Modbus
Length2 bytes00 06Number of bytes following (Unit ID + PDU)
Unit ID1 byte01Slave address (1–247) or 0xFF for direct TCP device

Example: Read 3 Holding Registers from Slave 6

Request on port 502:

00 01 00 00 00 06 06 03 00 6B 00 03

BytesFieldValue
00 01Transaction ID1
00 00Protocol IDModbus
00 06Length6 bytes follow
06Unit IDSlave 6
03Function CodeRead Holding Registers
00 6BStart AddressRegister 108
00 03Quantity3 registers

The MBAP header replaces the slave address and CRC used in Modbus RTU. The Unit ID serves the same purpose as the slave address — it identifies which device should respond, especially when a gateway bridges TCP to a serial bus with multiple RTU slaves.

For a deeper look at frame structure, see: Modbus Function Codes Explained

5. Client and Server Roles

RoleAlso CalledInitiates ConnectionListens on Port 502
ClientMasterYes (opens TCP connection)No
ServerSlaveNo (waits for connections)Yes

A single device can act as both client and server simultaneously. For example, a PLC can be a Modbus TCP server (other systems read its data on port 502) while also being a client (it polls energy meters on their port 502).

6. Connection Limits: How Many Clients Can Connect

Every Modbus TCP server has a maximum number of simultaneous TCP connections. This is a hardware and firmware limitation, not a protocol limitation.

Device TypeTypical Max Connections
Budget energy meters1–2
Mid-range PLCs4–8
Industrial PLCs (Siemens, Allen-Bradley)8–16
Protocol gateways4–32
Software simulators50–100+

If you exceed the limit, new connections are refused or existing connections are dropped. This is a common cause of intermittent communication failures in systems with multiple SCADA clients polling the same device.

Fix: Use a single SCADA master as the Modbus client and distribute data internally, or use a data concentrator/gateway.

7. Can You Change the Port from 502

Yes. Most devices allow custom port configuration. Common alternatives:

PortUse Case
502Default — use unless there is a reason to change
802Modbus/TCP Security (TLS-encrypted)
1502Security-through-obscurity (not recommended as sole protection)
5020Used by some vendors for secondary Modbus service

If you change the port, every client must be reconfigured to match. Firewall rules must also be updated. Changing the port does not add security — it only hides the service from basic scans.

8. Port 802: Modbus/TCP Security with TLS

The Modbus/TCP Security specification (published by the Modbus Organization) adds TLS encryption and X.509 certificate-based authentication to Modbus TCP.

FeaturePort 502 (standard)Port 802 (secure)
EncryptionNoneTLS 1.2+
AuthenticationNoneX.509v3 certificates
Data integrityTCP checksum onlyTLS HMAC
Role-based accessNoneDefined per certificate
Backward compatibleFalls back to port 502 if TLS fails (configurable)

Port 802 is registered with IANA under the service name “mbap-s” (Modbus Application Protocol — Secure).

The TLS handshake happens first, then standard Modbus TCP frames flow inside the encrypted TLS tunnel. The MBAP header and PDU structure remain unchanged — only the transport is encrypted.

Adoption is still limited. Most legacy devices do not support port 802. For existing installations, VPN tunnels remain the most practical way to encrypt Modbus TCP traffic.

9. Firewall Configuration for Port 502

Linux (iptables)

Allow Modbus TCP traffic from a specific SCADA IP:

iptables -A INPUT -p tcp --dport 502 -s 192.168.1.10 -j ACCEPT
iptables -A INPUT -p tcp --dport 502 -j DROP

Linux (firewalld)

firewall-cmd --permanent --add-port=502/tcp
firewall-cmd --reload

Windows Firewall

netsh advfirewall firewall add rule name="Modbus TCP 502" dir=in action=allow protocol=tcp localport=502

Industrial Firewall Best Practice

RuleSourceDestinationPortAction
Allow SCADA192.168.1.10192.168.2.0/24502ALLOW
Allow engineering192.168.1.20192.168.2.0/24502ALLOW
Block everything elseanyany502DROP

⚠️ Warning: Never expose port 502 to the internet. Thousands of Modbus devices are found on Shodan every day. Always use VPN for remote access.

10. Verifying Port 502 Is Open and Listening

From the server side (is the device listening?)

Linux:

ss -tlnp | grep 502

Windows:

netstat -an | findstr 502

From the client side (can I reach the device?)

Using netcat:

nc -zv 192.168.1.100 502

Using nmap:

nmap -p 502 192.168.1.100

Using telnet:

telnet 192.168.1.100 502

If the connection is refused, either port 502 is not open on the device, a firewall is blocking it, or the device is not reachable on the network.

11. Wireshark Filters for Modbus TCP Traffic

FilterWhat It Shows
modbusAll Modbus TCP traffic
tcp.port == 502All traffic to/from port 502
tcp.dstport == 502Requests sent to Modbus servers
tcp.srcport == 502Responses from Modbus servers
modbus.func_code == 3Only FC 03 (Read Holding Registers)
modbus.func_code == 16Only FC 16 (Write Multiple Registers)
modbus.func_code >= 128Only exception responses
ip.addr == 192.168.1.100 && tcp.port == 502Modbus traffic to/from one device
modbus && frame.time_delta > 1Slow responses (> 1 second gap)
Wireshark capture showing Modbus TCP/IP queries and responses on IANA default port 502.
Wireshark capture showing Modbus TCP/IP queries and responses on port 502

To test, run a Modbus client tool (like ModbusPoll or QModMaster) and capture with Wireshark on the same machine. You will see the MBAP header, function code, register addresses, and data values in plain text.

12. Security Risks of Port 502

Modbus TCP has zero built-in security:

  • No authentication — any device that can reach port 502 can read all data and send any command
  • No encryption — all data is plaintext, including register values and control commands
  • No access control — there is no concept of user roles or permissions
  • Predictable protocol — Modbus frames are simple and easy to craft with basic tools

Real Threats

AttackHow It Works
Unauthorized readAttacker connects to port 502 and reads all register data (process values, setpoints, alarms)
Command injectionAttacker sends FC 05 or FC 16 to write values — change setpoints, open valves, stop motors
ReconnaissanceAttacker scans port 502 across a network to map all Modbus devices
Man-in-the-middleAttacker intercepts and modifies Modbus frames between client and server
Denial of serviceAttacker floods port 502 with connections, exhausting the device’s connection limit

13. How to Secure Port 502 in Industrial Networks

Since Modbus TCP has no built-in security, protection must come from the network.

MeasureWhat It Does
Network segmentationPlace Modbus devices on a dedicated VLAN. Separate from corporate/IT networks.
Firewall rulesAllow only authorized SCADA IPs to reach port 502. Block all others.
VPN for remote accessNever expose port 502 to WAN or internet. Use encrypted VPN tunnels.
Industrial IDS/IPSDeploy OT intrusion detection to watch for abnormal Modbus commands on port 502.
Modbus/TCP Security (port 802)Upgrade to TLS-encrypted Modbus where devices support it.
Disable unused servicesIf a device does not need to be a Modbus server, disable port 502.
Connection monitoringAlert on unexpected client connections to port 502.

14. Troubleshooting Port 502 Problems

ProblemLikely CauseSolution
Cannot connect to deviceFirewall blocking port 502Check firewall rules. Test with nc -zv IP 502.
Connection refusedModbus service not enabled on deviceEnable Modbus TCP in device configuration. Verify with netstat.
Timeout after connectionWrong Unit IDCheck Unit ID in SCADA matches device configuration. Try 0, 1, and 255.
Intermittent disconnectionsConnection limit exceededReduce the number of Modbus TCP clients. Check device max connections.
Wrong data valuesRegister address offset or byte orderVerify zero-based vs one-based addressing. Check register map.
Exception code in responseInvalid function code or register addressCheck the exception code returned. Verify FC and register exist on device.
Slow responseNetwork congestion or device overloadCheck network latency with ping. Reduce poll rate. Read registers in larger blocks.
Connection drops after idleServer idle timeoutEnable TCP keep-alive on client side, or reduce idle timeout on server.

15. Port 502 in Real Systems

Energy Monitoring

A SCADA server polls 50 energy meters. Each meter listens on port 502 at its own IP address. The SCADA opens 50 TCP connections and polls every 5 seconds.

PLC Communication

A Siemens S7-1200 reads holding registers from a VFD (variable frequency drive). Both devices are on the same subnet. The PLC connects to the VFD on port 502 and reads speed, current, and status registers.

RTU-to-TCP Gateway

A Modbus TCP/RTU gateway listens on port 502. The SCADA sends TCP requests with Unit ID = 5. The gateway converts them to RTU frames and sends them to slave 5 on the RS-485 bus. For a full guide, see: How to Convert Modbus RTU to Modbus TCP

Multi-Site Remote Monitoring

A control center monitors remote pump stations over VPN. Each site has a PLC on port 502 behind a VPN gateway. The SCADA connects through the VPN tunnel to each PLC’s local IP on port 502.

Summary

Port 502 is the single entry point for all Modbus TCP communication. It is simple, universally supported, and has been the standard for over 25 years.

The key things to remember:

  • Port 502 is IANA-registered as “mbap” for Modbus TCP
  • Port 802 is the new secure variant with TLS (Modbus/TCP Security)
  • Servers listen on port 502. Clients connect to it.
  • Always configure firewall rules to restrict access to port 502
  • Never expose port 502 to the internet — use VPN for remote access
  • Connection limits vary by device — check the datasheet
  • Use Wireshark with filter modbus or tcp.port == 502 to diagnose problems

Decode and Test Your Modbus Frames

Need to verify your Modbus TCP frames? Use our free Online Modbus Frame Decoder & Encoder Tool to decode MBAP headers, function codes, and register values instantly.

Author: Zakaria El Intissar

I'm an automation and industrial computing engineer with 12 years of experience in power system automation, SCADA communication protocols, and electrical protection. I build tools and write guides for Modbus, DNP3, IEC 101/103/104, and IEC 61850 on ScadaProtocols.com to help engineers decode, analyze, and troubleshoot real industrial communication systems.

Leave a Reply

Your email address will not be published. Required fields are marked *