Users online right now: 111 - Login  » search  » forum index  

dhcpcd doesn't run indefinitely

JoeyKowala
wrote 3 years ago


reply
I'm running Slax 6.1.2 Works Great as always.

My problem seems to be with dhcpcd, it doesn't automatically reconnect if it loses the wireless signal.
I had to move my wireless router, and I'm not getting as good recpetion as before.
I'll sometimes lose my wireless connection. If I'm doing a large download, I'll come back 15 minutes later to find I lost the connection, and dhcpcd doesn't reconnect automatically.

I use this script to connect, always works ok.

#! /bin/sh
ifconfig eth0 down
sleep 1
/sbin/ifconfig wlan0 down
/sbin/ifconfig wlan0 up
/sbin/iwconfig wlan0 essid mywireless
/sbin/iwconfig wlan0 key password
/sbin/iwconfig wlan0 ap any
/sbin/dhcpcd -t 0 wlan0
echo ........... done


From what I've read in the MAN pages and lots of google-ing it seems using the parameter "-t 0"
will make dhcpcd look for a lease (ip) indefinitely if it looses the connection. (that's how I understand it).

But my system won't ever reconnect automatically, I have to type-in "dhcpcd wlan0" to re-connect.
Is there something I'm missing?

Thanks .
 
forum
wrote 3 years ago


reply
typical unix hack - write a script that will monitor whether you are connected (by say, ping-ing some host on the net), if result is negative, - it will call dhcpcd again.

similar overseers were used to reboot fawlty daemons on MIT servers in the 90-s.
 
JoeyKowala
wrote 3 years ago


reply
OK. Thank you.

I guess I misinterpreted the -t 0 feature.
I looks like that it tries indefinitely "on its first attempt", then connects, eventually, then if it should lose the connection... that's it.. done.. no more trying.

I did as suggested and got the following to work.
I can program, but Bash script is new to me, so I put this together from google-ing similar examples.
It works good enough for me...

Cheers




#! /bin/sh


foo="1"
while [ foo="1" ];do

sleep 10

# ping Google's DNS to see if network alive

ping -c1 -w5 8.8.8.8 >/dev/null

if [ $? != 0 ]; then

# no reply

killall dhcpcd
sleep 1
/sbin/ifconfig wlan0 down
/sbin/ifconfig wlan0 up
/sbin/iwconfig wlan0 essid mywireless
/sbin/iwconfig wlan0 key password
/sbin/iwconfig wlan0 ap any
/sbin/dhcpcd -n -t 0 wlan0 >/dev/null 2>&1

sleep 5

fi

done
 
jayflood
wrote 3 years ago


reply
Here is what i use for a net check. Ping can have long stalling periods on many machines. This method is MUCH faster doing the check.

Substitute "it seems you have no connection" for your reconnect code.


site=8.8.8.8
# Check for internet
check_net () {
clear
echo
echo "Checking net connectivity ..."

#if (wget --delete-after $site); then
#if (wget --spider --force-html $site); then
if (wget --spider --force-html --inet4-only $site); then
echo "Net connection: active"
else
echo "It seems you have no net connection"
echo
exit
fi
}
 
JoeyKowala
wrote 3 years ago


reply
Thanks.
I'll give it a try. I had to look up the -spider feature. Cool.
 

  » search  » forum index  

Post your reply

Your name (Login):

Message:

These HTML tags are allowed: <quote>, <b>, <u>, <i>, <pre>, <code>, <small>, <h1>, <h2>, <h3>, <li>



Slax is generously supported by: P&P Software GmbH and wisol technologie GmbH