GoAdmio

mqtt

Install the Mosquitto MQTT broker on RHEL-family servers, open TCP port 1883 in the firewall, and write a minimal configuration that listens on all interfaces and allows anonymous clients

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/mqtt installs Eclipse Mosquitto, a lightweight broker for MQTT, the messaging protocol used by IoT devices, sensors, and many apps. The command:

[!WARNING] The result is an MQTT broker that anyone on the internet can connect to, with no username, password, or encryption. Anyone can read the messages and publish their own. Secure the broker (see Securing the broker) before you restart it or put it into use.

The command works on RHEL-family servers that use firewalld (AlmaLinux, Rocky, CentOS, Red Hat, Fedora). It does not check the operating system.


Quick start

# 1. Install and configure Mosquitto
/go/mqtt

# 2. Secure the configuration before the broker restarts (see "Securing the broker")
sudo nano /etc/mosquitto/mosquitto.conf

# 3. Apply it
sudo systemctl restart mosquitto

Syntax

/go/mqtt
Form Behavior
/go/mqtt Opens the port, installs Mosquitto, and writes the configuration.

Options

This command has no options. Arguments are only written to the log file.


Output

The command prints what firewall-cmd and dnf print, such as success for each firewall step and the package installation progress. There is no final message. Every run is recorded in /var/log/go/mqtt.log.

[!IMPORTANT] The configuration file is written after the service is restarted, and the service is not restarted again. Mosquitto keeps running with its previous settings until the next restart or reboot. After that, it listens on all interfaces and allows anonymous clients.


Examples

# Install Mosquitto
/go/mqtt
# Test it from the server: in one terminal, listen...
mosquitto_sub -h localhost -t "test/topic"

# ...and in another, publish a message
mosquitto_pub -h localhost -t "test/topic" -m "Hello MQTT"
# Check the service and the open port
systemctl status mosquitto
sudo firewall-cmd --list-ports

Troubleshooting

Symptom Likely cause Fix
firewall-cmd: command not found or dnf: command not found The server is not a RHEL-family system with firewalld. The command does not support it. Install Mosquitto and open the port with your system's tools.
No match for argument: mosquitto The package isn't in the enabled repositories. On some systems it comes from EPEL. Enable the EPEL repository, then run the command again.
Other servers can't connect right after the command The service is still running with its previous settings. Restart it with sudo systemctl restart mosquitto, after securing the configuration.
Anyone can connect and publish Anonymous access is on, by design of the command. See Securing the broker.
Your configuration changes disappeared Running the command again overwrites /etc/mosquitto/mosquitto.conf. Don't run it again after you customize the file. Restore your settings from your own copy.
You want the original configuration back The first run saved it as /etc/mosquitto/mosquitto.bak. Copy that file back to mosquitto.conf, then restart the service.
Port 1883 is still reachable after you secured the broker The firewall rule is still open. Close it with deny, and check with sudo firewall-cmd --list-ports.
Clients still can't connect A firewall or security group outside the server (at your hosting provider) blocks the port. Open TCP 1883 there as well.
Connection refused The service isn't running. Check systemctl status mosquitto.

Details

What it does

  1. Writes the command and its arguments to /var/log/go/mqtt.log.
  2. Opens TCP 1883 in firewalld's public zone, permanently, and reloads the firewall.
  3. Installs mosquitto with dnf, enables it at boot, and restarts it.
  4. If /etc/mosquitto/mosquitto.bak does not exist, moves the original mosquitto.conf to that name. Later runs keep the first backup.
  5. Writes /etc/mosquitto/mosquitto.conf with exactly two lines:
listener 1883 0.0.0.0
allow_anonymous true
Line Effect
listener 1883 0.0.0.0 Accept connections on port 1883 on every network interface.
allow_anonymous true Accept clients without a username or password.

The configuration has no authentication, no access rules, and no encryption (TLS). MQTT on port 1883 is plain text.

Securing the broker

A safer configuration (replace the file's contents, then restart the service):

listener 1883 127.0.0.1
allow_anonymous false
password_file /etc/mosquitto/passwd
# Create a user (you will be asked for a password)
sudo mosquitto_passwd -c /etc/mosquitto/passwd myuser

sudo systemctl restart mosquitto

This example is general Mosquitto practice and is not part of the command. Test it on your server before relying on it.

Firewall

The port is opened directly with firewall-cmd, not through GoAdmio's own firewall command. If you later reset or rebuild the firewall with firewall, check that the rule is still what you want with sudo firewall-cmd --list-ports.


See also

Command Description
firewall Install and configure the server firewall (firewalld or UFW) with GoAdmio's default open ports, and start, stop, or reset it
allow Open a TCP port in the server firewall
deny Close a TCP port by removing its allow rule from the server's firewall
status Collect the status of every systemd service
memcached Install Memcached, enable it at boot, and restrict it to localhost with UDP turned off