sudo lshw -class network -short
lshw -C network
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
eth0
with the interface found with sudo lshw -class network -short
.sudo ifconfig eth0 down
sudo ifconfig eth0 up
#!/bin/bash
LOGFILE=/home/pi/network-monitor.log
if ifconfig eth0 | grep -q "inet"
then
:
#echo "$(date "+%m %d %Y %T") : Ethernet OK" >> $LOGFILE
else
echo "$(date "+%m %d %Y %T") : Ethernet connection down! Attempting reconnection." >> $LOGFILE
ifconfig eth0 up
OUT=$? #save exit status of last command to decide what to do next
if [ $OUT -eq 0 ] ; then
STATE=$(ifconfig eth0 | grep "inet")
echo "$(date "+%m %d %Y %T") : Network connection reset. Current state is" $STATE >> $LOGFILE
else
echo "$(date "+%m %d %Y %T") : Failed to reset ethernet connection" >> $LOGFILE
fi
fi
sudo nano /etc/crontab
Add this line to the end
*/3 * * * * root bash /home/pi/bin/network-monitor.sh
service cron status
sudo service cron restart
sudo service cron start
at boot.sudo ifconfig eth0 down
less /home/pi/network-monitor.log