RabbitMQ
TCP Port
Network Configuration
Server Management
Tech Guides

How to disable RabbitMQ default tcp listening port - 5672

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

RabbitMQ is a widely utilized open-source message-broker software that facilitates asynchronous communication and implements the Advanced Message Queuing Protocol (AMQP). By default, it listens on TCP port 5672 for such AMQP connections. However, there may be scenarios—such as security policies, specific application needs, or environment setups—where you need to disable this default port. In this article, we will explore how you can achieve this modification through the RabbitMQ configuration.

Understanding RabbitMQ Configuration

Configuring RabbitMQ involves manipulating its configuration file, which could be rabbitmq.conf on newer installations or the older rabbitmq.config format. The location of this configuration file might vary based on the operating system and the method of installation (package manager, direct download, etc.).

Disabling the Default Port

To disable the default TCP listening port (5672), you should adjust the listeners for AMQP within the RabbitMQ configuration file (rabbitmq.conf). Essentially, you must specify that no listeners should be available for AMQP or you can change the default listening port to a different one if the service still needs to be accessible.

Here’s how it can be achieved:

plaintext
# rabbitmq.conf
## Disable the default AMQP listener on port 5672
listeners.tcp.default = none

After making this change, it’s necessary to restart RabbitMQ for the changes to take effect. This can typically be done using your system’s service management (like systemctl restart rabbitmq-server on systemd-based systems).

Alternative Configuration: Different Port or Interface

If you need RabbitMQ to listen for AMQP connections on a different port or network interface, configure it like this:

plaintext
1# rabbitmq.conf
2## Set RabbitMQ to listen on port 5673 instead of the default 5672
3listeners.tcp.default = 5673
4
5## Or specify an interface
6listeners.tcp.1 = 192.168.1.5:5672

Security Considerations

When disabling a default port or redirecting traffic to a different port or interface, you must also consider possible security implications:

  • Ensure firewall rules are updated accordingly to prevent unauthorized access.
  • Consider using TLS/SSL for encrypting traffic, especially when engaging with interfaces exposed to public networks.
  • Regularly update and patch RabbitMQ and its dependencies to mitigate vulnerabilities.

Testing Configuration Changes

After configuration changes, always ensure that RabbitMQ behaves as expected:

  1. Check the RabbitMQ service status.
  2. Validate the listening ports using tools like netstat or ss.
  3. Test the connectivity from a client to see if it still functions appropriately.

You can use the following command to check the listening ports:

bash
sudo ss -tulwn | grep 5672

If the configurations are correctly set, this command should not return any result for port 5672, indicating that RabbitMQ no longer listens on the default port.

Summary Table

Here is a summary of key actions and points:

ActionDescriptionCommand/Code Example
Disabling the Default PortStop RabbitMQ from listening on port 5672listeners.tcp.default = none
Changing the Listening PortSet RabbitMQ to listen on a different portlisteners.tcp.default = 5673
Specify Listening Interface and PortDefine a specific interface and portlisteners.tcp.1 = 192.168.1.5:5672
Restart RabbitMQ After ChangesMake configuration changes effectivesystemctl restart rabbitmq-server
Verify No Listening on Default PortCheck RabbitMQ is not listening on port 5672sudo ss -tulwn | grep 5672

Additional Resources

For readers interested in further particulars about RabbitMQ’s management and configuration:

  • RabbitMQ’s official documentation offers a comprehensive guide: RabbitMQ Documentation
  • For security best practices, refer to the Security section in the official documentation.

By adhering to the steps outlined in this article, you can effectively manage how RabbitMQ listens for AMQP connections, enhancing both the flexibility and security of your message broker setups.


Course illustration
Course illustration

All Rights Reserved.