Proper Network Service Restart in Ubuntu/Debian: Best Practices to Avoid Deprecated Methods


1 views

When you run the traditional /etc/init.d/networking restart command on modern Ubuntu/Debian systems, you'll see this warning:

Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces

This occurs because the old SysV init system is being phased out in favor of systemd. The warning indicates potential issues where some network interfaces might not properly reinitialize after the restart.

Method 1: Using systemd (Recommended)

The preferred approach is to use systemd's systemctl command:

sudo systemctl restart networking.service

For more granular control over specific interfaces:

sudo systemctl restart networking.service
sudo ifdown eth0 && sudo ifup eth0

Method 2: Network Manager (For Desktop Environments)

If you're using NetworkManager:

sudo systemctl restart NetworkManager

Or to reload specific connections:

nmcli connection reload
nmcli connection down "My Connection" && nmcli connection up "My Connection"

When modifying network configurations in /etc/network/interfaces, follow this workflow:

# Edit your configuration
sudo nano /etc/network/interfaces

# Apply changes without full restart (for new configurations)
sudo ifdown eth0 && sudo ifup eth0

# For major changes, use:
sudo systemctl restart networking.service

If interfaces fail to come back up:

# Check interface status
ip a

# Check journal logs
journalctl -u networking.service -b

# Manually bring interface up
sudo ip link set eth0 up
sudo dhclient eth0

On server or minimal installations using systemd-networkd:

sudo systemctl restart systemd-networkd

To check status:

networkctl list

Remember that the exact method depends on your specific network configuration and Ubuntu/Debian version. Always test in a non-production environment first.


<h2>Why the Traditional Method is Deprecated</h2>
<p>In modern Ubuntu/Debian systems (particularly since systemd adoption), the classic network restart command:</p>

<pre><code>sudo /etc/init.d/networking restart
</code></pre>

<p>Triggers this explicit warning:</p>

<pre><code>Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
</code></pre>

<h2>Modern Network Management Approaches</h2>
<p>Choose the appropriate method based on your network configuration:</p>

<h3>For systems using NetworkManager</h3>
<pre><code># Full service restart (not recommended for active connections)
sudo systemctl restart NetworkManager

# Graceful connection reload (preferred)
nmcli connection reload
nmcli networking off && nmcli networking on
</code></pre>

<h3>For systems using systemd-networkd</h3>
<pre><code>sudo systemctl restart systemd-networkd
</code></pre>

<h3>For legacy ifupdown configurations</h3>
<pre><code># The new recommended approach
sudo ifdown --exclude=lo -a && sudo ifup --exclude=lo -a

# Alternative for specific interface
sudo ifdown eth0 && sudo ifup eth0
</code></pre>

<h2>Configuration Reload vs Full Restart</h2>
<p>Often you only need to reload configs without interrupting connections:</p>
<pre><code># NetworkManager config reload
nmcli general reload

# systemd-networkd config reload
sudo networkctl reload
</code></pre>

<h2>Troubleshooting Common Scenarios</h2>
<p><strong>After editing /etc/network/interfaces:</strong></p>
<pre><code>sudo systemctl restart networking
</code></pre>

<p><strong>When DHCP changes aren't applying:</strong></p>
<pre><code>sudo dhclient -r eth0 # Release
sudo dhclient eth0 # Renew
</code></pre>

<p><strong>For NetworkManager-managed interfaces:</strong></p>
<pre><code>nmcli dev disconnect eth0
nmcli dev connect eth0
</code></pre>