skip to Main Content

I’m running Mosquitto 2.0.15 on ubuntu 20.04

and I want to configure to listen on a specific interface,
but I don’t want to hardcode the interface address

the interface I want to listen on is:

enp3s0: connected to Wired connection 1
        "Realtek RTL8111/8168/8411"
        ethernet (r8169), 00:E2:69:3D:CA:C2, hw, mtu 1500
        ip4 default
        inet4 192.168.2.115/24
        route4 0.0.0.0/0
        route4 192.168.2.0/24
        inet6 fe80::9490:96c4:9f56:d81c/64
        route6 fe80::/64

Can anybody please help me?

Thanks,
Nadav

I run the mosquitto like this:

sudo mosquitto -v -c mosquitto.conf

If I configure the mosquitto like this:

listener  8882 192.168.2.115
protocol mqtt
allow_anonymous true

it works OK,

I tried this:

listener  8882
bind_interface enp3s0
protocol mqtt
allow_anonymous true

but I get error:

2022/11/30 10:35:12: Opening ipv4 listen socket on port 8882.
2022/11/30 10:35:12: Opening ipv6 listen socket on port 8882.
2022/11/30 10:35:12: Error: Invalid argument

I tried this:

listener  8882
bind_interface Wired connection 1
protocol mqtt
allow_anonymous true

and I get:

2022/11/30 10:35:55: Opening ipv4 listen socket on port 8882.
2022/11/30 10:35:55: Warning: Interface Wired connection 1 does not support IPv4 configuration.
2022/11/30 10:35:55: Opening ipv6 listen socket on port 8882.
2022/11/30 10:35:55: Warning: Interface Wired connection 1 does not support IPv6 configuration.

I even tried (there is NO eth0 interface):

listener  8882
bind_interface XXXX
protocol mqtt
allow_anonymous true

and I get:

2022/11/30 10:37:29: Opening ipv4 listen socket on port 8882.
2022/11/30 10:37:29: Warning: Interface XXXX does not support IPv4 configuration.
2022/11/30 10:37:29: Opening ipv6 listen socket on port 8882.
2022/11/30 10:37:29: Warning: Interface XXXX does not support IPv6 configuration.

2

Answers


  1. Chosen as BEST ANSWER

    problem is with ipv6

    strace shows

    bind(5, {sa_family=AF_INET6, sin6_port=htons(8882), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "fe80::9490:96c4:9f56:d81c", &sin6_addr), sin6_scope_id=0}, 28) = -1 EINVAL (Invalid argument)
    write(2, "1669878630: Error: Invalid argum"..., 361669878630: Error: Invalid argument
    )
    

    adding

    socket_domain ipv4
    

    to the config file solves the problem

    mosquitto documentation does not say that bind_interface only works on ipv4


  2. The correct syntax is

    listener  8882
    bind_interface enp3s0
    protocol mqtt
    allow_anonymous true
    

    And works as expected (with a suitable changed device name to match my wifi adapter) on my Ubuntu 20.04 machine with mosquitto 2.0.15.

    Do you have more in your config file that the syntax error could be releated to?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search