Build a distributed environment with Raspberry PI series (Part 3: Install and configure dnsmasq)

Introduction

  1. Construction of distributed environment with Raspberry PI series (Part 1: Summary of availability of diskless client by model)
  2. Building a distributed environment with Raspberry PI series (Part 2: Analysis of PiServer and design of alternative system)
  3. Building a distributed environment with Raspberry PI series (Part 3: Installing and setting dnsmasq)
  4. Building a distributed environment with Raspberry PI series (Part 4: Build NFS server and import OS for clients)
  5. Building a distributed environment with the Raspberry PI series (Part 5: Customizing the Raspberry PI OS for cluster nodes (1))
  6. Building a distributed environment with Raspberry PI series (Part 6: Customization of Raspberry PI OS for cluster nodes (2))
  7. Building a distributed environment with Raspberry PI series (7: tftp route setting and startup test for each Raspberry Pi)

This article is a continuation of Part 2. This time, when building a PiServer alternative system, it will be the part of building a PXE server with dnsmasq, which is the key.

1. First, prepare a surplus machine with a UNIX-based OS installed.

It's a selfish guess, but if you have a lot of Raspberry Pis, I think that the surplus machines that you can use freely are lying somewhere at home or at work / university. And I think it's a good idea to install a UNIX-like OS that you're used to on a surplus machine, so I won't describe any how-tos about installing the OS itself.

Precautions when installing the OS

Hereafter, we will assume that the host name of the PXE server is "hogeHost" and the IP is 192.168.172.16/24.

# /etc/hosts(Example)
#192 fixed IP for PXE server.168.172.16
#When the host name is hogeHost

127.0.0.1 localhost
192.168.172.16 hogeHost

[^ 20200608 Added]: Added after receiving a comment from @kakinaguru_zo (2020/06/08) [^ 20200608 Added 2]: 2020/06/08 Added

2. Install the dnsmasq package

Each distribution has a different way to install the package, but if you have a UNIX-like OS that uses a package system, you should definitely distribute the binary package on the official repository, so you don't have to compile it yourself. [^ GENTOO]. I will also omit how to install the package for each distribution. Install dnsmasq using the commands you normally use, such as apt-get, pacman, or dnf. If you forgot the command, refer to the link below. Reference: ArchLinux Pacman Comparison Table

[^ GENTOO]: Except for Gentoo, which requires you to compile any software yourself (bitter smile)

3. dnsmasq settings

Normally I can write all the settings to the /etc/dnsmasq.conf file, so I take the style of writing everything to the dnsmasq.conf file. Depending on the distribution, in addition to /etc/dnsmasq.conf, there is also an environment where there is a subdirectory /etc/dnsmasq.d/ and all files under this directory are included, so in this case everyone's preference Please save the setting file separately with. [^ DIV_EX]

The dnsmasq.conf file described in this article is a modified version of the one spit out by PiServer.

[^ DIV_EX]: Example: Divide files by DNS, DHCP, tftp functions, divide by MAC address of Raspberry Pi, etc.

3.1. Setting (disable) DNS function

The sample (default) dnsmasq.conf file is commented out with a line to open the DNS service on port 5353. However, if you run dnsmasq in this state, it will open port 53, which is used by normal DNS services, so do not open it intentionally. Keep the comment line and add port = 0 line

/etc/dnsmasq.conf(part)


・ ・ ・
#port=5353
#Disable DNS(Add line)
port=0

#The following line is port=If 0 is specified, it is a line that is not originally needed,
#In case the DNS service starts by mistake
#Specify DNS as a local service
local-service

#As a tag name when setting DHCP related items
#Since you will be using your own host name, your own host name in advance/Register the address
# [Format] host-record=hostname,Host IP
host-record=hogeHost,192.168.172.16
・ ・ ・

3.2. Setting the tftp function

By default, the tftp server feature is disabled, so enable it first. It also enables the ability to identify clients by MAC address and change the download destination tftp route.

/etc/dnsmasq.conf(part)


#Enable tftp server function
enable-tftp

#The location of the reference directory for files provided by tftp(as you like)
#Under this directory, MAC/You will create a tftproot directory for each IP address
# (It's actually a symbolic link)
tftp-root=/srv/tftp

#Enable the ability to automatically sort the tftproot directory by MAC address.
#By the time Raspberry Pi accesses the tftp server, it should already have an IP.
#In an environment where a fixed IP can be assigned, the tftproot directory can be automatically assigned to each IP address.
#In that case, after equal"ip"To
#The environment we are currently building/etc/I plan to use a fixed IP for management by hosts.
#I dare to use mac to maintain compatibility with PiServer functions.
tftp-unique-root=mac

Also, create a base directory to store the tftp root directory to be shown to each Raspberry Pi specified on the tftp-root line.

# mkdir /srv/tftp

3.3. DHCP function settings

By default, the DHCP server function is disabled, so enable it. However, please note that the description method of the DHCP function to be set from now on will change depending on whether or not another DHCP server exists in the environment (subnet) you are currently using. By the way, in my example, it is the one who has an existing DHCP server.

/etc/dnsmasq.conf(part)


# dhcp-The DHCP function will not be enabled without the range line, so use either line according to your environment.

#If there are no other DHCP servers in the subnet
# -------------------
#It is necessary to specify the range of IP given to the client, netmask, etc.
# [Format] dhcp-range=tag:hostname,Start IP,End IP(,Net mask(,Broadcast address(,Lease time)))

#dhcp-range=tag:hogeHost,192.168.172.32,192.168.63,255.255.255.0

#You should also specify the default gateway
# [Format] dhcp-option=tag:hostname,option:router,Gateway address

#dhcp-option=tag:hogeHost,option:router,192.168.172.254

#If there is another DHCP server in the subnet that will give you an IP
# ------------------
#Act as a DHCP Proxy. In the case of Proxy, the format is changed because the range given is only the IP that you own.
# [Format] dhcp-range=tag:hostname,Host IP,proxy
dhcp-range=tag:hogeHost,192.168.172.16,proxy

#It seems that it is better to delay the DHCP response by 1 second to prevent boot failure due to a bug in client-side PXE
dhcp-reply-delay=2

#Log about DHCP
log-dhcp

3.4. PXE function settings

The person who enables the tftp and dhcp functions is the person who wants the PXE function, so there is a dedicated setting item for such a person. The setting for Raspberry Pi is a "magic" state that requires only one line, but if you want to use the PXE function on a general computer other than Raspberry Pi, please check the details based on the sample file. Note that the dnsmasq PXE server, which does not have this one line, will be ignored by the Raspberry Pi bootloader (bootcode.bin), so it is a required item.

# /etc/dnsmasq.conf(part)
#Raspberry bootcode.One line required to make bin recognize as a tftp server
# ("Raspberry Pi Boot"Character string cannot be modified)
# pxe-service=tag:PXE server name,0,"Raspberry Pi Boot"
pxe-service=tag:hogeHost,0,"Raspberry Pi Boot"

3.5. DHCP settings for each client and provisional tftp root directory creation

From here, you will be adding one entry for each Raspberry Pi. Find out the MAC address of your Raspberry Pi and add entries line by line.

/etc/dnqmasq.conf(part,MAC address is an appropriate value)



#Settings when there is no other DHCP server
# (Allocate a fixed IP to each MAC address)
# --------------
# [Format] dhcp-host=MAC address of Raspberry Pi,set:hostname,IP address to give,infinite
# Raspi2
#dhcp-host=b8:27:eb:GG:HH:II,set:hogeHost,192.168.172.32,infinite
# Raspi3
#dhcp-host=b8:27:eb:XX:YY:ZZ,set:hogeHost,192.168.172.33,infinite
# Raspi4
#dhcp-host=dc:a6:32:PP:QQ:RR,set:hogeHost,192.168.172.34,infinite

#Settings for Proxy DHCP settings
#  -----
# [Format] dhcp-host=MAC address of Raspberry Pi,set:hostname

# Raspi2
dhcp-host=b8:27:eb:GG:HH:II,set:hogeHost
# Raspi3
dhcp-host=b8:27:eb:XX:YY:ZZ,set:hogeHost
# Raspi4
dhcp-host=dc:a6:32:PP:QQ:RR,set:hogeHost

After adding entries, create a subdirectory with a name that changes the colon of the MAC address to a hyphen under the reference directory specified when setting tftp related items so that an error does not occur when dnsmasq is test-started. To do. (In production this will be a symbolic link to the / boot folder of the client OS)

# mkdir /srv/tftp/b8-27-eb-GG-HH-II
# mkdir /srv/tftp/b8-27-eb-XX-YY-ZZ
# mkdir /srv/tftp/dc-a6-32-PP-QQ-RR

This completes the dnsmasq settings.

4. Grammar check in dnsmasq.conf

Perform a syntax check on the completed dnsmasq.conf

# sudo dnsmasq --test      
dnsmasq: syntax check OK.
#

That's all for this time. Next time will be the construction of NFS server and the manual import of OS for clients.

Recommended Posts

Build a distributed environment with Raspberry PI series (Part 3: Install and configure dnsmasq)
Building a distributed environment with the Raspberry PI series (Part 2: PiServer analysis and alternative system design)
Build a Tensorflow environment with Raspberry Pi [2020]
Distributed environment construction with Raspberry PI series (Part 4: NFS server construction and client OS import)
Building a distributed environment with the Raspberry PI series (Part 1: Summary of availability of diskless clients by model)
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Distributed environment construction with Raspberry PI series (7: tftp route setting and startup test for each Raspberry Pi)
Build a Django environment on Raspberry Pi (MySQL)
Build a virtual environment with pyenv and venv
Build a Python development environment on Raspberry Pi
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction
Cross-compiling Raspberry Pi and building a remote debugging development environment with VS Code
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server ―― 1. Apache introduction
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a numerical calculation environment with pyenv and miniconda3
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a web server --3. Use MySQL
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
Create a web surveillance camera with Raspberry Pi and OpenCV
Create a partition and then install the Raspberry Pi OS
How to build a python2.7 series development environment with Vagrant
Using a webcam with Raspberry Pi
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
Make a Kanji display compass with Raspberry Pi and Sense Hat
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Pet monitoring with Rekognition and Raspberry pi
Easily build a development environment with Laragon
How about creating a virtual environment with Anaconda and doing pip install?
Build a Fast API environment with docker-compose
Make a wireless LAN Ethernet converter and simple router with Raspberry Pi
[Linux] Build a jenkins environment with Docker
Make a wash-drying timer with a Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Build a python virtual environment with pyenv
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Build a modern Python environment with Neovim
Build Linux on a Windows environment. Steps to install Laradock and migrate
[Linux] Build a Docker environment with Amazon Linux 2
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
Build a data analysis environment that links GitHub authentication and Django with JupyterHub
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Build a C language development environment with a container
Build a WardPress environment on AWS with pulumi
Building a python environment with virtualenv and direnv
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Build a Django environment with Vagrant in 5 minutes
MQTT RC car with Arduino and Raspberry Pi
[Memo] Build a virtual environment with Pyenv + anaconda
Build a Django development environment with Doker Toolbox
Build a Python environment with OSX El capitan
Get temperature and humidity with DHT11 and Raspberry Pi
Quickly build a Python Django environment with IntelliJ