Well-known · Cross-platform

502 Modbus

TCP Yes
UDP Yes
SCTP
DCCP

What it is

Modbus/TCP industrial automation protocol.

When / why

OT/SCADA. No authentication — strictly segment from IT networks.

Protocol status detail

TransportStatusMeaning
TCP Yes Assigned by IANA and standardized, specified, or widely used on this port.
UDP Yes Assigned by IANA and standardized, specified, or widely used on this port.
SCTP Not applicable for this transport.
DCCP Not applicable for this transport.

Port range

Well-known (0–1023). System port for a core service. On Unix-like systems, binding it requires superuser privileges.

Browse all ports →

Firewall rules for port 502

Copy-ready inbound rules for the active transports. Replace every <source> placeholder with the specific host, subnet, or CIDR that should reach this port.

⚠ Unencrypted or unauthenticated by default — prefer a TLS variant or tunnel over VPN/SSH rather than exposing this port directly.

ufw

sudo ufw allow proto tcp from <source> to any port 502

Allow TCP 502 (Modbus). Replace <source> with the network/host that should reach it.

sudo ufw allow proto udp from <source> to any port 502

Allow UDP 502 (Modbus). Replace <source> with the network/host that should reach it.

firewalld

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<source>" port port="502" protocol="tcp" accept'

Allow TCP 502 (Modbus) from <source>. Run 'firewall-cmd --reload' afterwards.

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<source>" port port="502" protocol="udp" accept'

Allow UDP 502 (Modbus) from <source>. Run 'firewall-cmd --reload' afterwards.

nftables

nft add rule inet filter input ip saddr <source> tcp dport 502 accept

Allow TCP 502 (Modbus). Assumes table 'inet filter' with an 'input' chain.

nft add rule inet filter input ip saddr <source> udp dport 502 accept

Allow UDP 502 (Modbus). Assumes table 'inet filter' with an 'input' chain.

iptables

sudo iptables -A INPUT -p tcp -s <source> --dport 502 -j ACCEPT

Allow TCP 502 (Modbus). Persist with iptables-save/netfilter-persistent.

sudo iptables -A INPUT -p udp -s <source> --dport 502 -j ACCEPT

Allow UDP 502 (Modbus). Persist with iptables-save/netfilter-persistent.

Azure NSG

az network nsg rule create -g <resource-group> --nsg-name <nsg> -n Allow-modbus-502 --priority 1000 --access Allow --direction Inbound --protocol "*" --source-address-prefixes <source> --destination-port-ranges 502

Inbound rule for 502 (Modbus). Set <source> to a CIDR; lower priority number = higher precedence.

AWS Security Group

aws ec2 authorize-security-group-ingress --group-id <sg-id> --ip-permissions IpProtocol=tcp,FromPort=502,ToPort=502,IpRanges="[{CidrIp=<source-cidr>}]"

Inbound TCP 502 (Modbus). Replace <source-cidr> (e.g. 10.0.0.0/16).

aws ec2 authorize-security-group-ingress --group-id <sg-id> --ip-permissions IpProtocol=udp,FromPort=502,ToPort=502,IpRanges="[{CidrIp=<source-cidr>}]"

Inbound UDP 502 (Modbus). Replace <source-cidr> (e.g. 10.0.0.0/16).

GCP firewall

gcloud compute firewall-rules create allow-modbus-502 --direction=INGRESS --action=ALLOW --rules=tcp:502,udp:502 --source-ranges=<source-cidr> --network=<network>

Ingress rule for 502 (Modbus). Scope with --source-ranges and optionally --target-tags.

Windows netsh

netsh advfirewall firewall add rule name="Allow Modbus 502/TCP" dir=in action=allow protocol=TCP localport=502 remoteip=<source>

Inbound TCP 502 (Modbus). Set remoteip to a host/subnet; 'any' is discouraged.

netsh advfirewall firewall add rule name="Allow Modbus 502/UDP" dir=in action=allow protocol=UDP localport=502 remoteip=<source>

Inbound UDP 502 (Modbus). Set remoteip to a host/subnet; 'any' is discouraged.

Windows PowerShell

New-NetFirewallRule -DisplayName "Allow Modbus 502/TCP" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 502 -RemoteAddress <source>

Inbound TCP 502 (Modbus). Replace <source> with a host or subnet.

New-NetFirewallRule -DisplayName "Allow Modbus 502/UDP" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 502 -RemoteAddress <source>

Inbound UDP 502 (Modbus). Replace <source> with a host or subnet.

Rules are generated only for transports marked active for this port. They default to an inbound allow with an explicit source placeholder — never any. Review direction, scope, and rule precedence before applying in production.