When working remotely on RHEL systems, administrators often face this dilemma: how to restart a network interface that's currently serving their SSH connection without losing access. The traditional approach of running separate ifdown
and ifup
commands becomes problematic because the connection drops after the first command.
RHEL provides a clean solution through the nmcli
(NetworkManager Command Line Interface) tool. This method allows you to restart an interface with a single atomic command:
nmcli connection down eth1 && nmcli connection up eth1
For systems not using NetworkManager, you can use these approaches:
# Method 1: Using ifdown/ifup with nohup
nohup sh -c "ifdown eth1 && ifup eth1" >/dev/null 2>&1 &
# Method 2: Using systemd (RHEL 7+)
systemctl restart network.service
Before restarting any interface:
- Verify you have alternative access methods (console, IPMI)
- Check interface configuration files at
/etc/sysconfig/network-scripts/ifcfg-eth1
- Consider scheduling the restart during maintenance windows
Here's how to implement this in a script that safely restarts an interface while preserving SSH:
#!/bin/bash
INTERFACE="eth1"
TIMEOUT=10
echo "Restarting $INTERFACE..."
if nmcli connection down "$INTERFACE" && nmcli connection up "$INTERFACE"; then
echo "Interface restarted successfully"
else
echo "Restart failed, attempting fallback method..."
nohup sh -c "ifdown $INTERFACE && sleep $TIMEOUT && ifup $INTERFACE" >/dev/null 2>&1 &
fi
If the interface doesn't come back up:
- Check logs:
journalctl -xe
or/var/log/messages
- Verify physical connection status
- Test with
ethtool eth1
When administering a remote RHEL server, you might encounter situations where you need to restart a specific network interface that's currently handling your SSH connection. The standard approach of running separate ifdown
and ifup
commands has an obvious flaw - your connection drops after the first command.
RHEL provides a clean solution through the nmcli
(NetworkManager command-line interface) tool. This allows you to restart an interface with a single atomic command:
nmcli connection down eth1 && nmcli connection up eth1
The key advantage here is that NetworkManager executes these operations as a single command sequence, preventing SSH session termination between the down and up states.
For Systems Using Legacy Network Scripts
If your system isn't using NetworkManager, you can use this alternative:
ifdown eth1 && ifup eth1
While this appears similar to separate commands, the &&
operator ensures both commands run in sequence during the same SSH session.
Using systemd-networkd
For systems using systemd-networkd:
networkctl reload eth1
Here's a real-world scenario where we test the interface restart while monitoring connectivity:
# First, check current interface status
ip link show eth1
# Then execute the restart (timing the operation)
time (nmcli connection down eth1 && nmcli connection up eth1)
# Verify the interface came back up
ip link show eth1
- Always have console access as backup when modifying network interfaces
- Test these commands in non-production environments first
- Consider adding a brief sleep between down/up commands for complex configurations
If the interface doesn't come back up, check:
journalctl -xe
nmcli connection show
nmcli device status