How to configure `eth0` to retry `dhclient` when unplugged and replugged?

AJ ONeal coolaj86 at gmail.com
Wed Sep 7 11:20:05 MDT 2011


I'm working on a linux gadget.

I want it to get DHCP if I plug in the network cable after it has booted up
already or if the network cable unplugged and replugged.

One solution is to run a script such as this (which works, btw):

    #!/bin/bash

    NET_STATUS='different'

    while true
    do
      NEW_NET_STATUS=`ifconfig | grep RUNNING | grep -v LOOPBACK`
      if [ "${NEW_NET_STATUS}" = "${NET_STATUS}" ]
      then
        echo "no change"
        sleep 1
        continue
      fi
      NET_STATUS=${NEW_NET_STATUS}
      if [ "${NET_STATUS}" ]
      then
        echo "cable plugged in"
      else
        echo "cable unplugged"
      fi
      sleep 1
    done

However, I've got a feeling deep down in my little toe that tells me that
there's a better way to deal with hotplug events for the ethernet cable.

Do any of you know what way that is?


Question also on SuperUser:
http://superuser.com/questions/332968/how-to-configure-eth0-to-retry-dhclient-when-unplugged-and-replugged

AJ ONeal


More information about the PLUG mailing list