Debian – Installing Debian with PXE and preseed and dynamic IP address, but configure it finally with static IP address

automated-installautomationdebianpreseedpxe-boot

I had setup an infrastructure for automatic installation of Debian based machines. It uses PXE booting with DHCP and TFTP servers, and preseed to automate the OS installation.

What I want is:

  • use DHCP for PXE boot
  • use DHCP for Debian installer: it needs an IP address to access the preseed file and I don't want to enter it manually
  • use a static IP address on the final installed OS. This IP address will be specified in the preseed file.

But I can't find how to do that, even know if it's possible.

My current preseed file looks like this (network parameters only):

# netcfg will choose an interface that has link if possible. This makes it
# skip displaying a list if there is more than one interface.
d-i netcfg/choose_interface select auto

# If you prefer to configure the network manually, uncomment this line and
# the static network configuration below.
d-i netcfg/disable_autoconfig boolean true

# If you want the preconfiguration file to work on systems both with and
# without a dhcp server, uncomment these lines and the static network
# configuration below.
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Configure network manually

# Static network configuration.
#
# IPv4 example
d-i netcfg/get_ipaddress string 192.168.1.10
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 192.168.1.254
d-i netcfg/get_nameservers string 192.168.1.1
d-i netcfg/confirm_static boolean true

(I also tested commenting the line d-i netcfg/disable_autoconfig boolean true with the same result).

Do anyone knows how to do that?

Thanks.

ps: It's Debian Wheezy

Best Answer

Use in preseed options of your's own command execution after installation:

d-i preseed/late_command string wget http://your-web_or_ftp/unattend/dopostinstall.sh -O /tmp/dopostinstall.sh;  chmod +x /tmp/dopostinstall.sh; /tmp/dopostinstall.sh

The dopostinstall.sh something like that:

#!/bin/ash

echo -e "auto lo eth0 \niface lo inet loopback\n\niface eth0 inet static\n\t address 192.168.1.10\n\t netmask 255.255.255.0\n\t gateway 192.168.1.254\n\t dns-nameservers 192.168.1.1" > /target/etc/network/interfaces