Restart HA when WAN IP changes, why is it needed?! Any workaround?

Hello!

I have HA running on Oracle VM, on a windows 10 PC with NGINX Home Assistant SSL proxy.
(which I suspect could be the culprit.)

To have redundancy on my connection I’m using a 4g USB modem into my ASUS RT-AC86U
in Dual-WAN config with failover after x amount of failed pings.
Now I’ve noticed this odd thing, when the failover happens I of course get a new WAN IP because I’m connected through 4g and not through the wired connection. This in turn for some reason blocks my WAN access to Home Assistant, while the LAN access still works.

I’ve made this Automation below that triggers on Public IP Adress change but it feels like a
dirty quickfix. I tried substituting the restart service with an addon restart of the NGINX addon but that did not restore my WAN connection on the “new IP”.

What can be done in order to avoid a full HA Restart just to restore WAN connection?

### Automation to reboot HA on Publ. IP Change
sensor:
    # Own public IPv4 address
    - platform: dnsip
      name: ct_public_ip            # default: myip
      hostname: myip.opendns.com    # default: myip.opendns.com (special hostname that resolves to your public IP)
      scan_interval: 60             # default: 120s
      resolver: 208.67.222.222      # default: 208.67.222.222 (OpenDNS)

automation:
  - alias: "CT|IpChange|HassRestart"
    id: "CT|RebootAddon"
    trigger:
      - platform: state
        entity_id: sensor.ct_public_ip
    action:
      - variables:
          delay_min: 1
          msg_title: 'Public IP Changed'
          msg_info: >
            '{{ trigger.from_state.state + " -> " + trigger.to_state.state }}'
            <br>Restart in {{ delay_min }} minute{{ "s" if delay_min > 1 else "" }}      
      #- service: notify.all_devices
      #  data_template:
      #    title: '{{ msg_title }}'
      #    message: '{{ msg_info  }}'
      - service: persistent_notification.create
        data:
          title: '{{ msg_title }}'
          message: '{{ msg_info | replace("<br>", "\n") }}'
      - delay:
          minutes: '{{ delay_min }}'
      - service: homeassistant.restart
        data: {}

Normally HA would really have anything to do with how the network is routing packets.

How do you connect to HA from WAN?
IP or URL?

Does the IP work, but not the URL?
If that is the case, then its because you are using a dynamic DNS and that needs to be updated to reflect the change.

1 Like

It’s url, using noip as ddns provider.
No sadly IP does not work either, until rebooted and I’ve also confirmed that my new ip is updated at noip before trying the connection and before rebooting HA.

I’ve tracked my routers syslog and at every failover it updates my ddns with the new IP

It does not make sense that it should be HA you should restart, unless your router does not just make a failover, but actually create a whole new host on the LAN.

Are you using DHCP or static IP on the HA installation?
With static IP, I mean an IP actually entered on the HA host and not just a permanent lease set in the router, which is in fact still DHCP.

If it is DHCP does the default gateway then change with a restart of HA?

I feel like this is more an issue with your router/firewall than HA. Is your DDNS being updating properly? Are you running the DDNS updates at the router level or HA? Rebooting the VM probably refreshes something that is not getting refreshed either externally (DDNS) or your router is not port forwarding correctly.

Well there are two approaches I’ve found that resolve my WAN Connection issues.

  1. Restart HA
  2. Restart network adapter of oracle VM, but this is manually and tedious, and beyond me to automate

My HA instance uses DHCP but my router has it bound to 192.168.1.100 by its MAC address

Hard to tell if its router based as I can solve the issues without doing anything in my router.
See previous post.

DDNS is properly updated according to Syslog in router and according to my login page on no-ip.
DDNS is ran on the router.

Rebooting VM? Isn’t it just a reboot of HA inside the VM?

There is no technical reason that Home Assistant would care what the WAN IP address is. However I guess Home Assistant could cache your external IP, if you are using your DDNS in the external URL configuration.

What is much more confusing to me, is that you have any external access to Home Assistant at all when you failover to 4G, because that would surely be CGNAT and thus port forwarding is impossible, without the aid of some external reverse tunnelling server.

(To test if it is a DNS cache problem, next time instead of restarting all of Home Assistant, try instead to use the Web and SSH addon, and type

ha dns restart

and see if it becomes reachable again.

1 Like

Depends on the contract you have with the cell service provider. There’s nothing stopping them from providing you a standard dynamic IP without private pool or even a static IP. It just (usually) costs more. At home, my 4G uses CGNAT and I need to reverse tunnel to access my HA. At work we have a 4G failover with a static IP where we have full control over the NAT. The service plan is more expensive though.

1 Like

If you can restart the Oracle VM adapter and things start to work, then that is what you have to look at.

How is the Oracle VM adapter configured?
Is the mode in bridge, routing or routing with NAT?

If it is routed, then can you extract the external default gateway and see if that changes when you restart the network adapter?
And does the default gateway change on the HA with a restart of the Oracle VM network adapter?

I do not know if your setup allow you to cycle just the network on the HA installation, but if you can, then test that too.

Similar to this borrowed image, bridged in promiscious mode = allow all

What I do from oracle to fix it is change Bridged → NAT → Bridged then
WAN access is restored.

I do not know if your setup allow you to cycle just the network on the HA installation, but if you can, then test that too.

I would not know how to do that other than my previous post

Here I had some luck my 4G Carrier does not use CGNAT :slight_smile:

1 Like

Ok, this seems to be a Oracle VM issue.
I did a little google search and quickly stumbled upon these two results.

I suggest you try to get this solved through Oracle VM support sites instead, since they are more knowledgable about such issues.

I’ve seen those and similar threads. I know of it’s limitations, hence why I stated that there is a dirty and tedious fix of changing the VM Network type from bridged to anything and then back to bridged. This solves my issue but I can’t automate it, as far as I know.

Now since I can resolve my issue with rebooting Home Assistant through an automation that works better for me.

This though indicates to me that there is something amiss in home assistant since a simple reboot solves it. Without changing the network adapter in oracle VM.

I’ll try resetting the dns manually in a moment. From HA terminal and see what it does.
If that does not help I’ll just be satisfied with a full reboot of HA

What I meant with turning to the Orcale forums was that this should not be happening, so they might have a solution to avoid it completly.

Was this ever resolved with HA and No-IP?

It can’t be solved with HA.
The bug is in the Oracle VM hypervisor’s network bridge emulation.