Networking

Force the primary outgoing IP address Windows Server 2012 R2

How to orce the primary outgoing IP address Windows Server 2012 R2

In working recently with a web server that also has a basic SMTP engine loaded as well, I ran into an issue with the mail server outbound mail queue stacking up after making a reverse DNS change with the ISP. ย The server which is a Windows 2012 Standard VM was not multihomed, but rather had multiple IP addresses in the same subnet assigned to the virtual adapter. ย In verifying everythingย the server was indeed setup in the SMTP server (simply the built in feature that can be installed) properties to use the correct IP address. ย However, it apparently was not sending using that address. ย Why?

It all comes down to how Windows Server versions since Windows Server 2008 and higher treat IP addresses in the same subnet when you have multiple addresses assigned. ย Prior to Windows 2008, Windows Server used the “weak host model” and now newer server OS’es are using the “strong host model” when picking an IP address to send from. ย The new server behavior more often than not picks the lowest IP address assigned in the network properties, whether this is theย primary IPย assigned or anย additional IP assigned to the interface. ย Take a look at this Microsoft KB which explains the functionality of Windows Server 2008 and higher: ย https://support.microsoft.com/

There are a few articles out there which explain how to use netshย to set the skipassourceย flag which effectively tells Windows you don’t want this interface to be used as the outgoing interface for traffic coming out of the server. ย However, I want to take these a bit further and describe some behavior that I saw in the environment I mentioned at the outset.

The environment

As you can see below, the primary IP address assigned in the network properties isย 192.168.1.80.

ip01

The additional IP address that has been assigned isย 192.168.1.50.

ip02

However, when quickly doing aย route print on the box, it is easy to see the outgoing interface being preferred for routing traffic outbound isย 192.168.1.50! ย So don’t assume that since you have an IP address bound to the primary TCP/IP properties slot that it will be used for the outbound interface.

ip03

In steps Powershell

There are so many awesome thing we can do with powershell that can make our lives so much better. ย As opposed to using netsh which requires theย skipassource flag to be set when adding the IP address, the powershell commandlets will allow us to manipulate this flag as is without having to strip anything out or reconfigure IP addresses. ย What is the skipassource flag?

From most of the Microsoft articles I have been able to find, the skipassource flag was primarily written with the intent of DNS registration and allowing the flag to control which interface was used to register DNS records. ย However, this flag is much more powerful than that as we will demonstrate.

To see your IP Address and skipassource flag currently set:

get-netadapter | get-netipaddress | select ipaddress, skipassource

You will see output similar to the following:

ip04

We can effectively manipulate which address is being used to send traffic with theย Set-NetIPAddress commandlet. ย So in the example above, I want to useย 192.168.1.80 instead ofย 192.168.1.50 as the preferred inteface.

Set-NetIPAddress โ€“IPAddress 192.168.1.50 โ€“SkipAsSource $True

Notice now what our route looks like after running the command:

ip05

This is interesting how the command effectively changes your route statements. ย Also, a very interesting find to me was that if I set the skipassource flag for .50 back to “False” and set the .80 skipassource flag to “True”, it changes the primary address to .50! ย Take a look:

Ran the commandlets to set the flags accordingly:

ip06

With no GUI intervention, it has set .50 to the primary address:

ip07

Now .80 is assigned as the additional address.

ip08

Also, a really cool finding with how this works is that I ran a continuous ping on both IP addresses and the server didn’t drop a single packet with the swapping. ย So the additional benefit of this is that if you need to quickly swap addresses you can actually use this flag setting as a means to do that.

The skipassource flag is definitely something administrators need to keep in mind when running multiple IP addresses on a single interface or multihomed servers as well. ย Especially if you are running IP addresses in the same subnet range, Windows will pick the address with the lowest IP in the subnet for outgoing egress traffic if there isn’t a request coming in for a particular IP.

 

 

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.