LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2003, 03:05 PM   #1
Gramphos
LQ Newbie
 
Registered: Sep 2003
Posts: 17

Rep: Reputation: 0
Question How to make linux retry to bring up eth0 if failiure


I have a computer that I sometimes wants to be able to access via network, especially on times when I'm on another location than the computer.

The problem is that the computerlocation sometimes gets powercuts and when the power is restored my system boots faster than the DHCP server and router and the eth0 bring up will fail.

Is there any way to make the computer retyr every 5 minutes if the network is down?
 
Old 11-18-2003, 04:16 PM   #2
mi6alec
Member
 
Registered: Sep 2003
Distribution: Mandrake 9.2
Posts: 41

Rep: Reputation: 15
i don't know about every five minutes, but typing at a command line
ifup eth0 or ifconfig eth0 up

will bring it back up. this may need to be root?
 
Old 11-19-2003, 02:54 AM   #3
Gramphos
LQ Newbie
 
Registered: Sep 2003
Posts: 17

Original Poster
Rep: Reputation: 0
Well ther problem is that I won't be able to do commands unless the net is up and I can log in with SSH, so I need a way to ensure that it is up.
 
Old 11-19-2003, 07:33 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,692

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
Do you have to use DHCP? Just configure your eth0 for a static IP address.
Stick an UPS on the DCHP server and router.

Yes, you could write a script to try configuring eth0 with a fixed interval.
 
Old 11-19-2003, 09:14 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
In Mandrake I would restart my network by doing this:
service network restart
So I could write a script and run it from /etc/rc.d/rc.local that would try to ping my GATEWAY and until it got a good ping it would sleep then restart then ping then try again.

That script would look something like this:
Code:
#!/bin/bash
GATEWAY=192.168.0.1
PING="100%"
until [ "$PING" = "0%" ]
    do
    sleep 30
    echo "Trying to start network..."
    service network restart
    PING=`ping -c1 -w2 $GATEWAY 2>/dev/null|grep pack|awk '{print $6}'`
done
The output of the script looks like this.
Code:
./startnet
Trying to start network...
Shutting down interface eth0:                                   [ COOL ]
Shutting down loopback interface:                               [ COOL ]
Setting network parameters:                                     [ COOL ]
Bringing up loopback interface:                                 [ COOL ]
Bringing up interface eth0:  Can't find a dhcp client
                                                                [BUMMER]
Trying to start network...
Shutting down loopback interface:                               [ COOL ]
Setting network parameters:                                     [ COOL ]
Bringing up loopback interface:                                 [ COOL ]
Bringing up interface eth0:  Can't find a dhcp client
                                                                [BUMMER]
Trying to start network...
Shutting down loopback interface:                               [ COOL ]
Setting network parameters:                                     [ COOL ]
Bringing up loopback interface:                                 [ COOL ]
Bringing up interface eth0:                                     [ COOL ]
<edit> Of course you may need to change GATEWAY and the sleep value.
Another thing is you would want to ping the GATEWAY first and only run the script if the network is down, otherwise you have a big long delay in your bootup. I guess that could be done in the script too. Let me see.

Code:
#!/bin/bash
GATEWAY=192.168.0.1
PING=`ping -c1 -w2 $GATEWAY 2>/dev/null|grep pack|awk '{print $6}'`
until [ "$PING" = "0%" ]
    do
    sleep 30
    echo "Trying to start network..."
    service network restart
    PING=`ping -c1 -w2 $GATEWAY 2>/dev/null|grep pack|awk '{print $6}'`
done
Yes the above works better than the really far above.

Last edited by /bin/bash; 11-19-2003 at 09:25 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot bring up eth0 zhex900 Linux - Distributions 5 04-24-2005 03:33 PM
Cannot bring up Eth0 jamespetts Linux - Networking 7 08-03-2004 05:42 AM
can not bring up eth0 summerfish Linux - Networking 2 07-19-2004 10:09 PM
couldn't bring up interface eth0 mikez Linux - Networking 9 02-28-2002 12:02 PM
Can't bring up eth0 cyrano Linux - Networking 4 08-21-2001 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration