I have one more issue in openwrt GUI. By default, openwrt opens in static IP i.e., eg: 192.168.1.1.
Suppose we have changed this static IP to DHCP IP and forgot to put the LAN then the board will not get IP from DHCP then it should get the default static IP.
I am using udhcp for DHCP IP. So it should support fallback.
Can anyone help me how can I set static IP after fail to get DHCP IP in 15 sec using UDHCP.
Thanks for your reply.
I want to know that how we will run this hotplug.d when not able to get DHCP IP.
Is there any file in which I have to call this hotplug.d file.
I have read somewhere on google about dhclient.conf which is used when we are using dhcpc but in my case, I am using udhcp for DHCP IP.
I am having this problem as i have DHCP IP using "udhcp" command.
I have googled this thing and getting some answer that i have to add some line in dhclient.conf.
But i am not having dhclient.conf file in my board.
So anyone can help me in this as i dont know anything about this.
cat << "EOF" > /etc/hotplug.d/iface/95-dhcp-fallback
NET_ACTION="ifup"
NET_IFLO="lo"
NET_IF="lan"
NET_DELAY="15"
UCI_IP="192.168.1.123"
UCI_MASK="255.255.255.0"
UCI_GW="192.168.1.1"
UCI_DNS="192.168.1.1"
. /lib/functions/network.sh
network_flush_cache
if [ "${ACTION}" = "${NET_ACTION}" -a "${INTERFACE}" = "${NET_IFLO}" ]
then
sleep "${NET_DELAY}"
network_get_ipaddr NET_IP "${NET_IF}"
if [ -z "${NET_IP}" ]
then
uci set network.${NET_IF}.ipaddr="${UCI_IP}"
uci set network.${NET_IF}.netmask="${UCI_MASK}"
uci set network.${NET_IF}.gateway="${UCI_GW}"
uci set network.${NET_IF}.dns="${UCI_DNS}"
/etc/init.d/network reload
fi
fi
EOF
No, command cat writes the code until EOF inside /etc/hotplug.d/iface/95-dhcp-fallback.
You just need to copy-paste the whole code-block inside the terminal via SSH.
The script runs automatically when network-service brings up lo-interface.
It waits 15 seconds and checks lan-interface IPv4-address.
If there's no IPv4-address, it configures static address.
I have tried your solution by running the above command.
When I change my board from static to DHCP and I didn't put the LAN wire in the board, so the board will not get the DHCP IP. After that, I have waited for more than 20 sec and my board didn't get the static IP define in the 95-dhcp-fallback file.
So i really didn't know how this will work.
Please confirm this how it will work.
I have rebooted my board to get that script trigger but didn't work for me.
I have changed my GUI from static to DHCP and wait for 15 sec and more but didn't get the fallback IP i.e., static IP which is written in 95-dhcp-fallback. PFA file.
source /lib/functions/network.sh
INTERFACE="br-lan"
NET_ACTION="ifup"
NET_IFLO="lo"
NET_IF="lan"
NET_DELAY="15"
UCI_IP="192.168.1.1"
UCI_MASK="255.255.255.0"
UCI_PROTO="static"
if [ "$ACTION" = "$NET_ACTION" -a "$INTERFACE" = "$NET_IFLO" ]
then
sleep "$NET_DELAY"
network_get_ipaddr NET_IP "$NET_IF"
if [ -z "$NET_IP" ]
then
uci set "network.$NET_IF.ipaddr=$UCI_PROTO"
uci set "network.$NET_IF.ipaddr=$UCI_IP"
uci set "network.$NET_IF.netmask=$UCI_MASK"
/etc/init.d/network restart
fi
fi
I don't know from where it will get the INTERFACE so i have INTERFACE in this file and changed according to my requirements.
source /lib/functions/network.sh
INTERFACE="br-lan"
NET_ACTION="ifup"
NET_IFLO="lo"
NET_IF="lan"
NET_DELAY="15"
UCI_IP="192.168.1.1"
UCI_MASK="255.255.255.0"
UCI_PROTO="static"
set -x -v
exec &>>/tmp/dhcp-fallback.log
date
if [ "$ACTION" = "$NET_ACTION" -a "$INTERFACE" = "$NET_IFLO" ]
then
sleep "$NET_DELAY"
network_get_ipaddr NET_IP "$NET_IF"
if [ -z "$NET_IP" ]
then
uci set "network.$NET_IF.ipaddr=$UCI_PROTO"
uci set "network.$NET_IF.ipaddr=$UCI_IP"
uci set "network.$NET_IF.netmask=$UCI_MASK"
/etc/init.d/network restart
fi
fi
and reboot the board.
After that, I have changed my router from static to DHCP and again wait for more than 15 sec.
Also, I didn't get any logs on /tmp path.
I think this file is not running in the backend.
Thanks in advance