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/08/25 22:24] – [Get WAN IP address] vgaeteradocs:guide-developer:network-scripting [2023/07/19 09:34] (current) – [Get WAN gateway for unmanaged default route] add vgaetera
Line 208: Line 208:
 ===== Examples ===== ===== Examples =====
 [[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 required.+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 ==== 
 +<code bash> 
 +# Runtime configuration 
 +. /lib/functions/network.sh 
 +network_flush_cache 
 +network_find_wan NET_IF 
 +network_find_wan6 NET_IF6 
 +echo "${NET_IF}" 
 +echo "${NET_IF6}" 
 +</code>
  
 ==== Get WAN L2 device ==== ==== Get WAN L2 device ====
Line 224: Line 247:
  
 ==== Get WAN L3 device ==== ==== Get WAN L3 device ====
- 
-{{section>meta:infobox:howto_links#config-network-device&noheader&nofooter&noeditbutton}} 
- 
 <code bash> <code bash>
 # Runtime configuration # Runtime configuration
Line 239: Line 259:
  
 # Persistent configuration # Persistent configuration
-uci get network.wan.ifname +uci get network.wan.device 
-uci get network.wan6.ifname+uci get network.wan6.device
 </code> </code>
  
Line 288: 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/08/25 22:24
  • by vgaetera