Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:guide-developer:network-scripting [2021/09/27 05:32] – [Examples] vgaeteradocs:guide-developer:network-scripting [2023/07/19 09:34] (current) – [Get WAN gateway for unmanaged default route] add vgaetera
Line 209: Line 209:
 [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/functions/network.sh|Network functions]] rely on runtime configuration and can return unexpected result if you are using MWAN or VPN. [[https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/functions/network.sh|Network functions]] rely on runtime configuration and can return unexpected result if you are using MWAN or VPN.
 Replace automatic WAN detection with explicit interface definition if necessary. Replace automatic WAN detection with explicit interface definition if necessary.
 +
 +==== Get LAN address ====
 +<code bash>
 +# Runtime configuration
 +NET_IF="lan"
 +. /lib/functions/network.sh
 +network_flush_cache
 +network_get_ipaddr NET_ADDR "${NET_IF}"
 +network_get_ipaddr6 NET_ADDR6 "${NET_IF}"
 +echo "${NET_ADDR}"
 +echo "${NET_ADDR6}"
 +</code>
  
 ==== Get WAN interface ==== ==== Get WAN interface ====
 <code bash> <code bash>
 +# Runtime configuration
 . /lib/functions/network.sh . /lib/functions/network.sh
 network_flush_cache network_flush_cache
Line 295: Line 308:
 # Persistent static configuration # Persistent static configuration
 uci get network.wan6.ip6prefix uci get network.wan6.ip6prefix
 +</code>
 +
 +==== Get WAN gateway for unmanaged default route ====
 +<code bash>
 +# Runtime configuration
 +ubus call network.interface dump \
 +| jsonfilter -e "$['interface'][*]['inactive']
 +['route'][*]['target'='0.0.0.0','mask'='0','nexthop']"
 </code> </code>
  
  • Last modified: 2021/09/27 05:32
  • by vgaetera