How to restart dnsmasq automatically after restarting network

Sometimes you need to restart the network (/etc/init.d/network restart) during use, but after restarting the network, you must manually restart dnsmasq (/etc/init.d/dnsmasq restart) in order to use the network normally. I found that dnsmasq will automatically restart after redialing with ifup wan. How does this work? Is there any way to restart dnsmasq automatically after restarting the network?

Can you reproduce the issue using the factory default network and DHCP/DNS configs?

The default factory setting is to restart dnsmasq automatically after restarting the network? That is, I can’t restart now. Maybe it’s due to a setting problem?

By default, Dnsmasq doesn't even need to restart as it dynamically binds interfaces.
Thus, normally it can survive the restart of the network service safely.
It sounds like you have some sort of race condition due to misconfiguration.

There are no special changes on my side, even if there are changes, they are changed through the Luci interface. This way should avoid errors. After ifup wan redials, how does it make dnsmasq restart? I haven't found the implementation code or related instructions for this function, do you know it?

Yes I have experienced this as well. After editing config files to build out a guest network-- the network itself, firewall zone and rules, a wifi AP, and a DHCP server, service network restart only starts the first three. The guest network is not usable since dnsmasq was not restarted to listen on the new interface.

In many cases, I do not need to restart the network because of changes to the configuration. It is just a restart of the network, not to mention that you have made so many changes. Some modifications are modified through the LUCI interface, there will be so many problems, and the official support is also poorly done. It is only suitable for regular applications or users with development capabilities.