How come restarting networking does not work on Debian?

Solution 1:

root@machine:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
 address 192.168.1.110
 gateway 192.168.1.1
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255

The solution was replacing allow-hotplug by auto. Thanks! :)

Solution 2:

I suspect your problem is that when networking is shut down (to restart), sshd is noticing and closing the connection. When sshd closes the connection, the pseudo-tty SIGHUPs the shell, along with the programs that were running in it. This includes init.d/networking which is dying before it can start the connection back up again.

Try running screen first (so that the shell is not interrupted) or at least nohup service networking restart so that the script won't receive SIGHUP and terminate.