Need to restart odhcpd after boot

After my router, a Mercusys MR90X, has booted, I can't connect to it.
In order to connect, I have to connect via ethernet and run: service odhcpd restart, and then the router immediately works.

This happened after I configured unbound and odhcpd, and disabled (if I remember correctly) dnsmasq, which was the default. I did this to use NextDNS instead of our ISP's DNS.

dhcp config:

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'server'
        option ra 'server'
        option ra_slaac '1'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '1'
        option leasefile '/var/lib/odhcpd/dhcp.leases'
        option leasetrigger '/usr/lib/unbound/odhcpd.sh'
        option loglevel '4'
        option piofolder '/tmp/odhcpd-piofolder'

unbound config:

onfig unbound 'ub_main'
        option add_extra_dns '0'
        option add_local_fqdn '3'
        option add_wan_fqdn '1'
        option dhcp_link 'odhcpd'
        option dhcp4_slaac6 '1'
        option exclude_ipv6_ga '0'
        option dns64 '0'
        option dns64_prefix '64:ff9b::/96'
        option domain 'lan'
        option domain_type 'static'
        option edns_size '1232'
        option extended_stats '0'
        option hide_binddata '1'
        option interface_auto '1'
        option listen_port '53'
        option localservice '1'
        option manual_conf '0'
        option num_threads '1'
        option protocol 'default'
        option query_minimize '0'
        option query_min_strict '0'
        option rate_limit '0'
        option rebind_localhost '0'
        option rebind_protection '1'
        option recursion 'default'
        option resource 'default'
        option root_age '9'
        option ttl_min '120'
        option ttl_neg_max '1000'
        option unbound_control '1'
        option validator '0'
        option validator_ntp '1'
        option verbosity '1'
        list iface_trig 'lan'
        list iface_trig 'wan'
        list iface_wan 'wan'
        option dhcp_4_slaac6 '1'

config zone 'auth_icann'
        option enabled '0'
        option fallback '1'
        option url_dir 'https://www.internic.net/domain/'
        option zone_type 'auth_zone'
        list server 'lax.xfr.dns.icann.org'
        list server 'iad.xfr.dns.icann.org'
        list zone_name '.'
        list zone_name 'arpa.'
        list zone_name 'in-addr.arpa.'
        list zone_name 'ip6.arpa.'

config zone 'fwd_isp'
        option enabled '0'
        option fallback '0'
        option resolv_conf '1'
        option zone_type 'forward_zone'
        list zone_name 'isp-bill.example.com.'
        list zone_name 'isp-mail.example.net.'

config zone 'fwd_google'
        option enabled '0'
        option fallback '1'
        option tls_index 'dns.google'
        option tls_upstream '1'
        option zone_type 'forward_zone'
        list server '8.8.4.4'
        list server '8.8.8.8'
        list server '2001:4860:4860::8844'
        list server '2001:4860:4860::8888'
        list zone_name '.'

config zone 'fwd_cloudflare'
        option enabled '0'
        option fallback '1'
        option tls_index 'cloudflare-dns.com'
        option tls_upstream '1'
        option zone_type 'forward_zone'
        list server '1.1.1.1'
        list server '1.0.0.1'
        list server '2606:4700:4700::1111'
        list server '2606:4700:4700::1001'
        list zone_name '.'

config zone 'fwd_next_dns'
        option enabled '1'
        option fallback '1'
        option tls_index '******.dns.nextdns.io'
        option tls_upstream '1'
        option zone_type 'forward_zone'
        list server '2a07:a8c0::#******.dns.nextdns.io'
        list server '2a07:a8c1::#******.dns.nextdns.io'
        list server '45.90.28.0#******.dns.nextdns.io'
        list server '45.90.30.0#******..dns.nextdns.io'
        list zone_name '.'

how are you trying to connect to the router ?

1 Like

Via Wifi, it's 5Ghz and sae encrypted if that is important.
Neither phones nor my PC's can connect.

1 Like

ok

see something useful here:

logread | grep odhcpd

Have you already tried something similar? Edit "/etc/rc.local"

sleep 30
/etc/init.d/odhcpd restart

It looks like my logs don't go back far enough, it's been a while since I last rebooted the router.
And I have thought of adding a restart in the init script, but it just feels wrong :sweat_smile:.

I can try and reboot it now, to see if I get any logs

1 Like

cat /etc/rc.local

sleep 30
dmesg > /tmp/dmesg.boot
logread > /tmp/logread.boot
exit 0
1 Like

Should I add that to the file?
Currently it's just the default comment and exit 0 at the bottom

1 Like

if you don't want to explicitly restart "odhcpd" it would be better to have some logs (don't you think) :grinning_face:

or you could try to see if with hotplug events you can solve via ethernet I assume so but via wifi I doubt it

cat /etc/hotplug.d/iface/99-odhcpd-fix

#!/bin/sh

[ "$ACTION" = ifup ] || exit 0
[ "$INTERFACE" = lan ] || exit 0

logger -t odhcpd-hotplug "Restarting odhcpd after LAN up"

sleep 5
/etc/init.d/odhcpd restart

cat /etc/hotplug.d/net/99-wifi-odhcpd (adapt $DEVICE to your wifi interface)

#!/bin/sh

[ "$ACTION" = add ] || exit 0

case "$DEVICE" in
wlan*)
    logger -t wifi-hotplug "WiFi up, restarting odhcpd"
    sleep 5
    /etc/init.d/odhcpd restart
    ;;
esac
1 Like

Of course now the problem has disappeared.
I just rebooted it 2 times, and unplugged it for ~20 seconds, and all 3 times I was able to connect after boot.
Edit:
No might it be the init script?

Keep this change

At least when it happens you'll be able to figure out what's wrong. :grinning_face:

1 Like

That is true.
Hopefully it just works :grinning_face_with_smiling_eyes:

1 Like

Might also be worthwhile to issue a service odhcpd enable to make sure it is set to autostart on boot. Also monitor LuCI/System/Startup or service odhcpd status.

1 Like