Windows Static Route Recovery
If you have messed up the routing table on a remote Windows Server, this network adapter recovery method may help you or inspire one even better. Since my particular issue happened over 5 years ago I’m honestly having a hard time remembering the exact scenario, but obviously there was a communication problem due to accidental static route deletion. The remote computer still needs to have layer 3 connectivity with your own client machine which might entail putting yourself in the same broadcast domain if that is do-able.
psexec.exe \\ServerName -s powershell Enable-PSRemoting -Force Invoke-Command -ComputerName ServerName -ScriptBlock {route add -p 0.0.0.0 mask 255.255.255.0 <Gateway here>} c:\>netsh int ipv4 show address "Ethernet" Configuration for interface "Ethernet" DHCP enabled: No IP Address: 10.0.1.90 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.92 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.91 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) Default Gateway: 10.0.1.1 Gateway Metric: 256 InterfaceMetric: 10 c:\>netsh interface ipv4 add address "Ethernet" 10.0.1.93 255.255.255.0 c:\>netsh int ipv4 show address "Ethernet" Configuration for interface "Ethernet" DHCP enabled: No IP Address: 10.0.1.90 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.92 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.93 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.91 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) Default Gateway: 10.0.1.1 Gateway Metric: 256 InterfaceMetric: 10 c:\>netsh interface ipv4 add address "Ethernet" 10.0.1.200 255.255.255.0 c:\>netsh int ipv4 show address "Ethernet" Configuration for interface "Ethernet" DHCP enabled: No IP Address: 10.0.1.90 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.92 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.93 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.200 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) IP Address: 10.0.1.91 Subnet Prefix: 10.0.1.0/24 (mask 255.255.255.0) Default Gateway: 10.0.1.1 Gateway Metric: 256 InterfaceMetric: 10 c:\>netsh interface ipv4 delete address "Ethernet" 10.0.1.93
This is what I wrote at the top of my text file, so it must have been an improvised fix that actually worked for my scenario:
when-you-fucked-your-ip.txt
# very first line of this recovery method is a last ditch effort and if it fails nothing else will work. # if this works then it was thought of by travis, if not then I found it somewhere else. psexec.exe \\SERVERNAME -s powershell Enable-PSRemoting -Force # use ps-remoting to add a static route to one of the network adapters specified as the last argument Invoke-Command -ComputerName SERVERNAME -ScriptBlock {route add -p 0.0.0.0 mask 255.255.255.0 10.0.0.1}