• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Using the "net" command in windows to change an ip address on another windows machine?

Czar

Lifer
I'm trying to make an automatic failover script/program... or write down what needs to be done and letting one of the programmers here at work to have a hack at it.

Basicly just a heartbeat sensor on two servers, if one goes offline the program would run a net command to change the ip address of the second server to take over the primary server.

What would be the best way to do this?
 
fewer clients to install, less management

But it seems to be the only way is to have it on the computer itself. Probably better because then the heartbeat can flow from the witnes server application to the application running on the other two servers.
 
The net command doesn't do such things netsh does and it doesn't do so remotely.

WMI windows scripts?
Remotely edit registry?

You could perhaps use NLB (likely built-in and free on your Windows server) that lets both machines use the same IP and simply keep one node down.



This sounds like a really convoluted way to solve a problem that has already been solved in several ways.
 
And even if netsh did do it remotely what happens when you change the IP in the middle of your netsh script and you lose the connection? The script will fail half way through, not exactly a good idea if you ask me.
 
Originally posted by: Nothinman
And even if netsh did do it remotely what happens when you change the IP in the middle of your netsh script and you lose the connection? The script will fail half way through, not exactly a good idea if you ask me.

well it could just add a second ip address in addition to the current ip address (no idea if you can script that with netsh).
 
well it could just add a second ip address in addition to the current ip address (no idea if you can script that with netsh).

There are definitely ways around that problem, but it's just safer to have the script/config on the local machine so there's no chance of problems when the switch happens.
 
Originally posted by: Nothinman
well it could just add a second ip address in addition to the current ip address (no idea if you can script that with netsh).

There are definitely ways around that problem, but it's just safer to have the script/config on the local machine so there's no chance of problems when the switch happens.

and safer still not to do any retardedness but instead rely on known and proven failover/redundancy technologies.

If it's important enough to have failover/redundancy why is not important enough to put time or money into???
 
If it's important enough to have failover/redundancy why is not important enough to put time or money into???

Definitely, but my past experience with another vendor's failover were not good and I would bet that I could come up with something more reliable and simpler than their concoction. As long as you're not worried about keeping state for any of the active connections it's a pretty simple process.
 
you could write the netsh batch file on the second server, and use something like psexec from systernals to call that batch file remotely....

look into all the pstools, as there is some great stuff in there. You MIGHT consider fencing/failing over in other ways, rather then just changing IP's (such as using a managed switch and changing the port status using SNMP, telnet or local serial port)
 
It would be simplest to just have a service that does the heartbeat on each box and changes the IP locally, I don't see the need to keep the configs central since it's not like you'll be changing them very often.
 
Originally posted by: Smilin
The net command doesn't do such things netsh does and it doesn't do so remotely.

WMI windows scripts?
Remotely edit registry?

You could perhaps use NLB (likely built-in and free on your Windows server) that lets both machines use the same IP and simply keep one node down.



This sounds like a really convoluted way to solve a problem that has already been solved in several ways.

ahah nlb, yeah forgot to look into that one, will do that tomorrow 🙂

was mostly looking at third party automatic failover solutions and those are not cheap, and make something very simple very complex
 
Originally posted by: nweaver
you could write the netsh batch file on the second server, and use something like psexec from systernals to call that batch file remotely....

look into all the pstools, as there is some great stuff in there. You MIGHT consider fencing/failing over in other ways, rather then just changing IP's (such as using a managed switch and changing the port status using SNMP, telnet or local serial port)

will check out sysinternals stuff tomorrow thanks 🙂

I thought about using the switch to shut down ports, but that would I think bring us back to making a simple problem complex
 
Originally posted by: Czar
Originally posted by: nweaver
you could write the netsh batch file on the second server, and use something like psexec from systernals to call that batch file remotely....

look into all the pstools, as there is some great stuff in there. You MIGHT consider fencing/failing over in other ways, rather then just changing IP's (such as using a managed switch and changing the port status using SNMP, telnet or local serial port)

will check out sysinternals stuff tomorrow thanks 🙂

I thought about using the switch to shut down ports, but that would I think bring us back to making a simple problem complex

actually....


I could have that done in no time flat...every minute, you ping the IP, if it's down, you have a telnet subroutine to up box2 and down box1 (to prevent it from coming back up and knocking both off the network)

probaby only 20-30 lines of code in perl...and I'm sure there are severa perl folks who would scoff at that many.
 
well you could have a bat file on the machine you need to change the ip on and find someway to remotely run it, now the example i have provided is for 1 of our users to get a dhcp address in 1 place and staic in another but you be able to modify it to suit..

1 bat file 2 TEXT FILES

contents of bat file

@echo off
title Change IP Configuration Batch File - 2006
setlocal
set OK=N



:again
set /p choice=Please enter 1[Swindon], 2[London] or END ??
if /i [%choice%]==[END] endlocal&goto end
if [%choice%]==[] goto again
if [%choice%]==[1] goto 1
if [%choice%]==[2] goto 2
set /p xxx=wrong entry, press any key to exit.
endlocal
goto end



:1
echo NIC setting for Swindon being configured.....
@netsh exec Swindon.txt
set /p see=IP changed successfully to Swindon Settings [9]see new setting [Enter]exit...
if [%see%]==[9] goto show
echo Ending IP Configuration
goto end



:2
echo NIC setting for London being configured.....
@netsh exec London.txt
set /p see=IP changed successfully to London Settings [9]see new setting [Enter]exit...
if [%see%]==[9] goto show
echo Ending IP Configuration
goto end



:show
@netsh int ip show config



:end
@echo on
cls

text file 1 DHCP

# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Local Area Connection"
set address name="Local Area Connection" source=dhcp
set dns name="Local Area Connection" source=dhcp register=primary
set wins name="Local Area Connection" source=dhcp


popd
# End of interface IP configuration

TEXT FILE 2 STATIC

# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Local Are Connection"
set address name="Local Area Connection" source=static addr=XXX.XXX.XX.XXX mask=255.255.255.0
set address name="Local Area Connection" gateway=XXX.XXX.XX.XXX gwmetric=0
set dns name="Local Area Connection" source=static addr=XXX.XXX.XX.XXX register=primary


popd
# End of interface IP configuration

i only needed 2 for my users but you could make as many as you want to

Regards

Allanv
 
good script you have there 🙂


but I checked out NLB and that is exactly what I was looking for 🙂 cant belive I havent used it before

So far I set up three machines in my vmware setup, set two of them up with nlb, one to monitor, and the failover is instant, I'm a happy admin right now 😀
 
Back
Top