Give a static ip alias to some dhcp interface on home windows 8 (and above) – super user

I authored a little batch-file. You can look at to find out if it really works inside your situation. (here it really works fine)

  • It’ll set your interface to DHCP.
  • Then it will extract IP, Subnet Mask, Default Gateway and also the first DNS-server. This is actually the difficult bit. Particularly if you have multiple interfaces. Whether it does not work we have to fiddle here a little to have it to operate.
  • If you would like the 2nd DNS too it ought to be added here (however i did not look that far because one DNS ought to be acceptable for now).
  • It’ll set these settings “static” around the interface.
  • Then you’re able to add some 10.x.y.z address for your interface with no problem.

I authored a little batch-file. You can look at to find out if it really works inside your situation. (here it really works fine)

  • It’ll set your interface to DHCP.
  • Then it will extract IP, Subnet Mask, Default Gateway and also the first DNS-server. This is actually the difficult bit. Particularly if you have multiple interfaces. Whether it does not work we have to fiddle here a little to have it to operate.
  • If you would like the 2nd DNS too it ought to be added here (however i did not look that far because one DNS ought to be acceptable for now).
  • It’ll set these settings “static” around the interface.
  • Then you’re able to add some 10.x.y.z address for your interface with no problem.

This is actually the script:

Give a static ip alias to some dhcp interface on home windows 8 (and above) - super user ten days you can set

@echo off

set interface=”Ethernet 2″

set extra_ip=10…33

set extra_mask=255.255.248.

echo Setting %interface% to DHCP

netsh int ipv4 set address name=%interface% source=dhcp

netsh int ipv4 set dnsservers name=%interface% source=dhcp

echo Awaiting 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.”‘) do set _IP=%%a

set IP=%_IP:~1%

for /f “tokens=2 delims=:” %%a in (‘type %temp%ipconfig.txt ^ find “Subnet” ^ find /v “127.”‘) do set _IP=%%a

set MASK=%_IP:~1%

for /f “tokens=2 delims=:” %%a in (‘type %temp%ipconfig.txt ^ find “Default” ^ find /v “127.” ^ 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.”‘) do set _IP=%%a

set DNS1=%_IP:~1%

echo Setting Ip, 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 %tempipconfig.txt

You simply need to run this once a time period of your lease (or following a restart). Therefore if your lease is ten days you can set this within the task scheduler for several AM on Sunday after every restart. In case your computer is definitely off during the night it might simply be needed after restart.

Give a static ip alias to some dhcp interface on home windows 8 (and above) - super user several AM

Resourse: https://superuser.com/questions/679134/

Stan Walker – Give