Broker Testing

How to Check if an MQTT Port Is Open (nc, telnet, nmap)

Check whether MQTT ports 1883, 8883, 8083 or 8084 are open with nc, telnet, nmap and PowerShell Test-NetConnection, and tell firewall problems from broker ones.

Updated · 7 min read

How to Check if an MQTT Port Is Open (nc, telnet, nmap)

To check whether an MQTT port is open, run nc -vz -w 5 broker.connectmq.com 1883 on Linux or macOS, or Test-NetConnection broker.connectmq.com -Port 1883 in PowerShell. "Succeeded" means a TCP connection was accepted; "refused" or "timed out" tells you where to look next. This guide shows each tool, what its output means, and how to tell a firewall problem from a broker problem.

The ports to check

PortTransportTypical use
1883MQTT over TCPPlain MQTT, development, trusted networks
8883MQTT over TLSProduction devices
8083 / 8080MQTT over WebSocketBrowsers on http pages, local tools
8084 / 8443 / 443MQTT over secure WebSocketBrowsers, restrictive networks

Exact numbers depend on the broker's configuration — see MQTT ports explained. For the examples below we use broker.connectmq.com, which listens on 1883, 8883, 8083 and 8084.

nc (netcat) — Linux and macOS

nc -z opens a TCP connection and closes it without sending data; -v prints the result and -w 5 gives up after five seconds.

Check one port
nc -vz -w 5 broker.connectmq.com 1883
Possible results
Connection to broker.connectmq.com port 1883 [tcp/ibm-mqtt] succeeded!
nc: connect to broker.connectmq.com port 1883 (tcp) failed: Connection refused
nc: connect to broker.connectmq.com port 1883 (tcp) failed: Connection timed out

The exact wording varies between netcat variants (macOS prints connectx to ..., some builds print open), but the three outcomes are always the same. Check all MQTT ports in one go:

All MQTT ports
for p in 1883 8883 8083 8084; do nc -vz -w 5 broker.connectmq.com "$p"; done

No nc installed? Bash can open a TCP socket by itself:

Bash only
timeout 5 bash -c '</dev/tcp/broker.connectmq.com/1883' && echo open || echo closed

telnet

telnet is still installed on many servers and works on Windows once the Telnet Client feature is enabled:

telnet
telnet broker.connectmq.com 1883
Output
Trying 203.0.113.10...
Connected to broker.connectmq.com.
Escape character is '^]'.

Connected to means the port is open. Press Ctrl+] and type quit to leave. If you instead see telnet: Unable to connect to remote host: Connection refused, nothing accepted the connection; a long pause followed by Connection timed out points to a filter in between. Don't type anything after connecting — MQTT is a binary protocol, and the broker will close the connection once its connect timeout expires without a valid CONNECT packet. That is normal.

nmap — several ports and their state

nmap reports a clear state for every port, which makes it the best tool to separate "closed" from "filtered":

nmap
nmap -Pn -p 1883,8883,8083,8084 broker.connectmq.com
Example output (8084 blocked by a local firewall)
PORT     STATE    SERVICE
1883/tcp open     mqtt
8883/tcp open     secure-mqtt
8083/tcp open     us-srv
8084/tcp filtered websnp
StateMeaning
openSomething accepted the TCP connection
closedHost reachable, nothing listening (TCP reset)
filteredNo reply — a firewall dropped the probe

-Pn skips the ping check, which many cloud hosts block. The SERVICE column is just nmap's port-number guess, not proof that MQTT is running there.

PowerShell Test-NetConnection — Windows

PowerShell
Test-NetConnection broker.connectmq.com -Port 1883
Output
ComputerName     : broker.connectmq.com
RemoteAddress    : 203.0.113.10
RemotePort       : 1883
TcpTestSucceeded : True

On failure you'll see WARNING: TCP connect to (203.0.113.10 : 1883) failed and TcpTestSucceeded : False. Use -InformationLevel Quiet to get just True / False for scripts. If a local broker is unreachable from other machines, the Windows Defender Firewall is a frequent cause — see MQTT and the Windows firewall.

Reading the result: firewall or broker?

ResultWhat it meansWhere to look
Open / succeededTCP works end to endMove up a layer: TLS and MQTT (below)
Connection refusedHost reached, no listener on that portIs the broker running? Which address and port does it listen on?
Timed out / filteredPackets dropped somewhereHost firewall, cloud security group, corporate proxy, wrong IP
Name not resolvedDNS problem, not a port problemCheck the host name — see testing DNS and network

Then run the same check from a second network — your phone's hotspot, a cloud VM, a colleague's machine. If the port is open from outside but not from your office, your network blocks it (common for 1883 and 8883 on corporate and guest Wi-Fi; see MQTT behind a corporate firewall). If it's closed everywhere, the problem is on the broker side.

On the broker host: is anything listening?

If you run the broker yourself and see "refused", check what is listening:

Linux / macOS
sudo ss -ltnp | grep -E '1883|8883'        # Linux
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -E '1883|8883'   # macOS
Windows
netstat -ano | findstr :1883

A listener on 127.0.0.1:1883 accepts only local connections. Mosquitto 2.x does this by default when no listener is configured and logs Starting in local only mode. Connections will only be possible from clients running on this machine. Add an explicit listener (and authentication) to accept remote clients:

mosquitto.conf
listener 1883 0.0.0.0
allow_anonymous false
password_file /etc/mosquitto/passwd

The Mosquitto config generator builds a complete file with TLS and WebSocket listeners. In Docker, also check that the port is published (-p 1883:1883).

Open port, still no connection? Test the next layer

An open port proves only that TCP works. Two quick checks cover the layers above it:

TLS: does the port speak TLS, and which certificate?
openssl s_client -connect broker.connectmq.com:8883 -servername broker.connectmq.com </dev/null
MQTT: does the broker answer CONNECT with CONNACK?
mosquitto_pub -h broker.connectmq.com -p 1883 -t testmqtt/port-check/ping -m ok -d

With -d, a healthy broker shows a sending CONNECT line followed by received CONNACK (0). A non-zero CONNACK is an authentication or protocol problem — look the code up with the reason codes tool. If TLS hangs on 1883 or MQTT fails on 8883, you have mixed up the plain and TLS ports. Certificate errors are covered in testing a TLS connection. Finally, connect with the online MQTT client to confirm a full publish/subscribe round trip.

Confirm with a real MQTT round trip

Checking a port takes seconds and splits the problem in two: if TCP fails, it's a network, firewall or listener issue; if TCP succeeds, look at TLS, credentials and MQTT itself. Run the check from more than one network, read "refused" and "timed out" differently, and you'll know where to look before opening a single log file.

Frequently asked questions

How do I check if port 1883 is open?

Run nc -vz -w 5 host 1883 on Linux or macOS, or Test-NetConnection host -Port 1883 in PowerShell on Windows. "succeeded" or TcpTestSucceeded : True means a TCP connection was accepted; refused or timed out means it was not.

What is the difference between connection refused and timed out?

Refused means the host answered but nothing is listening on that port (or a firewall actively rejected it). Timed out means no answer at all, which usually points to a firewall or security group silently dropping packets, a wrong IP, or a routing problem.

The port is open but my MQTT client still cannot connect. Why?

An open port only proves TCP works. The failure is then at the TLS or MQTT layer: wrong port for TLS vs plain TCP, certificate problems, a WebSocket port used for raw MQTT, wrong credentials or a rejected client ID. Check the CONNACK reason code with mosquitto_pub -d.