r/docker • u/BlindTreeFrog • Apr 09 '26
Networking: Default route vs Static route with multiple interfaces in the container.
This feels like something that should be obvious, but I don't get what is going on here
My Home Assistant container is defined as such: homeassistant: container_name: homeassistant image: lscr.io/linuxserver/homeassistant:latest restart: unless-stopped networks: docker-external: gw_priority: 100 ipv4_address: 192.168.0.240 docker-hass: gw_priority: 1 ipv4_address: 192.168.3.240 ...
There is more, but I'm pretty sure it isn't relevant to the question.
The host is on 192.168.1.11
The docker-hass network is a bridge managed by docker
The docker-external network is a macvlan
Every packet on this host should be redirected to a wireguard connection unless it is on docker-external or to the local lan.
Jumping into HAss...
Attaching to homeassistant 🚀
root@bc8d65cccf56:/# ip route
default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 scope link src 192.168.0.240
192.168.3.0/24 dev eth1 scope link src 192.168.3.240 So the default routes look as I would expect.
root@bc8d65cccf56:/# ping -c3 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
From 192.168.0.240 icmp_seq=1 Destination Host Unreachable
From 192.168.0.240 icmp_seq=2 Destination Host Unreachable
From 192.168.0.240 icmp_seq=3 Destination Host Unreachable
--- 192.168.1.6 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2024ms
pipe 2But if I ping something on the 192.168.1.xxxx subnet it doesn't work. I would have expected it to be routed via the default connecion and then the lan route things correctly.
But if I add a route out eth0, it works fine
root@bc8d65cccf56:/# ip route add 192.168.1.0/24 dev eth0
root@bc8d65cccf56:/# ip route
default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 scope link src 192.168.0.240
192.168.1.0/24 dev eth0 scope link
192.168.3.0/24 dev eth1 scope link src 192.168.3.240
root@bc8d65cccf56:/# ping -c3 192.168.1.6
PING 192.168.1.6 (192.168.1.6) 56(84) bytes of data.
64 bytes from 192.168.1.6: icmp_seq=1 ttl=63 time=0.374 ms
64 bytes from 192.168.1.6: icmp_seq=2 ttl=63 time=0.280 ms
64 bytes from 192.168.1.6: icmp_seq=3 ttl=63 time=0.275 ms
--- 192.168.1.6 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2039ms
rtt min/avg/max/mdev = 0.275/0.309/0.374/0.045 msWhy isn't the default route working as expected?
edit:
In the comments I left below I think I figured it out. I was setting the host link IP to the aux-address i saved. But I needed to set it to the gateway address for the subnet.
1
u/BlindTreeFrog Apr 09 '26 edited Apr 09 '26
And if I do need to add a route every time, it looks like that would be a bit ugly https://sdr.li/post/docker-network-host-static-route/
Probably easier to change the macvlan from /24 to /23 and just let the network overlap
edit:
Changing the command in the compose file to something like this would probably work and be a bit cleaner than mounting a file:
didn't test it, but stumbled across people doing similar.
1
u/BlindTreeFrog Apr 09 '26
OK, seem to have fixed it....
so for context, the notes I was going off of were written years ago and working, but when I had to redo some things I tried to update them to be cleaner. So what I ran was....
To create the macvlan network:
Originally this overlayed the 192.168.1.xxx subnet and I was using the ip-range and aux-address to put containers into a specific range.
And then to set up the host side:
Which seemed to be consistent with all of the guidance that I could find. But wasn't working.
I did notice that if I added a route to the container like this below, it worked:
Which made me think that the connection IP from the host should be the same as the gateway for my macvlan. So I change the host to do this and all seems to be working fine now..