1

I have a media and PVR server running ubuntu 16.04 that sporadically loses its wired connectivity (the IP drops off the ifconfig output; the icon on the desktop indicates that it's connected but it's not). The interface is dhcp, but is statically assigned from the router. If I don't catch that it's down for hours or days, I miss recording shows onto it (which saddens the wife).

After reading numerous approaches across askubuntu and elsewhere, my solution was going to be simply to add "ifup -a" to cron.hourly. Is there a performance hit or any other impacts of doing this? Is there a better or "approved" way of checking and restarting network interfaces automatically? I don't know why it drops in the first place-- the wire stays connected and the machine is directly connected to my main (unmanaged) switch.

/etc/network/interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
auto enp0s10
iface lo inet loopback
iface enp0s10 inet dhcp

1 Answers1

0

One solution would be to actually check to see if the interface is up first and then restart the network-manager service if it's not with a script like the following. This checks to see if a single ping

if ! ping -Q 1 -c 1 -t 60 google.com; then
echo warning: lost network connection >>/var/log/syslog
    service network-manager restart
fi

and launch that with cron at whatever period of time you think is sufficient.

You may want to boost the -Q parameter as discussed here if you don't get the desired results but it worked fine at 1 in my tests. you might also have to tweak the -t parameter to suit your environment.

Of course you'll have to setup the cron job properly for this to work.

Sources:

https://unix.stackexchange.com/questions/133931/automatically-restarting-network-connection

man ping

How to set up a root cron job properly

Testing.

Elder Geek
  • 36,752