PowerShell: Get Default Gateway
Need to check a machine's default gateway - for network troubleshooting, documentation, or confirming router configuration? This one-liner pulls it straight from the system's routing table.
Prerequisites:
- Privileges: None
- Module: Built-in, no import needed
Quick Command:
Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object NextHop, InterfaceAlias
Example Output:
NextHop InterfaceAlias
------- --------------
10.211.55.1 Ethernet
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
How It Works:
- Get-NetRoute returns the full routing table - a list of every network path the system knows about, including local subnets, multicast ranges, and loopback routes.
- -DestinationPrefix "0.0.0.0/0" filters that table down to just the default route - the entry that catches all traffic not covered by a more specific route, which is exactly what "default gateway" means.
- NextHop shows the actual gateway IP address traffic gets sent to, and InterfaceAlias shows which network adapter uses it.
Pro Tip:
If a machine has multiple network adapters, this may return more than one default route. Check InterfaceAlias to confirm which one is actually active for your connection.