Obtaining a DHCP IP address if static address is not available

8

1

I have seen some questions that are similar to my problem but not a good solution.

Ex. User has a laptop and has a static IP address at the office. They also take the laptop off site where they also need internet.

Is there a way to configure their computer so that it will obtain an IP address automatically when the configured static address is not available (without making the user go into network configuration and changing to obtain automatically)?

user142485

Posted 2012-06-29T19:27:29.543

Reputation: 1 743

Don't know the answer for Windows 7, but many years ago (the XP times) some laptop manufacturers had their own software to handle this, one could define different settings for different locations and switch between them; I think the IBM one was called Access Connections or something similar. From what I remember, using the built-in network XP settings one could do this with Alternate Configuration or something like that, but it didn't work well. – lupincho – 2012-06-29T19:40:55.380

Why don't go the other way around, configure the DHCP server at the office to assign user an static IP so it will always work. – jhcaiced – 2012-06-29T22:53:06.747

Answers

8

I don't know if there's an automatic way, but the way I did it with my laptop was with a program called Mobile Net Switch. http://www.mobilenetswitch.com/ It lets you juggle between different active network configurations so you can have one for your work network and when you go off site, you switch to the network configuration that is set to obtain DHCP automatically.

An alternate solution if your router has this feature in its firmware is to configure Static DHCP for that device. Get the laptop's wireless MAC address, and if your router supports it, configure it to automatically assign a static IP address on the router. Third party router firmwares like Tomato and DD-WRT support this out of the box. I feel this is the cleanest solution. Using this method will allow your user to keep the laptop set on DHCP mode without any problems. I use this setup for my home network so I don't have to worry about manual configuration on the device side - all configuration is done from the router.

White Phoenix

Posted 2012-06-29T19:27:29.543

Reputation: 1 271

I don't really want to put any other software on it, I don't want users to have to do anything. It would be nice if DHCP could just be an "Alternate Configuration" when static is not available but there is probably a reason its not. The second solution seems like my best bet, thanks. – user142485 – 2012-06-29T19:44:07.793

5Agreed. Don't use statis IP addresses. Create reservations in your DHCP server instead. – jftuga – 2012-06-29T19:51:55.923

7

A lot of people are not aware that the Windows network configuration can be adjusted through the command line. For example:

Set your network adapter to DHCP

netsh interface ipv4 set address "Local Area Connection" dhcp
ipconfig /renew

Set your network adapter to static IP

netsh interface ipv4 set address "Local Area Connection" static 10.1.2.3 255.0.0.0 10.0.0.1

With that in mind, it becomes trivial to write 2 .bat files which you can put on your desktop.

This makes it a lot easier to switch network configurations

Der Hochstapler

Posted 2012-06-29T19:27:29.543

Reputation: 77 228

Depending on the wireless adapter, you might also be able to assign it to run these when they connect to each network so that minimal user intervention is needed (probably when new networks are added) – Nick – 2012-07-05T20:01:09.823

4

Windows 7 has the concept of an "Alternate Configuration" in the network card's IP configuration. From the Windows Help page for "IPv4 Alternate Configuration Tab":

User configured specifies that IPv4 will use a manually specified configuration if a DHCP server is not found. This alternate configuration is useful when the computer is used on more than one network, at least one of the networks does not have a DHCP server, and an APIPA configuration is not wanted. A good example is a portable computer that is used at the office and at home. At the office, the laptop uses a DHCP-allocated TCP/IP configuration. At home, where there is no DHCP server present, the portable computer automatically uses the alternate configuration, allowing easy access to home network devices and the Internet. This enables the portable computer to operate seamlessly on both networks without manual IP reconfiguration.

Set this up by going to Control Panel -> Network status and tasks (or "Network and Sharing Centre" if you're not using the category view).

Click the connection name that you're interested in (probably "Local Area Connection" or "Wireless Network Connection (network name)").

enter image description here

This should pop up the Connection Status window, click the Properties button. enter image description here

In the Connection Properties window, look for the "Internet Protocol Version 4 (TCP/IPv4)" line, click that and click Properties.

enter image description here

You should now have a window with two tabs, one of which is "General", the other is "Alternate Configuration".

You can now set the first tab to use DHCP (select "Obtain an IP address automatically" and "Obtain DNS server address automatically") and put your static IP details into the second "Alternate Configuration" tab.

enter image description here enter image description here

More from Technet IPv4 Alternate Configuration Tab and elsewhere on SuperUser What is the "Alternate Configuration" tab in TCP/IP settings

GAThrawn

Posted 2012-06-29T19:27:29.543

Reputation: 4 176

This of course assumes that the reason you've got a static IP address is because there's no DHCP available at the office. On the other hand, if you do have DHCP in the office then why not just leave the laptop set to DHCP all the time and reserve the IP address for the machine on the DHCP server? – GAThrawn – 2012-07-06T13:35:03.330

I agree with reserving the address in DHCP, that was the answer I accepted. Even-so, this is a great write-up for configuring IP properties, thanks for the input. – user142485 – 2012-07-06T13:54:27.267

1

Not that I know of. Configuring a static address is analogous to telling the computer to completely ignore the network - a static address is in concept "always available" (barring a IP conflict) from the computer's point of view.

If you can find a way to use multiple network interfaces, configure one for DHCP and one for static, and set the static one to have a higher metric (cost) than the DHCP one. This will cause the system to use the DHCP if it's available, but fall back to the static one if the system isn't connected to a DHCP network. Most laptops don't have this, so you might need to use a USB network interface to achieve this.

If you're using a laptop running linux (you tagged windows 7, so this is more for completeness), then you can use IP aliasing to assign two IPs to the same interface. Combine with the above idea to create a network port which will try to use DHCP, but fall back to static IP if DHCP fails.

Darth Android

Posted 2012-06-29T19:27:29.543

Reputation: 35 133

Your second paragraph seems like it would work, you switched your words in the second sentence though. – user142485 – 2012-06-29T19:46:26.883

@user142485 Which words? I'm not noticing the ones to which you're referencing. – Darth Android – 2012-06-29T20:00:26.883

"This will cause the system to use the DHCP if it's available, but fall back to the static one if the system isn't connected to a DHCP network." The goal is for the system to fall back to DHCP when the static address is not available. – user142485 – 2012-06-29T20:02:25.990

1@user142485 You can't do that, as there's no way to detect when a static IP is "unavailable" (see my first paragraph). On the other hand, you can detect when DHCP is not available (given a timeout), and fall back to a static IP. – Darth Android – 2012-06-29T20:04:57.347

This is what my question was; whether or not you can fall back on DHCP if the static address was not available (my terminology is not exact here, maybe I should have said only allowing Local only access). Obtaining an address with dhcp and falling back on Automatic private or static addressing is the default setting in windows anyway. – user142485 – 2012-06-29T20:23:11.970

1@user142485 I see. The issue is there is no way to tell the difference between a misconfigured static address, or a failing/temporarily unavailable gateway and a correctly configured static address. – Darth Android – 2012-06-29T20:25:59.887

1I guess this answers my question on why my desired configuration is not an option: because it is expecting the address to be usable and in theory, that address could temporarily have limited access (due to a down gateway as you exemplified) and would not want to be changed in the event that the gateway would come back. Thanks for the explanation. – user142485 – 2012-06-29T20:36:06.470