Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
153 stars 55 forks source link

Why failed to initialized when I turn on the firewall #140

Closed welpher closed 5 years ago

welpher commented 5 years ago

RT,but I turn off the firewall everything is looking good. ENV: Centos 7 host , HA in docker, firewalld public zone

Is there another port using by PyXiaomiGateway except tcp port 8123 ?

syssi commented 5 years ago

The gateway publishes multicast messages to 224.0.0.50:9898. This library publishes UDP messages to the gateway IP. The destination port can vary and is part of the discovery response.

https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L20-L21 https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L105-L107

The discovery port is 4321 (multicast, too). Home Assistant is using tcp port 8123 for the web interface.

welpher commented 5 years ago

I added 9898 and 4321 port (both udp and tcp) to firewalld allowed port , but failed to initialized too

syssi commented 5 years ago

What about

iptables -A INPUT   -m pkttype --pkt-type multicast -j ACCEPT
iptables -A FORWARD -m pkttype --pkt-type multicast -j ACCEPT
iptables -A OUTPUT  -m pkttype --pkt-type multicast -j ACCEPT

# or

iptables -A INPUT   -s 224.0.0.0/4 -j ACCEPT
iptables -A FORWARD -s 224.0.0.0/4 -d 224.0.0.0/4 -j ACCEPT
iptables -A OUTPUT  -d 224.0.0.0/4 -j ACCEPT
welpher commented 5 years ago

I add firewall-cmd rules like this, Both not working for me.

syssi commented 5 years ago

I cannot help here without further details. It's a firewall issue and could be solved by a traffic capture (active vs. inactive firewall).

welpher commented 5 years ago

Finnaly, I give up docker in Centos 7 with firewalld active run HA, I cannot find out why not working in this ENV. But It's working when inactive firewall.