OpenWrt Forum Archive

Topic: Static route & default gateway

The content of this topic has been archived on 26 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

What is wrong with the folowing script ("S30mymetwork" in init.d)?
When I run the script, the route is not added (last line), when I type it manually on the console the route well is added (visible via route -n)

The script is:
#!/bin/sh
set -x
. /etc/config/network
WAN_IP="$wifi_ipaddr"

wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode sta
echo WAN_IP $WAN_IP
ifconfig ath0 $WAN_IP
iwconfig ath0 essid "test"
ifconfig ath0 up
route add default gw 192.168.1.1

The command I type on the console:
>route add default gw 192.168.1.1

Any idea, can the default route be deleted by dnsmasq, udhcpc.... ?

Your PATH environment may differ so try to run "route" with full path (/sbin/route).

seagull wrote:

. /etc/config/network
WAN_IP="$wifi_ipaddr"

You couldn't possibly write $wifi_ipaddr in the rest of the script, you had to create a variable to reference another variable? Anyways .. If you set the following in your /etc/config/network:

wan_ifname=ath0
wan_proto=static
wan_ipaddr=192.168.1.x
wan_gateway=192.168.1.1

You can then change your S30mynetwork script to a much simpler:

#!/bin/sh
wlanconfig ath0 destroy
wlanconfig ath0 create wlandev wifi0 wlanmode sta
iwconfig ath0 essid "test"
ifup wan

The discussion might have continued from here.