Table of contents
- Introduction
- How to check windows routing table from powershell
- How to add new routes in windows routing table from powershell
- How to modify added routes in windows routing table from powershell
- How to delete routes in windows routing table from powershell
- Conclusion
Introduction
Checking , adding or deleting the routes in the host windows machines routing table is a key skill for any system engineer or the network admin. In this article we will see how to do those with practical examples
How to check windows routing table from powershell
There are two command we can use to check the windows routing table entries from the powershell
route print
netstat -rn
Here is an example of using route print
to check the windows routing table from the powershell
PS C:\Users\Public\Discovering-systems> route print
===========================================================================
Interface List
27...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
9...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.1 10.0.0.166 40
10.0.0.0 255.255.255.0 On-link 10.0.0.166 296
10.0.0.166 255.255.255.255 On-link 10.0.0.166 296
.
.
.
Here is an example of using netstat -rn
to check the windows routing table from the powershell
PS C:\Users\Public\Discovering-systems> netstat -rn
===========================================================================
Interface List
27...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
9...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.1 10.0.0.166 40
10.0.0.0 255.255.255.0 On-link 10.0.0.166 296
10.0.0.166 255.255.255.255 On-link 10.0.0.166 296
.
.
.
How to add new routes in windows routing table from powershell
Here is a practical example on how to add a route 10.123.0.0/16 pointing to the nexthop 10.0.0.1 in windows routing table using the powershell
PS C:\Users\Public\Discovering-systems> route add 10.123.0.0 mask 255.255.0.0 10.0.0.1 metric 3
OK!
PS C:\Users\Public\Discovering-systems> route print 10.123.0.0
.
.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
10.123.0.0 255.255.0.0 10.0.0.1 10.0.0.166 43
===========================================================================
.
.
How to modify added routes in windows routing table from powershell
Here is a practical example on how to modify a route 10.123.0.0/16 to make it point to the new nexthop 10.0.0.2 in windows routing table using the powershell
PS C:\Users\Public\Discovering-systems> route change 10.123.0.0 mask 255.255.0.0 10.0.0.2 metric 3
OK!
PS C:\Users\Public\Discovering-systems> route print 10.123.0.0
.
.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
10.123.0.0 255.255.0.0 10.0.0.2 10.0.0.166 48
===========================================================================
.
.
How to delete routes in windows routing table from powershell
Here is a practical example on how to delete a route 10.123.0.0/16 pointing to the nexthop 10.0.0.1 in windows routing table using the powershell
PS C:\Users\Public\Discovering-systems> route delete 10.123.0.0
OK!
PS C:\Users\Public\Discovering-systems> route print 10.123.0.0
.
.
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
None
===========================================================================
.
.
Conclusion
In this article we explored the steps to Check , add or delete routes in the windows routing table using the powershell.
If you are interested in more cool things we can do from the Windows Powershell , please go through the following links