Change Static IPs
Hello I was wondering if there was an efficient way to use FOG to change the IP address of a computer after imaging. I stumbled across these two posts in my research and neither seemed to really have an answer.
One requires the use of the now outdated IP field and the other would require creating 600+ different snapins. Is there any way of doing this while using the fog hostname as the constant variable?
Thanks in advance!
@turcotter Here is 3 different ways you could do this with powershell and a fog snapin. Reply #2 is interesting since it embeds the csv file right into the powershell script.
We can only offer ideas based on how the snapin system works since we have not / do not assign static IP addresses this way to hosts. I’m not saying its wrong, only we don’t have the experience doing this.
@george1421 Alright thanks for your help but I have to take a few steps back i guess I am trying to just run a simple batch file to confirm that at least my snapin configuration is correct and even that isn’t wokring properly. I am trying to run this batch file:
ECHO BATCH > C:\Users\REG\Desktop\BATCH_LOG.txt
and even this isn’t working and is just failing at “MIddleware:: Authentication Waiting for authentication timeout to pass”
Thanks for your help again I know this is starting to drag on. Is there any in depth literature on this sort of thing I can’t really seem to find any.
@turcotter So if you were to take my script and change it this way.
net use w: \\Server\Share /user:domain\user password Set csv=w:\pcsetup\ipchanger\ComputerList.csv if not exist %csv% echo "Unable to access csv file" >c:\windows\temp\ipset_error.txt for /f “skip=1 delims=, tokens=1-7” %%a in (%csv%) do (
and then at the end remove the mapping to the w: drive
net use w: /delete
Warning: I did not test or debug this but just wrote off the top of my head. But the idea is that if the script can’t reach the csv file it will create a flag file ip_set_error in c:\windows\temp directory.
@turcotter The issue in the link is that SYSTEM does have local admin rights, but it can’t reach outside of the box to pickup the csv file. If you connect to the remote share as a domain user then you can access the central csv file.
The other method is to deliver the csv file with the batch file.
@george1421 Thanks for the reply I took what you said and did some test to try and get it to run and I thought I had solved it but it still doesnt change the IP. It was always my understanding that the SYSTEM had higher access than a normal admin account. I saw in the post you linked me that I could specify the user within the batch file? It runs fine when I just run it as admin without launching as a snapin. Any advice?
they are shipped to these conferences and are on their own LAN.
You could send a small desktop/raspberry pi with them to serve as a DHCP server. If you’re sending the switch, you could send a managed switch that does DHCP. If it’s not your LAN, you could request that the LAN have DHCP available. Just ideas.
@turcotter TBH, I did not look at the first script. I just did take a peek and this should work for you. I just got rid of the intents.
@Echo Off Set csv=\\Server\Share\pcsetup\ipchanger\ComputerList.csv for /f “skip=1 delims=, tokens=1-7” %%a in (%csv%) do ( if /I “%computername%”=="%%a" ( netsh int ipv4 set address “Local Area Connection” static %%b %%c %%d netsh int ipv4 set dnsserver “Local Area Connection” static %%e netsh int ipv4 add dnsserver “Local Area Connection” %%f netsh int ipv4 add dnsserver “Local Area Connection” %%g ) ) REM Pause Echo On
Now for the csv file. It looks like it takes on this form from the script
computer_name, ip_addr, subnet_mask, gateway,dns_server1, dns_server2, dns_server3 computer1, 192.168.1.20,255.255.255.0,192.168.1.1,192.168.1.50,192.168.1.52,192.168.1.55
No need for headers unless a human needs to read it. The script will look for a line that matches the current computer name in the .csv file and then set the parameters accordingly.
Just be aware you will have the same issue as the OP of the thread I linked, the snapin runs as the SYSTEM user, which is a local admin user that has no domain rights. You will need to map a drive to the remove CSV file, or just include it with the snapin then not need to worry about connecting to an external share.
@wayne-workman I don’t want to get too off topic but all imaging and management is done in our office and then they are shipped to these conferences and are on their own LAN.
@turcotter I think, if you make a csv and the snapin uses power shell, having headers would make you life a lot easier. Ultimately the csv could be something like:
hostname,ip Foghostname1,192.168.1.1 Foghostname2,192.168.1.2
@tom-elliott I agree that the CSV file would be ideal and the fastest method however I was unsure how to setup the file and was trying to find an example to better understand. Should I just leave all headers blank and just list column A=Hostname Column B = IP Column C= Sunbet and so on? Thanks for your help again.
Also for several security conferences the kiosks cannot be physically connected to the internet
If it’s a traveling laptop without internet access, how is the laptop going to get a snapin from FOG? If you plan on having a intranet at the conferences (offline network) that includes a FOG Server, why not have FOG do DHCP for you?
@turcotter if you follow the first article, they just created a csv of all the hosts and assigned the ip as another field. All the snapin does is look at that csv after getting the hostname.
So I’m not seeing how you would need 600 separate scripts.
If you’re willing to take the time to apply a “proper” ip through fog, why aren’t you willing to make a csv file containing the information? To me the csv is faster and simple. Doing through the GUI could be done, but you’d need to do edit each host individually. While it could be done through fog, functionally speaking fog does not have a feature such as requested. Yours and the other posting from 2013 you found are the only two cases I’ve seen needing this functionality. The snapin csv setting still sounds the easiesy method, even if fog did have this functionality.
@george1421 Thanks for the link this is very familiar to the first link i provided in my first link. This seems almost perfect I just get confused setting up the .CSV. I know I can put it somewhere on the server to share it to the clients but do I not put headers in the .CSV. Do you have an example of a .CSV setup? Thanks again!
@wayne-workman Thanks for the input I replied to Tom to explain why DHCP is not an option I was just wondering if there was a more automated way of doing this. Any ideas?
@tom-elliott The problem with that is that we have sort of a special use case. We use our laptops as mobile kiosks for tradeshows and conventions and are unable to use a separate DHCP server per many convention centers and venues guidelines. Also for several security conferences the kiosks cannot be physically connected to the internet so DHCP just isn’t an option. The script idea was going to be my last resort since it will get pretty long and unwieldy after 600 or so laptops are added.
@turcotter Someone who is doing something similar, where you might get an idea or two don’t follow the title, the action is the same none the less: https://forums.fogproject.org/topic/11474/problem-to-mapping-network-drive-using-snapin-with-batch-file
Agree with Tom. This is why DHCP was created - to address machines for you. If you want machines to always have the same IP address, use DHCP reservations.
Trying to create a snapin that sets IPs for you is basically like trying to recreate DHCP but in a really bad and likely to fail way.
Why not set dhcp server to hand out reserved addresses? That, to me, would seem the easiest.
That or make your snapin lookup the name of the physical machine, based on that give the appropriate IP address. (All ips stores in a single script based on the machine name. .e.g. foghostname1 => 192.168.1.1, foghostname2=> 220.127.116.11, etc…)