Hi. I've got a rather flaky wifi connection from one of my computers (highly modified ubuntu 12.04) to the gateway and am looking into ways of preventing the connection from going down. I decided that running a dhcp request from said machine every 4 hours or so might do the trick, so I implemented a quick and dirty solution: 0 0,4,8,12,16,20 * * * /sbin/dhclient eth0 as an entry in root's crontab file.
While that cron entry helps a great deal, I note that it has an undesirable effect: namely, when I run htop I can see many instances of dhclient running. Apparently the process needs to be killed, then restarted. So, might a more sensible way of doing this be to make a cron entry that looks like this: 0 0,4,8,12,16,20 * * * /sbin/dhclient -x && /sbin/dhclient eth0? From my reading of the dhclient man page that should kill, then restart dhclient.
Broadcasting for a new dhcp lease can also be done using ifup, as I know from experience. I tried entering 0 0,4,8,12,16,20 * * * /sbin/ifup --force eth0 into root's crontab file, but that has the same effect of causing multiple instances of dhclient to run. So, once again it seems something should be killed, then restarted.
Relevant to that, and as a final query in this thread, there are more sophisticated ways of doing what I'm after. To wit, a script could be created that established whether the network is up by doing a ping test or such, then a request for an IP can be run--or not--depending on the result. I ran across a script that someone created that seems pretty close to what I need at http://ubuntuforums.org/showthread.php?t=1101174 but I don't completely understand how that works
For my purposes, that script would actually be modified to ping the gateway at 192.168.1.1 instead of pinging some internet address, for starters. So it would need to look something like this:
Code:
#!/bin/bash
if ! `ping -c 1 -w 1 -q 192.168.1.1 </dev/null &>/dev/null` ; then
echo resetting eth0
ifdown eth0
ifup eth0
ip route add default via ath0 table WIFI
else
echo eth0 operational
fi
exit 0
Two main things I do not understand about this script. First of all, where does the result of the echo commands get recorded? In /var/log/messages? Second, and more important, why is the line "ip route add default via ath0 table WIFI" needed? When I run ifup manually on this machine, there is no need to tell it about any sort of route: the machine gets its lease renewed and I can once again browse the 'net.
Input on these issues and suggestions for accomplishing the task will be greatly appreciated.
James
Bookmarks