Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdns over Wireguard interface flushes Wireguard IP and use IP from router #5807

Closed
MoraeFox opened this issue May 17, 2024 · 4 comments
Closed

Comments

@MoraeFox
Copy link

MoraeFox commented May 17, 2024

The problem

Hello community 😸 !
I'm pretty much enjoying this wonderful project!

I run HA container, ESPhome container on (AWS + Wireguard). mdns works after all, but it flushes Wireguard interface's IP and multicasts router assigned IP.
Statically assigned ESPs wireguard IP and it appears on HA.

https://wget.seoul-it-prod.com/mdns_aws_wg0.pcap

First here is how it's configured.

  • On Aws ubuntu, installed Wireguard, Avahi-daemon, configured them.
  • Deployed HA docker and ESPhome docker container under host network.
  • So HA and ESPhome can access to wg0 interface.
  • My phone is working as LTE router for ESPs and assigned 192.168.184.x to connected ESPs while Wireguard interface on AWS is starting from 10.13.13.x
  • Inside HA, ESPhome container, I can ping to other Wireguard clients
  • If ESP devices are connected to Wireguard server, HA, ESPhome container can see them. 10.13.13.1 can ping to ESP(10.13.13.4).
  • While adding the ESP devices to HA, no auto detection, no service found. Statically added devices, manually added services to HA container. LED on ESP8266 can be used from HA on AWS.
  • Now instead of using ESPhome on my home server, ESPhome in AWS trying to update ESP devices wirelessly, but it says 192.168.184.128 device cannot be found while Wireguard interface is 10.13.13.4. This way it will never be found.
  • I dumped wg0 interface and the packet dump I attached on the top is the result. ESP device first multicasts Wireguard ip than sends it's router ip next, flushing Wireguard's IP.

I'm totally newB to mdns, multicast, broadcast stuff like that, not sure if this intended behavior?
Or should there be an option like [- preferrd interface] in yaml?

Thanks in advance 🙇‍♂️

Which version of ESPHome has the issue?

2024.5.0

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

2024.5.3

What platform are you using?

ESP8266

Board

esp8266 dev kit

Component causing the issue

Wireguard, mdns

Example YAML snippet

~~~
time:
  - platform: sntp

# Example configuration entry
wireguard:
  address: 10.13.13.4
  private_key: [private_key]
  peer_endpoint: [My domain]
  peer_public_key: [peer_public_key]

  netmask: 0.0.0.0

  peer_port: 51820

  peer_preshared_key: [peer_preshared_key]

  peer_allowed_ips:
    - 10.13.13.1/32    #Mandatory, WG gateway
    - 224.0.0.251/32   #Mandatory, Broadcast
    - 172.31.9.229/32  # Test
    - 127.0.0.1/32     # Test

  peer_persistent_keepalive: 25s

binary_sensor:
  - platform: wireguard
    status:
      name: 'WireGuard Status'
  - platform: wireguard
    enabled:
      name: 'WireGuard Enabled'

~~~

Anything in the logs that might be useful for us?

Packet dump of wg0 interface :
- https://wget.seoul-it-prod.com/mdns_aws_wg0.pcap

ESPhome update error when freshly mdnsed/connected:
~~~
========================= [SUCCESS] Took 3.18 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.184.128
ERROR Connecting to 192.168.184.128:8266 failed: timed out

ESPhome update error when mdnsed like 10 minute ago:
~~~
========================= [SUCCESS] Took 3.18 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of test.local
WARNING Error with socket 4 (('10.13.13.1', 5353))): [Errno 126] Required key not available
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 1196, in sendto
    self._sock.sendto(data, addr)
OSError: [Errno 126] Required key not available
ERROR Error resolving IP address of test.local. Is it connected to WiFi?
ERROR (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
ERROR Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -2] Name or service not known

Additional information

No response

@MoraeFox
Copy link
Author

I'm also attaching log from serial port but nothing about mdns :(

[I][wifi:303]: WiFi Connecting to 'Jeong_M'...
[W][wifi_esp8266:219]: wifi_apply_hostname_(test): lwIP error -16 on interface st (index 0)
[D][wireguard:105]: WireGuard remote peer is offline (latest handshake 2024-05-17 01:03:07 UTC)
[D][wireguard:237]: WireGuard is waiting for local network connection to be available
[I][wifi:597]: WiFi Connected!
[C][wifi:408]: Local MAC: D8:F1:5B:11:BF:8C
[C][wifi:413]: SSID: [redacted]
[C][wifi:416]: IP Address: 192.168.4.1
[C][wifi:416]: IP Address: 192.168.184.128
[C][wifi:419]: BSSID: [redacted]
[C][wifi:421]: Hostname: 'test'
[C][wifi:423]: Signal strength: -36 dB ▂▄▆█
[C][wifi:427]: Channel: 11
[C][wifi:428]: Subnet: 255.255.255.0
[C][wifi:429]: Gateway: 192.168.184.116
[C][wifi:430]: DNS1: 192.168.184.116
[C][wifi:431]: DNS2: 0.0.0.0
[D][wifi:606]: Disabling AP...
[W][component:237]: Component wifi took a long time for an operation (55 ms).
[W][component:238]: Components should block for at most 30 ms.
[W][component:170]: Component wifi cleared Warning flag
[D][wireguard:105]: WireGuard remote peer is offline (latest handshake 2024-05-17 01:03:07 UTC)
[D][wireguard:251]: starting WireGuard connection...
[D][wireguard:257]: WireGuard is waiting for endpoint IP address to be available
[W][component:237]: Component wireguard took a long time for an operation (207 ms).
[W][component:238]: Components should block for at most 30 ms.
[D][wireguard:105]: WireGuard remote peer is offline (latest handshake 2024-05-17 01:03:07 UTC)
[D][wireguard:251]: starting WireGuard connection...
[I][wireguard:255]: WireGuard connection started
[D][wireguard:264]: configuring WireGuard allowed IPs list...
[D][wireguard:272]: allowed IPs list configured correctly
[W][component:237]: Component wireguard took a long time for an operation (213 ms).
[W][component:238]: Components should block for at most 30 ms.
[D][api:102]: Accepted 10.13.13.1
[W][component:170]: Component api cleared Warning flag
[W][component:237]: Component api took a long time for an operation (291 ms).
[W][component:238]: Components should block for at most 30 ms.
[D][api.connection:1210]: Home Assistant 2024.5.3 (10.13.13.1): Connected successfully
[I][wireguard:095]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:17 UTC)
[D][binary_sensor:036]: 'WireGuard Status': Sending state ON
[D][wireguard:098]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:17 UTC)
[D][wireguard:098]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:43 UTC)
[D][light:036]: 'Livingroom Lights' Setting:
[D][light:047]: State: ON
[D][light:085]: Transition length: 1.0s
[D][wireguard:098]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:43 UTC)
[D][wireguard:098]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:43 UTC)
[D][light:036]: 'Livingroom Lights' Setting:
[D][light:047]: State: OFF
[D][light:085]: Transition length: 1.0s
[D][wireguard:098]: WireGuard remote peer is online (latest handshake 2024-05-17 01:11:43 UTC)

@MoraeFox MoraeFox changed the title mdns over Wireguard flushed Wireguard IP and use router given IP for cloud HA mdns over Wireguard interface flushes Wireguard IP and use IP from router May 17, 2024
@MoraeFox
Copy link
Author

Hi all. I found "use_address" part from Wifi component section and It works.
If the others provide no further issue, I'll close this after a few days.
Thanks 😄

wifi:
ssid: [Your phone]
password: [Password]

ap:
ssid: "Test Fallback Hotspot"
password: "12341234"
use_address: [Wireguard client IP]

@MoraeFox
Copy link
Author

Device auto detection still not working but I'm sure this is routing between host eth0, 0.0.0.0 interfaces and Wireguard interface so no further issue for me

@MoraeFox
Copy link
Author

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant