iPXE discussion forum
If statement based on IP address? - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: If statement based on IP address? (/showthread.php?tid=7186)



If statement based on IP address? - apitanga - 2014-01-23 16:23

Is there a variable for subnet? I'm trying to point to different chain scripts depending on the subnet from which the request originates.

Something like this:

Code:
#!ipxe
dhcp
goto ${subnet} || goto unknown
:192.168.0.0
chain http://server1/boot.ipxe
:172.29.28.0
chain http://server1/boot.ipxe
:unknown
boot tftp://server3/pxelinux.0



RE: If statement based on IP address? - robinsmidsrod - 2014-01-30 23:04

There is no way to detect the subnet, and iPXE scripting doesn't have any logic bit operators. But you can use the address of the dhcp-server or the next-server (tftp server) variable from the DHCP server to make decisions depending on which IP it is. The better option would be to configure the DHCP server to give out the right URL to chainload directly in the "filename" variable from each DHCP server and then just handle the case where filename is not set at all as a special case.


RE: If statement based on IP address? - Torgeir - 2014-02-02 12:02

Why do you want/need this?
With php in the loop you can do extra cool stuff.

Describe how/why a bit better, and maybe it is easier to help with a solution.

--


RE: If statement based on IP address? - apitanga - 2014-02-04 02:43

What's going on is that I have four different data-centers with different subnets and I'm trying to come up with a single iPXE boot that I can distribute to hypervisors/bare-metal on each location/subnet and then have clients being built only "touch" the boot server on that subnet.

I'd like to have the logic built into my boot iPXE ISO that checks from which subnet the request originates and chain a dynamic iPXE script that I'll replicate to each subnet's boot server.

I currently have that logic on the dynamic script, so that depending on where the request for the script comes from, a different boot server is presented, but the various subnets are still coming back to the same boot server defined in the ISO.

I think I'll do what robinsmidsrod suggests but make the decision depending on the gateway assigned to the client. That should be different depending on the subnet.

I'll report back ...


RE: If statement based on IP address? - MultimediaMan - 2014-02-05 00:21

If you have a GeoLoad Balancer, you can solve this problem with no scripting, GLB would select the "closest" one.

Also, If your datacenters have unique DNS Suffixes, you could search based on ${15}

Many newer DataCenters have geographical and location markers built into their DNS Suffixes:

e.g.

echo ${15}

aisle1.floor2.yourdatacenter.net which are then assigned a CNAME to make the 'local' DNS Suffix be "hidden" from the "outside" e.g.: yourcompany.com