TLDRBins TLDRBins / IP Routing


Usage Tips:

  • Click on a keyword to enable inline editing.
  • Click inside a code block to copy (excludes comments).
  • Use the button to view examples.
  • Click outside to collapse all examples.

Check Routes

ip route show
Sample Output: TO-DO

Add Route

sudo ip route add <SUBNET> via <GATEWAY> dev <INTERFACE>
Sample Output: sudo ip route add 172.16.0.0/16 via 192.168.1.10 dev eth0

Modify Route

sudo ip route replace <SUBNET> via <GATEWAY> dev <INTERFACE>
Sample Output: sudo ip route replace 172.16.0.0/16 via 192.168.1.20 dev eth0

Delete Route

sudo ip route del <SUBNET>
Sample Output: sudo ip route del 172.16.0.0/16
# Exact match sudo ip route del <SUBNET> via <GATEWAY> dev <INTERFACE>
Sample Output: sudo ip route del 172.16.0.0/16 via 192.168.1.10 dev eth0

Check Routes

netsh interface ipv4 show route
Sample Output: TO-DO

Add Route

netsh interface ipv4 add route <SUBNET> "<INTERFACE>" <GATEWAY> store=persistent
Sample Output: netsh interface ipv4 add route 172.16.0.0/16 "Ethernet" 192.168.1.10 store=persistent

Delete Route

netsh interface ipv4 delete route <SUBNET> "<INTERFACE>" <GATEWAY>
Sample Output: netsh interface ipv4 delete route 172.16.0.0/16 "Ethernet" 192.168.1.10

Flush Routes

netsh interface ipv4 reset
Sample Output: TO-DO

Check Routes

Get-NetRoute
Sample Output: TO-DO

Add Route

New-NetRoute -DestinationPrefix "<SUBNET>" -NextHop "<GATEWAY>" -InterfaceAlias "<INTERFACE>" -PolicyStore PersistentStore
Sample Output: New-NetRoute -DestinationPrefix "172.16.0.0/16" -NextHop "192.168.1.10" -InterfaceAlias "Ethernet" -PolicyStore PersistentStore

Delete Route

Set-NetRoute -DestinationPrefix "<SUBNET>" -NextHop "<NEW_GATEWAY>" -InterfaceAlias "<INTERFACE>"
Sample Output: Set-NetRoute -DestinationPrefix "172.16.0.0/16" -NextHop "192.168.1.20" -InterfaceAlias "Ethernet"

Flush Routes

Remove-NetRoute -Confirm:$false
Sample Output: TO-DO
# Re-add default gateway New-NetRoute -DestinationPrefix "0.0.0.0/0" -NextHop "<GATEWAY>" -InterfaceAlias "<INTERFACE>"
Sample Output: New-NetRoute -DestinationPrefix "0.0.0.0/0" -NextHop "192.168.1.1" -InterfaceAlias "Ethernet"