This tutorial will show you how to create a PXE server and use it to install Ubuntu over a network. This is ideal if you want to install Ubuntu on a large number of computers at once.
Table of Contents
Introduction
In this guide, I will show you how to create a PXE server on Ubuntu 18.04 using Dnsmasq. The PXE server will hand out IP addresses using DHCP and will serve the Ubuntu netboot files over TFTP.
We will also configure a client to PXE boot and install Ubuntu over the network using the minimal amount of packages needed to start the system.
After installing Ubuntu on the client machine, any future packages will be downloaded from the internet.
Prerequisites
Before we begin, you will need toinstall Ubuntu Server 18.04,configure it with a static IPandinstall Dnsmasq. You will also need a client machine with PXE boot enabled in the BIOS.
If you don’t have the physical hardware required to perform the steps below, you can use a desktop virtualization program such asVMware Workstation*orVMware Fusion*to follow along.
In this tutorial, I’m using a MacBook Pro withVMware Fusion 11.5*to run two virtual machines, one for the PXE server, and the other as the client, which will have Ubuntu installed over the network.
Let’s begin.
Step 1: Install and Configure Dnsmasq
In this tutorial, I will use the following network settings, but you’ll want to change them to suit your environment:
-----------------------------------PXE Server-----------------------------------IP Address: 10.1.1.250DHCP Range: 10.1.1.11 to 10.1.1.249Gateway: 10.1.1.2Domain: example.labhostname: dnsmasq
Follow the steps inthis tutorial. to install Dnsmasq on Ubuntu. Once finished, you should have adnsmasq.conf
file that looks like the following:Advertisem*nts
# Global settingsdomain-neededbogus-privno-resolvexpand-hostsfilterwin2k# Upstream nameserversserver=8.8.4.4server=8.8.8.8# domain namedomain=example.lablocal=/example.lab/listen-address=127.0.0.1listen-address=10.1.1.250# DHCP optionsdhcp-range=10.1.1.10,10.1.1.249,12hdhcp-lease-max=100dhcp-option=option:router,10.1.1.2dhcp-option=option:dns-server,10.1.1.250dhcp-option=option:netmask,255.255.255.0
Modify the network settings in the file to suit your environment.
Note:Since we are using the DHCP server built-in to Dnsmasq, you may need to disable any other DHCP server you have on your network.
Step 2: Enable TFTP Server and Download Ubuntu Netboot files
Add the following options to the file to enable the TFTP server:
enable-tftptftp-root=/srv/tftp
Download and extract the Ubuntu files to the tftp root directory by running the following commands:
cd /tmpwget http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/netboot.tar.gzsudo tar -xvzf netboot.tar.gz -C /srv/tftp/sudo chown -R nobody:nogroup /srv/tftp/
Step 3: Configure the DHCP Server to send the name of the boot image
Add the following option to thednsmasq.conf
file to send the name of the image to boot.
dhcp-boot=pxelinux.0
Determine the MAC address of your client machine that you want to install Ubuntu on.
If you’re following along using VMware Fusion, it can be found by clickingSettings, then on theNetwork Adapterand thenAdvanced Settings.
Now assuming your MAC address is00:50:56:39:87:7A
and you want to assign an IP address of10.1.1.21
, add the following to thednsmasq.conf
file:
dhcp-host=00:50:56:39:87:7A,10.1.1.21,ubuntu-net
Save the changes and restart dnsmasq with the following command to apply the changes:
sudo systemctl restart dnsmasq
Step 4: Power on Client and Test
Power on your client machine and it should boot using PXE. The DHCP server will assign it the fixed IP address specified in the previous step and then the client will download the Ubuntu boot image from the TFTP server.
The following screenshots show this in action on a VMware Fusion virtual machine.
Note:After clicking install, the screen will freeze for a minute as the files are transferred.
Now you can walk through the installation of Ubuntu as you would normally.
Conclusion
In this tutorial, we configured Dnsmasq on Ubuntu Server 18.04 to work as a DHCP, PXE and TFTP server. We setup a fixed IP for a client and tested booting the Ubuntu net installer over the network.
Next steps
After installing Ubuntu over the network, future packages will be downloaded from the internet. Depending on how many machines you have on the network, you might want to change it so that all files are downloaded over the local network. Another thing you might want to do, is use a Kickstart file to fully automate the installation.
David Miller
David Miller is a seasoned tech aficionado with a profound expertise in NGINX and Ubuntu. With a career spanning over a decade, David has honed his skills in optimizing web servers and enhancing server performance to perfection. His deep-rooted passion for open-source technologies has led him to become a go-to resource in the field. Whether it’s crafting intricate NGINX configurations or troubleshooting complex Ubuntu server issues, David’s problem-solving prowess shines through.