Simulate network reset or failure in Windows

I have to check if my server application can recover from transient network failures. The application listens on some ports and is a client to backend services. I would like to run some command or script that would drop and restore all connections.

Is there some tool included in Windows that would allow that? For instance, is there a sequence of route, ipconfig or netsh commands that would drop all connections and allow the machine to resume operation normally?

Maybe disabling the network card device and enabling it back?


You could accomplish in multiple ways.

Netsh Command - Dropping the Interface

Use the "netsh interface show interface" command to get the name of the interface you wish to control.

Run the command below replacing Interface Name from the output of the first command. This will disable the interface. netsh interface set interface "{Interface Name}" disable

Run the command below replacing the Interface Name from the output of the first command. This will enable the interface. netsh interface set interface "{Interface Name}" enable

Firewall Rules

You could block traffic by creating a Windows Firewall rule for inbound/outbound connections that matches your application connections.

Documentation for PowerShell on Creating Firewall Rules

https://docs.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=windowsserver2019-ps

Route Command

You could in fact create a bad route to simulate a failure as well however if you are only serving your local subnet with these services this will not work.

Powershell Command to Add Route

New-NetRoute -DestinationPrefix '{Destination Network}' -NextHop {Some Bad Gateway}

Route Command

route add {Network} MASK {Subnet Mask} {Some Bad Gateway}

Of course too you could do this by simply unplugging the network cable, no keyboard required.