Arun Ramachandran
Arun Ramachandran

Reputation: 271

Setting up Mosquitto on home server

I'm struggling with exposing Mosquitto that I setup on my Centos7 homeserver to the outside internet through my router.

Mosquitto runs fine on my localhost and post 1883 on the homeserver. I am able to pub/sub, and it is listening on the port as 127.0.0.1:1883 (tcp)

My home router has a dynamic IP (for now), say 76.43.150.206. On the router I port forwarded 1883 as both internal/external ports to my home server, say 192.168.1.100.

In the mosquitto.conf file, I have one simply line "listener 1883 76.43.150.206".

When I then attempt to pub/sub using a python client on an external computer as mqttc.connect("76.43.150.206", 1883), it says connection refused.

Any hints on what I'm doing wrong or how to get it working? BTW, my understanding of this setup is very basic and I've pretty much been going off blogs.

Upvotes: 12

Views: 47066

Answers (2)

Trishant Pahwa
Trishant Pahwa

Reputation: 2943

Here's how it will work:

1.) Setup mosquitto.conf as

listener 1883 0.0.0.0
#cafile <path to ca file>
#certfile <path to server cert>
#keyfile <path to server key>
#require_certificate false

0.0.0.0 binds the server to all interfaces present.

You can uncomment the code to enable TLS for better security. But you'll have to configure the client to use the same as well..

2.) Port forward router's 1883 port number to port 1883 of IP of machine running the broker.

3.) Start the broker and test your client!

Upvotes: 23

hardillb
hardillb

Reputation: 59628

You should not put the external address into the mosquitto config file.

You should probably not even have a listen line at all as mosquitto will bind to all available IP addresses on the machine it's running with the default port (1883).

If you really must use the listen directive (e.g. in order to set up SSL) then it should be configured with the internal IP address of the machine running the broker, in this case 192.168.1.100 and with a different port number so it does not clash with the default

listen 1884 192.168.1.100

Upvotes: 2

Related Questions