Linux – Simulate a network cable unplugged without losing all routes

iproutelinuxnetworking

I want to simulate unplugging a cable from a Linux instance. My initial response was ip link set eth0 down. However, this command has impact on higher-level networking functions, e.g. routes (including default route) are removed, etc. When I "plug it back in" with ip link set eth0 up, the routes now are missing.

How can I simulate unplugged network without using down, or conversely tell iproute2 to just cause the network cable to be disconnected?

Best Answer

Try this command:

nmcli device disconnect eth0

To turn interface on, use this command.

nmcli device connect eth0

Note: Please change eth0 to your interface device.

Related Question