Bind service to local IP

Hi. I need a tutorial. Please help.

Tvheadend package seems to send multicast message to the wrong interface. See: OpenWrt issue and tvheadend discussion. There is a command line switch available that binds tvheadend's satip client to a specific IP (--satip_bindaddr).

  1. How do I write a service startup script that binds the service to router's LAN IP address? How do I get that address?

  2. If your proposed solution to obtain the IP is based on interface name (br-lan), what happens if the user changed the interface name to something else?

  3. What happens if the router is connected to multiple LANs? Will the suggested solution work?

  4. How to auto-restart the service if the local LAN address changes (manually by the user? DHCP offers another?)

  5. Instead of a fixed setting, should I add this binding as a config option in /etc/config/tvheadend? Should this option accept an IP address or interface name? Or both / any? Is there any wiki / tutorial for creating configuration files?

Thank you for your answers.

1 Like

You don't, as it would be inherently racy. You'll need to do this from within hotplug handlers (/etc/hotplug.d/iface/)

Then the user needs to adjust the tvheadend configuration as well.

The user will need to decide which interface to bind to or, in case tvheadend supports multiple, enter all local interfaces in the configuration

Hotplug should work for that.

Yes, it should be configurable. Ideally it should be able to resolve both logical network names ("lan") and accept IPs directly.

For parsing uci in init scripts, see

For querying network state, have a look at


Maybe another quick and dirty workaround but what about (ab)using /etc/init.d/tvheadend (re)start:

uci set tvheadend.server.bindaddr=$(uci get network.lan.ipaddr)
uci commit

Or better without making it permanent and skipping /etc/config/tvheadend by just altering the startup variable of tvheadend from /etc/init.d/tvheadend:

procd_set_param command "$PROG" -B -u $TVH_USER -g $TVH_GROUP
LANIP=$(uci get network.lan.ipaddr)
procd_set_param command "$PROG" -B --bindaddr $LANIP -u $TVH_USER -g $TVH_GROUP

EDIT just tested this init.d only solution and works on current OpenWrt Snapshot :wink:

Hotplug solution isn't OK for tvheadend because it can't be stopped at some random time if IP address changes. It may be in the middle of recording some TV show. Restarting it will interrupt the recording.

I'm working on a simple, but better solution:
If bindaddr is not set in /etc/config/tvheadend, it defaults to router's LAN IP when tvheadend starts. Users can still set it to if they want all interfaces.