How to restart networking safely
Topic: Networking basics
Summary
Restart networking on Linux without losing SSH by using systemd to restart the networking service or NetworkManager, or by bringing interfaces down and up. Prefer restarting only the affected service; have console or out-of-band access in case the session drops. Use this after changing IP, DNS, or routes so the new config is applied.
Intent: How-to
Quick answer
- NetworkManager: nmcli con down ID; nmcli con up ID (or restart NetworkManager). systemd-networkd: systemctl restart systemd-networkd. Avoid restarting the whole network if you are over SSH unless you have console backup.
- If you must restart and only have SSH: schedule a job to bring the interface back up after a short delay, or change config and then restart so the new config is used when the service comes back (reducing downtime).
- Have console or serial access before restarting networking on a remote host; test with a second session or run the restart in a way that restores the interface (e.g. via cron or at).
Prerequisites
Steps
-
Prefer targeted restart
Restart only the component that changed: NetworkManager (systemctl restart NetworkManager), systemd-networkd (systemctl restart systemd-networkd), or just bring one interface down and up (ip link set eth0 down; ip link set eth0 up) if you re-applied config manually.
-
Apply config then restart
Edit netplan or NM connection; run netplan apply or nmcli con reload; then restart the service so it rereads config. That way when the service comes back it has the correct settings (same IP, so SSH may not drop if you are quick).
-
Reduce risk when remote
Use a second SSH session or console; run the restart in one session and immediately try to reconnect in the other; or use at/cron to bring the interface up after 30 seconds so a brief outage is recovered automatically.
-
Verify after restart
ip addr; ip route; getent hosts google.com; ping gateway and a public IP; confirm the interface has the expected IP and that default route and DNS work.
Summary
Restart networking only when needed and prefer restarting the specific service (NetworkManager or systemd-networkd) rather than rebooting. Have console or a second session when doing this over SSH so you can recover if the connection drops. Use this after changing IP, routes, or DNS so the new config is applied.
Prerequisites
Steps
Step 1: Prefer targeted restart
Restart the service that manages the config:
- NetworkManager:
sudo systemctl restart NetworkManager - systemd-networkd:
sudo systemctl restart systemd-networkd
Or bring a single interface down and up: sudo ip link set eth0 down; sudo ip link set eth0 up (config must already be applied).
Step 2: Apply config then restart
Edit netplan or the NM connection, run netplan apply or nmcli con reload, then restart the service. When it comes back it will use the new config; if the IP and route are unchanged, SSH may stay up.
Step 3: Reduce risk when remote
- Use a second SSH session or out-of-band console.
- In one session run the restart; in the other try to reconnect.
- Optionally use
ator cron to runnmcli con up IDor equivalent after 30 seconds so a brief outage recovers.
Step 4: Verify after restart
ip addr
ip route
getent hosts google.com
ping -c 2 GATEWAY
ping -c 2 8.8.8.8
Verification
- Interface has the expected IP; default route and DNS work; you can reach the host again if connection dropped.
Troubleshooting
Lost SSH after restart — Config may have changed the IP or removed the default route; use console to fix config and restart again, or restore the previous config.
Interface did not come up — Check logs (journalctl -u NetworkManager or systemd-networkd); config syntax error or missing device can prevent bring-up.