Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If statement based on IP address?
2014-01-23, 16:23
Post: #1
If statement based on IP address?
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
Find all posts by this user
Quote this message in a reply
2014-01-30, 23:04
Post: #2
RE: If statement based on IP address?
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
2014-02-02, 12:02 (This post was last modified: 2014-02-02 12:06 by Torgeir.)
Post: #3
RE: If statement based on IP address?
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.

--
Find all posts by this user
Quote this message in a reply
2014-02-04, 02:43
Post: #4
RE: If statement based on IP address?
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 ...
Find all posts by this user
Quote this message in a reply
2014-02-05, 00:21
Post: #5
RE: If statement based on IP address?
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

"Thus far, you have been adrift within the sheltered harbor of my patience..."
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)