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
  • Try using allow-hotplug instead of auto for the Ethernet interface. It should then automatically recover when reconnected and attempt to renegotiate for the IP. (This is what I do on several systems with non-Network-Manager-managed Ethernet interfaces). I'll bet its losing the IP because of some other reason, such as the wire temporarily losing connectivity or such, and as such allowing as hotplug will help a little. – Thomas Ward Sep 23 '17 at 13:20
  • You could adapt my answer askubuntu.com/questions/665721/how-to-rotate-wifi-connections/… - it's a script that monitors for network going down, then executes a command from a config file. – waltinator Sep 23 '17 at 13:27
  • sporadic loss of connectivity on a wired connection has been in my experience most often an issue with either a bad lan cable or bad port on the switch. Can you confirm that you get the same result on a different port/with a known good cable? – Elder Geek Sep 23 '17 at 18:44
  • I will do some cable/port testing tonight. Where might I find indicators in the logs of what's going on? I tried trolling through syslog and a few other places, but I'm afraid I'm not savvy enough to distill any answers or even know if they're in there... – scottwmcgregor Sep 25 '17 at 12:42
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.