Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default gateway from powershell?

Tags:

powershell

If a computer has multiple gateways, how can I determine which is the default gateway using the PowerShell?

like image 237
praveen Avatar asked Dec 13 '12 21:12

praveen


2 Answers

If you're on PowerShell v3, you can use Get-NetIPConfiguration e.g.:

Get-NetIPConfiguration | Foreach IPv4DefaultGateway
like image 189
Keith Hill Avatar answered Oct 11 '22 14:10

Keith Hill


I think this will be more cross platform:

 Get-NetRoute |
    where {$_.DestinationPrefix -eq '0.0.0.0/0'} |
    select { $_.NextHop }
like image 25
skfd Avatar answered Oct 11 '22 13:10

skfd