[ipxe-devel] [gPXE] Static IP address setting in gPXE

Michael Brown mbrown at fensystems.co.uk
Thu Mar 31 02:26:36 UTC 2011


On Thursday 31 Mar 2011 02:42:36 何闯 wrote:
> For some reason, I want to set a static IP address for my gPXE bootloader.
> I first run a PXENV_GET_CACHED_INFO call in pxeprefix.S, and store the
>  result in pxe_cached_dhcpack_data
> 
> then I coded such( dhcp call is replaced by it ):
> ////////////////////////////////////BEGIN//////////////////////////////////
> //////////////////////// struct settings *parent;
>     union pxe_cached_info *info;
>     struct dhcp_packet pxe_cached_dhcpack;
> 
>     info = (union pxe_cached_info
>  *)phys_to_user(__from_data16(&pxe_cached_dhcpack_data));
>  info->dhcphdr.ciaddr= inet_addr("192.168.117.144");  //To set a static IP
>  address for my bootloader parent = netdev_settings( netdev );
>     dhcppkt_init( &pxe_cached_dhcpack,&info->dhcphdr, sizeof(*info));
>    register_settings( &pxe_cached_dhcpack.settings, parent );
> ////////////////////////////////////END////////////////////////////////////
> /////////////////////
> 
> However, when I call route command in gPXE shell,  it seems that the IP
>  address for the netdev still remains unchanged. see the picture:

There is a much, much, much easier way to do this!  Use the "set" command:

  set net0/ip 192.168.117.144

You can find documentation at http://ipxe.org/cmd/set - including an example of 
configuring a static IP address.

You can embed a script to do this.  Create a file "static.ipxe" containing 
something like:

  #!ipxe
  set net0/ip 192.168.117.144
  autoboot

and build iPXE using

  make bin/undionly.kpxe EMBEDDED_IMAGE=static.ipxe

Scripts (and embedded scripts) are documented at http://ipxe.org/scripting

(Redirected to the ipxe-devel mailing list; please use iPXE instead of gPXE, 
since iPXE is actively maintained.)

Michael



More information about the ipxe-devel mailing list