9

I have a Windows 8 machine that has only a single Ethernet port. It needs to use DHCP and also needs a static IP. Each IP is in a different subnet, and each serves a different, incompatible purpose.

This machine must use DHCP because the site network admin says this is the only supported way to get a 192.168.x.y address. Either his network scheme doesn't have a static IP block within that subnet, or he won't assign one of them to this machine.

I can't risk using a DHCP-assigned IP statically, betting it won't be reassigned after the lease expires. That would let me use Windows' ability to assign multiple static IPs to the interface, but this is a production server, not something I can risk getting bounced off the network hours or days later.

I realize that some DHCP servers let you set up static MAC to IP assignments, so that my machine's DHCP IP is never reassigned, but since I know of no DHCP server that will issue two different IP addresses, each in a different subnet, that's no help here. (And if there is such a DHCP server, my client probably doesn't use it and wouldn't change over to it if I asked.)

Since I can't do this entirely with DHCP, I need a static IP because this machine also acts as a server to a 10.x.y.z subnet. The local network admins have given me a static IP in that scheme, but it's insufficient because I also need to talk to the 192.168.x.y side of the network.

I'm aware of a similar question here. I'm asking again because:

  1. That other question was posed when Windows 7 was current. Perhaps Microsoft used those 2+ years to fix this weakness in the Windows 8 network stack implementation?

    (Yes, weakness: Linux allows a network interface with both a DHCP and a static IP. There's nothing about TCP/IP that prevents Microsoft from allowing this. They just have to write the code to allow it.)

  2. It seems the network configuration GUI in Windows 8 has the same limitation as Windows 7's, but perhaps there is some low-level hack that will let us assign a static IP alias to the DHCP interface?

7

I wrote a small batch-file. You can test to see if it works in your situation. (here it works fine)

  • It will set your interface back to DHCP.
  • After that it will extract IP, Subnet Mask, Default Gateway and the first DNS-server. This is the difficult bit. Especially if you have multiple interfaces. If it doesn't work we need to fiddle here a bit to get it to work.
  • If you want the second DNS too it should be added here (but i didn't look that far because one DNS should be fine for now).
  • It will set these settings "static" on the interface.
  • After that you can add the 10.x.y.z address to your interface without a problem.

Here is the script:

@echo off
set interface="Ethernet 2"
set extra_ip=10.0.0.33
set extra_mask=255.255.248.0

echo Setting %interface% back to DHCP
netsh int ipv4 set address name=%interface% source=dhcp
netsh int ipv4 set dnsservers name=%interface% source=dhcp

echo Waiting for IP to stabilize...
timeout /t 5

echo Getting current IP of %interface%
ipconfig > %temp%\ipconfig.txt
for /f "tokens=2 delims=:" %%a in ('type %temp%\ipconfig.txt ^| find "IPv4" ^| find /v "127.0"') do set _IP=%%a
set IP=%_IP:~1%
for /f "tokens=2 delims=:" %%a in ('type %temp%\ipconfig.txt ^| find "Subnet" ^| find /v "127.0"') do set _IP=%%a
set MASK=%_IP:~1%
for /f "tokens=2 delims=:" %%a in ('type %temp%\ipconfig.txt ^| find "Default" ^| find /v "127.0" ^| find /v "::" ') do set _IP=%%a
set GATE=%_IP:~1%
for /f "tokens=2 delims=:" %%a in ('type %temp%\ipconfig.txt ^| find "DNS Servers" ^| find /v "127.0"') do set _IP=%%a
set DNS1=%_IP:~1%

echo Setting IP Address, Subnet Mask and Default Gateway...
echo (IP %IP%, mask %MASK%, gw %GATE%)
netsh int ipv4 set address name=%interface% static %IP% %MASK% %GATE% gwmetric=1

timeout /t 5
echo Setting Primary DNS (%DNS1%)...
netsh int ipv4 set dnsserver name=%interface% static %DNS1% primary

echo Adding secondary IP...
netsh int ipv4 add address %interface% %extra_ip% %extra_mask%

timeout /t 5
echo.
echo New IP configuration:
ipconfig /all

del %temp\ipconfig.txt

You only need to run this once a period of your lease (or after a restart). So if your lease is 10 days you could set this in the task scheduler for 3 AM on Sunday and after every restart. If your computer is always off at night it would only be needed after restart.

4

Finally DHCP and static IPs can be configured to co-exist on one NIC. This feature has landed in the Windows 10 Creators Update (1703).

There is a new property called dhcpstaticipcoexistence in the netsh interface ipv4 set interface command, which can be set to enabled and this interface can be configured with multiple static IPs along with a DHCP-configured IP. However this has to be done with the netsh add address command, not yet possible via the GUI.

Little documentation has been published about the update to netsh and there is little discussion about it on the entire Internet (Google search dhcpstaticipcoexistence gives only 5 results at the time of this answer). But this feature is real.

  • 2
    This answer was very useful to me as it worked across reboots and seemed like a good 1st party solution. Including examples of the commands to use would have been nice. This answer was so close to giving example commands, but I had to go to Google to figure out the exact syntax. My final commands were netsh interface ipv4 set interface interface="Ethernet" dhcpstaticipcoexistence=enabled and netsh interface ipv4 add address "Ethernet" 192.168.1.200 255.255.255.0. – jljtgr Dec 1 '18 at 4:54
4

Thanks Cecil, it works, here's what I did:

  1. Find out the interface name:

    netsh interface ipv4 show interface

  2. Enable dhcpstaticipcoexistence:

    netsh interface ipv4 set interface interface="interface name" dhcpstaticipcoexistence=enabled

  3. Add a static ip address to your interface

    netsh interface ipv4 add address "interface name" 192.168.x.xxx 255.255.255.0

  4. Use command 'ipconfig /all' to verify the static ip address is added. You can not do it from GUI.

3

One workaround could be to run a VM on the same machine and add a static IP to that VM. This will essentially provide a virtual adapter on the host but for the 10.x.v.z network.

Custom Networking configufation simular to the one you are requesting is well docunmented here.

  • The VM idea is hunting butterflies with a sledgehammer. Adding a VM system and licensing Windows for VM use would be complicated and probably more expensive than just adding a second NIC to the machine. I only need the 10.x.y.z address to serve a single program. – Warren Young Nov 22 '13 at 2:54
  • That is why I preface the answer with "one workaround could be.."; adding a VM would certainly work. Multihoming is obvious; but then again, your idea would fundamentally change the original question. good luck – Fergus Nov 22 '13 at 6:27
1

How about scheduling a script to add the IP address after boot:

netsh interface ipv4 add address “Local Area Connection” 10.x.y.z 255.255.255.0
  • Great idea, but I am confident that force the adapter out of DHCP. – Fergus Nov 22 '13 at 2:39
  • I tested it, and @Fergus is right: saying netsh interface ipv4 show address after this gives the static IP only. The DHCP IP is gone. – Warren Young Nov 22 '13 at 3:03
  • Ooops, yeah I remember now. The option would be to get the current IP, then add both back. It is very unlikely that an DHCP lease would not be renewed while in actively in use (there is a grace period to avoid this), so it only matters at boot time. – Paul Nov 22 '13 at 4:25
  • @Paul: If I just add the DHCP address back with netsh, doesn't that make it a static IP, so the Windows box's stack won't keep sending DHCP lease renewals to the DHCP server? When the initial lease time is up, the DHCP server would then be free to reassign that address. – Warren Young Nov 22 '13 at 5:17
  • @WarrenYoung How long is the lease you are getting? (ipconfig /all. for me it's 10 days from my router). So if the computer is restarted before the lease is over it shouldn't be a problem. Otherwise you could add a ipconfig /release and ipconfig /renew above these lines and schedule it to run at 3 AM (when nobody is behind the computer). – Rik Nov 22 '13 at 9:00
0

I used Win IP Config version 2.7.2 from 2007 running on Windows 10. Set your NIC to DHCP, Run Win IP Config as an administration (Right Click icon instead of double click for the option). Then click IP+ and type in the static ipaddress you want. I now have one DHCP and two static address. Now I can do my embedded system development and access the internet at the same time with one NIC!

  • This looks...so...shaddy.... – paquetp May 6 '18 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.