Windows 2012 Core Survival Guide – Default Gateway Settings

Learn about my 2012 Core Survival Guide here.

Default Gateway Settings

Often when troubleshooting IPv4 configuration you may find a misconfigured default gateway. Issue that may arise from a misconfigured gateway are:

  • Ping responses not traversing the router
  • IPv4 communication only working with clients on same network segment
  • Server not receiving a DHCP address

Viewing the Default Gateway

Like with most of the IPv4 settings IPConfig can be used to view the configuration. If you wish to change the default gateway settings you will have to know the “interfaceindex” to modify it. We use Get-NetIPconfiguration to view both the interface index and the IPv4DefaultGateway value.

PowerShell Command:

Get-NetIPConfiguration

The command will show in a list format each network interfaces IP configuration. In order to get this in a table format the PowerShell command gets a little confusing.

 

If you wish to view this information in a table format you can use the following command. I must admit, I had help with this command.

PowerShell Command:

Get-NetIPConfiguration | Format-table interfaceindex,interfacealias,ipv4address, @{ label=”DefaultGateway”; Expression={ $_.IPv4DefaultGateway.NextHop }}, @{ label=”DnsServers”; Expression={ $_.DnsServer.ServerAddresses}} -autosize

In the output below can you see where we are misconfigured?

 

That right we should only have a single default gateway! To view the same default gateway using get-netroute use the following command.

 PowerShell Command:

 Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Format-table -autosize

 In the screen shot below the default gateway is under the "NextHop" column the network interface it is configured on is under the ifIndex column. We should only have a single default gateway!

Removing the Default Gateway

First you must locate the correct default gateway you wish to remove using the commands above. You then need to know the ifIndex and the NextHop of the default gateway you wish to remove. Below I show you how to use them in the PowerShell command.

PowerShell Command:

Remove-NetRoute -ifindex 12 -NextHop "192.168.0.3"

In the screen shot below the default gateway is removed. 

 Setting the Default Gateway

The easiest way to set the default gateway is to first make sure any pervious settings have been removed, shown above.

It is best practice to configure the IP Address, Subnet Mask and Default Gateway all at the same time. I show you how to do this in Managing basic IPv4 configuration information.

When there is no default gateway configure you can use the command below to set it.

PowerShell Command

New-NetRoute -interfaceindex 15 -NextHop "192.168.0.1" -destinationprefix "0.0.0.0/0"

In the output below I configured Interfaceindex 15. I began with no default gateway set. Set the default gateway for interfaceindex 15 to 192.168.0.1 and then confirmed the setting was correct. 

I hope you found this useful. Please leave me a comment

Bruce