LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Cron job to check/restart network connection? (https://www.linuxquestions.org/questions/linux-networking-3/cron-job-to-check-restart-network-connection-196116/)

mac_phil 06-21-2004 04:20 PM

Cron job to check/restart network connection?
 
I leave my computer running nonstop. Every few months it loses its connection. I get my IP through DHCP and have no control over the DHCP server. My IP never changes even though it is dynamic.

I would like to do something to ensure that the computer puts itself back online.

Would a cron job be a good idea? I could have it check the network status every hour, and do a 'service network restart' (or equivalent) if it is offline.

Could you tell me if this is the correct solution, and if so, exactly what commands would I put in the cron job?

When the machine is offline doing 'service network status' returns: configured currently active lo eth0.

Thanks.

david_ross 06-22-2004 12:36 PM

I'm sure that you could create a script to check the output from somthign like:
ping -c 3 ip.of.your.gateway | grep -c "bytes from"

If the outut is 3 then the connection is OK - 0 then the system cannot reach your gateway and in the middle if there are intermittent network problems.

Although your IP is assigned by DHCP - have you tried configuring for a static IP (using the same details that DHCP gives)?

mac_phil 07-07-2004 07:24 PM

Quote:

Originally posted by david_ross
I'm sure that you could create a script to check the output from somthign like:
ping -c 3 ip.of.your.gateway | grep -c "bytes from"

If the outut is 3 then the connection is OK - 0 then the system cannot reach your gateway and in the middle if there are intermittent network problems.

Although your IP is assigned by DHCP - have you tried configuring for a static IP (using the same details that DHCP gives)?

Interesting, thanks. Is "service network restart" the right command for getting the connection back? I'll start writing a script.

I'm not quite sure what you mean configuring for a static IP. What benefits would that offer?

PS - Sorry for the late reply, I was gone fishin' as they say.

david_ross 07-08-2004 12:47 PM

"service network restart" should reset the connection for you.

If your IP never changes then you may be able to just specify the IP, netmask and gateway - this should solve the problem if it is a dhcp issue.

perry 07-21-2004 09:32 AM

Quote:

Originally posted by david_ross
"service network restart" should reset the connection for you.

If your IP never changes then you may be able to just specify the IP, netmask and gateway - this should solve the problem if it is a dhcp issue.

thats funny.... i just installed slackware 10 and i'm using the 2.4.26 kernal and under mandrake i could always go "service network restart" if i needed to, however i just tried to use it here and it didn't know what i was talking about.

is "service network restart" a linux thing or a mandrake thing? having to reboot my linux system to get on the internet is NOT cool....

- perry

comprookie2000 07-21-2004 10:41 AM

With Slackware I use dhcpcd eth0 because I lose mine also.

mcostello1 09-01-2004 01:51 PM

Hey I'm running into the same problem but we have a unique instance where as the linux server (RedHat) is running as a Microsoft Virtual Server. Is there anyway you can post the shell script.
I am unable to ping the box yet doing "service network restart" successfully shuts down the network interface and brings them back up and everything seems towork fine again for awhile. (Any Suggestions? )


All times are GMT -5. The time now is 08:16 PM.