Benutzer-Werkzeuge

Webseiten-Werkzeuge


en:ausbildung:der_raspberry_pi-lehrgang_v4

The RaspberryPi course

Introduction

About the Raspberry Pi

The Raspberry Pi is a single-board computer developed by the British Raspberry Pi Foundation.
The computer contains a single-chip system from Broadcom with an ARM microprocessor; the footprint of the board is roughly the size of a credit card.
The Raspberry Pi came onto the market at the beginning of 2012; its great market success is partly seen as a revival of the home computer for programming and experimentation, which had become largely irrelevant until then.
The computer, which has a very simple design compared to conventional personal computers, was developed by the foundation with the aim of making it easier for young people to acquire programming and hardware skills.
The sales price was set correspondingly low, at around USD 5 to 35 depending on the model.
By October 2015, more than seven million devices had been sold.
The development of the Raspberry Pi has received several awards and honours.
There is a wide range of accessories and software for numerous areas of application.
For example, it is widely used as a media centre, as the computer can decode video data with full HD resolution (1080p) and output it via the HDMI interface.
Customised Linux distributions with a graphical user interface are mainly used as the operating system; Windows 10 is also available for the latest model in a special Internet-of-Things version without a graphical user interface.
The boot process takes place from a removable SD memory card as the internal boot medium.
There is no native interface for hard disk drives; additional mass storage can be connected via a USB interface, e.g. external hard disks/SSDs or USB memory sticks.

Hardware Raspberry PI 4

- Chipset Broadcom BCM2711 64-bit SoC @ 1.5GHz
- Quad-Core Cortex-A72 (ARM v8)
- 2.4 GHz and 5.0 GHz IEEE 802.11b/g/n/ac Wireless LAN
- Bluetooth 5.0 (Classic & Low Energy)
- Dual-core co-processor Videocore IV® Multimedia
- 1 GB LPDDR2 memory
- Supports all current ARM GNU/Linux distributions and Windows 10 IoT
- 5 V- /3 A via the USB-C socket or the GPIO connector
- 1 x Gigabit Ethernet connection
- 2 x Micro HDMI ports
- 2 x USB 3.0 ports
- 2 x USB 2.0 ports
- 40 GPIO pins
- Chip antenna
- 2-lane MIPI DSI display port
- 2-lane MIPI CSI camera port
- Slot for microSD card
- Dimensions: 85 x 56 x 17 mm

Important Always exercise caution when working with the Raspberry, as the connectors are attached directly to the PCB and can therefore break or bend.
It is also important to use ESD tape when working on the board or with electronic hardware.

The Raspberry PI set from RAFISA

- Housing any colour
- Raspberry PI 4
- power supply unit
- Micro SD card 16 GB
- USB adapter for Micro SD card
or
- PCMCIA adapter for Micro SD card
- 1 Micro HDMI cable
- Mouse
- Keyboard

Opening the housing

Opening the case can be difficult, as different cases exist and the locking mechanism is always slightly different. In our case, the lock is located next to the power cable connection in the form of a screw. If you want to open the housing, carefully unscrew the housing, remove the screw and carefully pull the two parts apart.

Basic installation Raspberry Pi

Preparation

You need the following programme to write an image to the MicroSD card:
balenaEtcher which you can find under the following link.
https://etcher.balena.io/
We also need an operating system which we want to install on the MicroSD card. There are a variety of images which we can preferably download directly from the Raspberry PI website.
https://dietpi.com/ and select the download next to Download Image under Downloads Raspberry Pi 2/3/4. In the downloads there should now be a file called DietPi_RPi-ARMv8-Bookworm.img.xz.
In the first example, we install the Debian-based Linux with the name Dietpi, which is only available in one version, without a graphical user interface. However, we will install a corresponding user interface.

We now take the MicroSD card out of the Raspberry PI and get an SD card reader to help us. Insert the MicroSD card into the corresponding SD card and make sure that the small switch on the side of the card is not set to Lock and then insert this card into the card reader. Connect the card reader to the PC and then open balenaEtcher without clicking on anything else. Take Flash from file, select the .img.xz you just downloaded and then make sure you select the correct location on the card. Then just click on Flash and wait until it is finished, important: You will get two pop-ups, one to configure the storage space and one to configure a drive. Please click both away with X and the second pop-up will show a message later, which is unimportant for us and we can safely click away with X.

First steps after the installation

The image is now written and we install the MicroSD card in the corresponding slot on the lower side of the housing.
We also connect a mouse, a keyboard and the HDMI cable. Of course, we also need a network cable to connect to the Internet.
Once everything is connected, we plug in the Raspberry PI's power supply.

If we have done everything correctly, the Raspberry PI will now start up.

User
The user which is automatically created under Dietpi is called:
Username: root
Password: dietpi
Which will be changed in the next steps.

Getting started

(Attention, the order changes again and again but all steps are documented)

We start the system and the following screen should appear.

We press Enter and enter the default login data. This screen should then appear.

Here we select OK and enter a new password for the root user:
Password1
We have to enter this twice to ensure that it is not misspelled.
Afterwards this window appears which you can confirm with OK and then enter Password1 twice again.

This is followed by the question about a serial interface, which we confirm with „Cancel“.

Now we automatically come to the core of Dietpi, namely the configuration window.

So that we can set the correct Swiss keyboard, we first select the DietPi-Config button.
The following window appears in which we select item 5 and confirm with Enter.

Now we select Locale and there C.UTF-8 and confirm this with OK.

We then select the time zone and confirm with Enter.
We then select Europe and confirm again with Enter.

Then select Zurich and press Enter again to confirm.

Then select Keyboard and confirm with Enter.
The following window then appears, which we confirm with OK.

Now select Generic 105-key PC (intl.) and confirm with Enter.

In the following window, select Other and confirm with Enter.

Now select German (Switzerland) and confirm with ENTER.

In the following window, select German (Switzerland) and confirm with Enter.

Now select The default for the keyboard layout and confirm with ENTER.

Then select No compose key and confirm with ENTER.

In the basic configuration window, select „Exit“ .

Then confirm with „OK“ and return to the first window where we now select software.


Here we select the following points and confirm them with the space bar so that they receive an asterisk.





At the bottom we select „OK“ and with a second „OK“ we return to the start page, where we now switch to the „Install“ grid and confirm this with „OK“. We then confirm the installation again with „OK“ and the installation begins.
installation_25.jpg
At the end of the installation, the following window appears, in which we confirm the selected point with „OK“.

With the command

sudo reboot

command to restart the Raspberry PI.
We can then use the command

startx

command to start the graphical user interface.

Update of a Debian Linux

Now all so-called package lists are downloaded and updated.
With the command:

sudo apt update


All packages for which an update is available are installed. A list of the packages appears and they are installed with „y“ for yes.
If a newer version of the kernel and firmware is available, it can be installed with :

sudo apt upgrade


Install. There may be problems here if the MicroSD card is too small. Therefore, at the end of the installation, always use the command

sudo apt clean


command at the end of the installation to delete the downloaded packages and free up storage space.

Assign a fixed IP address

We give our DietPi a fixed IP address. To do this, we use the command

sudo dietpi-config

to open the configuration menu and select item 7 (Networkoptions Options: Adapters).

Then select the item Ethernet.

Then we change the DHCP item

The following window appears.

The following entries must be made for your project.
Static IP: 172.16.51.2
Static Mask 255.255.255.0
Static gateway 172.16.51.1
Static DNS 172.16.51.2 9.9.9.9
And confirm the selection with Apply : Save all changes and restart networking
The following window appears, which we confirm with „skip“.
We can now save the entries that have been made with the command

sudo nano /etc/network/interfaces

check

Remote Desktop

This is very important, as Raspis are often installed without a mouse and keyboard and are only maintained or configured using SSH or Remote Desktop.
Take, for example, a surveillance camera mounted on the front of a building. It would be quite conspicuous if a screen, mouse and keyboard were also installed there.

With a graphical user interface

On a Linux computer

Step 1
We install xrdp using the APT package manager. This is a free implementation of the Remote Desktop Protocol for Linux.

sudo apt install xrdp


Step 2
We can now customise some xrdp settings. The files of interest for customising would be /etc/xrdp/xrdp.ini and /etc/xrdp/sesman.ini, but this is not normally necessary.

Step 3

(Alternative to Windows)

Now we need to install the appropriate remote desktop client software on our client, unless we are using Windows, as a client is already pre-installed under Windows, which can be found by searching for Remote Desktop Connection. For Linux there is Rdesktop and for Mac there is the Microsoft Remote Desktop application in the App Store.
Now we can start from a Linux PC with the command:

rdesktop 172.16.51.2

(example IP!!!! Use the IP of your Raspi)
Of course, there are also various parameters for this command that we can set when entering it.

On a Windows computer

First create a user for the remote desktop with :

sudo useradd -m -s /bin/bash -g users -G sudo crt


Then enter this command to set the password (Password1):

sudo passwd crt


Use the Remote Desktop programme from Windows (don't worry, you can simply ignore the certificate and continue clicking that it starts the Remote Desktop, we don't have a certificate but it works without one in this context):

Log in with the user crt you just created and your password and you should be able to see the Remote Desktop.

(Alternative) Without graphical user interface

On a Linux computer

As we have activated the Open SSH server in the settings, we can now access our Raspi via the console and work with it.
Under Linux, we use the command:

ssh pi@172.16.51.2

(example IP!!!! Use the IP of your Raspi)
ssh is the command, while pi stands for the user. The II address identifies your Raspi and can be read out with the command ipconfig -a.

On a Windows computer

Use the Putty programme:

Attention: Reset Raspi without graphical user interface

Installing the DHCP server

To install the DHCP server, select the following package from Debian Natty onwards:

sudo apt install isc-dhcp-server


(Don't worry that there is so much red, it just started automatically and we haven't done any configuration yet)

After the package has been installed, we still have to adjust some files and of course plan our DHCP server.
In this example the nano editor is used. If this is not yet installed, we can do this with the command

sudo apt install nano

command.

Configuration

Example configuration:
- The rogue DHCP server should not allow any other DHCP servers in the network when activated
- The server serves the network 172.16.51.0
- The clients are assigned IP addresses between 172.16.51.110 and 172.16.51.120
- The transition (gateway or router) to another network has the IP address 172.16.51.1
- The name server has the IP address 172.16.51.2 (is only integrated during DNS configuration) and 8.8.8.8
- The server receives the fixed IP 172.16.51.2
- The netmask is 255.255.255.0
- Broadcast is 172.16.51.255
- The domain is called „raspi.home“
- The lease time is set to 10 minutes
- The maximum lease time is set to 2 hours
- The Eth0 interface is defined as the default
- A specific client is always assigned the same IP address based on its hardware (MAC) address.

Setting up the DHCP server

We open the file /etc/default/isc-dhcp-server

sudo nano /etc/default/isc-dhcp-server



And change the entry as follows:

# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid

# Additional options to start dhcpd with.
#       Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="eth0"
INTERFACESv6=""



We copy the file dhcpd.conf.

sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd2.conf



We open the file dhcpd.conf in the veryeichniss /etc/dhcp

sudo nano /etc/dhcp/dhcpd.conf



We delete the entire contents of the file and then insert the following lines:

subnet 172.16.51.0 netmask 255.255.255.0 {
range 172.16.51.110 172.16.51.120;
interface eth0;
option domain-name-servers 172.16.51.2, 9.9.9.9;
option domain-name "rafisa.home";
option routers 172.16.51.1;
option broadcast-address 172.16.51.255;
default-lease-time 600;
max-lease-time 7200;}


Once the configuration is complete, we can restart the server with the following commands or query the status.

sudo systemctl restart isc-dhcp-server



sudo systemctl status isc-dhcp-server


Installation DNS server

Installation

First, BIND (currently version 9) must be installed via the APT package management system using the following terminal command.

sudo apt install bind9 bind9utils dnsutils



Once the installation is complete, we can test the DNS server. With the command

dig @127.0.0.1 www.google.de



a similar output to the one below should appear.

«» DiG 9.16.22-Debian «» @127.0.0.1 www.google.de
; (1 server found)
;; global options: +cmd
;; Got answer:
;; →>HEADER«- opcode: QUERY, status: SERVFAIL, id: 59482
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: e31452e9a2ec22550100000062161feaf2121d8249561dd2 (good)
;; QUESTION SECTION:
;www.google.de. IN A

;; Query time: 404 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Feb 23 11:52:10 GMT 2022
;; MSG SIZE rcvd: 70

Beispiel-Konfiguration

Kommen wir nur zur eigentlichen Einrichtung von eigenen Zonen und der Konfiguration von BIND welches sich in der Datei /etc/bind/named.conf.local befindet.

Für ein einfaches Beispiel gehen wir von folgender lokalen Netzwerk-Topologie aus.

• Raspberry: 172.16.51.2
• Netzwerk: 172.16.51.0/24
• Subnetzmaske: 255.255.255.0
• Broadcast-Adresse: 172.16.51.255
• Gateways/Router: 172.16.51.1
• Interner Server: 172.16.51.5
• Raspberry (DNS-Server): 172.16.51.2 9.9.9.9
• Hostname: raspi
DNS-Zone: raspi.home
Forward- und Reverse-Lookup Zonen anlegen
Domains die wir im DNS-Server konfigurieren wollen, werden eigene Zonen angelegt.
Für jede Domain sollte es normalerweise zwei Zonen-Dateien geben. Jeweils eine Zonen-Datei für den Forward- und den Reverse-Lookup.

Zuerst muss in der Datei „/etc/bind/named.conf.local“ die Konfiguration für diese beiden Dateien unserer Beispiel-Zone „raspi.home“ eingetragen werden.
Um die Datei zu bearbeiten, muss diese in einem Editor (z. B. „nano“) geöffnet werden.

Natürlich machen wir zuerst ein Backup der Datei.

sudo cp /etc/bind/named.conf.local /etc/bind/named2.conf.local



We then open the file and enter our configuration.

sudo nano /etc/bind/named.conf.local



We enter the following configuration

// ----------------------- Zones -----------------------
// Forward-Lookup
zone "raspi.home" {
type master;
file "/etc/bind/zones/raspi.home";
};
// Reverse-Lookup
zone "51.16.172.in-addr.arpa" {
type master;
file "/etc/bind/zones/db.51.16.172.inv";
};
// ----------------------- Zones -----------------------


Firstly, only the zones for BIND are made known here. The actual configuration of the logical structure is then entered in the files specified under „file“.

For a better overview, we will create a separate „zones“ folder and save the files in it.

sudo mkdir /etc/bind/zones



The „raspi.home.zone“ file does not need to be created and can be opened directly with the following command.

sudo nano /etc/bind/zones/raspi.home



The following content must be entered and saved in the file.

;; BIND forward data file for zone raspi.home
;;

$TTL          86400   ; time-to-live - 24 hours could have been written as 24h or 1d

@             IN      SOA         ns1.raspi.home. mail.raspi.home. (
                                             2015061201       ; Serial - (NOTE: Needs to increment every time you restart BIND)
                                                 604800       ; Refresh
                                                  86400       ; Retry
                                                2419200       ; Expire
                                                 604800 )     ; Default TTL

              IN            NS           ns1.raspi.home.      ; nameserver
              IN            A            172.16.51.2         ; loop-back address

ns1           IN            A            172.16.51.2
raspi.home.   IN            A            172.16.51.2
server        IN            TXT          "Interner Server"

www           IN            CNAME        raspi.home.



Reverse lookup
Another zone file „db.20.168.192.inv“ is created for the reverse lookup.

sudo nano /etc/bind/zones/db.51.16.172.inv



And fill in the following data

;; BIND reverse data file for zone db. 51.16.172.inv
;;

$TTL           86400         ; time-to-live - 24 hours could have been written as 24h or 1d

@              IN            SOA      ns1.raspi.home. mail.raspi.home. (
                                           2015061101          ; Serial  - (NOTE: Needs to increment every time you restart BIND)
                                               604800          ; Refresh
                                                86400          ; Retry
                                              2419200          ; Expire
                                               604800 )        ; Default TTL

               IN            NS       ns1.raspi.home.          ; nameserver

2              IN            PTR      ns1.raspi.home.          ; #1 172.16.51.2
10             IN            PTR      server.raspi.home.       ; #2 172.16.51.2


Start server

sudo service bind9 restart



or

sudo service bind9 stop


sudo service bind9 start



We can now view the status of the server with the command. If all is well, no red lines should appear.

sudo service bind9 status



If something has gone wrong, it is advisable to view the messages in the log file „/var/log/syslog“.
Testing the DNS server with DNS queries

Enter the following command in the CMD prompt:

nslookup


Then enter www.google.ch, for example. If everything runs correctly, the DNS server should respond with the IP address of Google.ch.

Installing the Apache2 web server

We will install a web server next. A web server is a unit of software and hardware that uses HTTP and other protocols to respond to customer requests that come in over the Internet, meaning that it simply serves web pages and such.

First, of course, we need to download it, so enter

sudo apt install apache2

for this. Next you do

sudo systemctl status apache2

to see if the web server is running.
Now do

sudo systemctl enable apache2

to make sure that it starts with the reboot.
Test whether the server is fully functional by opening a new tab in an Internet browser and entering http:(SlashSlash)172.16.51.2 and checking whether the Apache welcome page boots.

Installation print server

Installation

To install the CUPS print server, we enter the following command in the console if we have not already made the selection at the beginning:

sudo apt install cups cups-client cups-bsd



In addition, we now need the root account so that we can then access Cups via the Webgui.
We enter the following command in the terminal:

sudo su


Cups requires some additional packages such as drivers for the printers and others, which is why the installation will take a moment.
Once Cups is installed, access to the web interface only works on the local host. We have to edit this configuration in the cupsd.conf file.

sudo nano /etc/cups/cupsd.conf


The following parameters are entered here:

# Listen for connections
Listen Port 631\\
Listen 172.16.51.2:631\\
Listen /var/run/cups/cups.sock\\

We then execute the following two commands so that we can configure a printer.

sudo cupsctl --remote-any


sudo /etc/init.d/cups restart


Once the installation is complete, we can immediately open our web browser and enter the following address:

http://localhost:631/admin

for the local PC or

http://172.16.51.2:631/admin

if we want to access from another PC.

Log in with root and dietpi.

We need the following information to install a printer:
IP address (172.16.51.150 in our case and the exact name of the device in our case a Brother-HL-5270DN. Under Linux as well as under Windows, the operating system requires a driver file so that the printer can be addressed.
Most drivers can be found on the page https://www.openprinting.org/drivers or directly from the manufacturer. The drivers are called ppd under Linux.
Under this link we can find the driver for our printer.
https://www.openprinting.org/printer/Brother/Brother-HL-5270DN .
Save the ppd file on your Raspi.

Check whether the printer is connected to the switch via an Ethernet cable and select the Add printer button.

The following picture appears.

Here we select the LPD/LPR host or printer protocol and confirm with next.
Now we enter the IP address of our printer with the prefix socket:(SlashSlash)172.16.51.150 and confirm with next.

The following screen appears and we can now enter the details such as location, device etc. As this is a server, we release the printer in the network.
Confirm with continue.

The following menu appears (don't be surprised, it doesn't say the same thing but it's still the same principle).

If it is an older printer, it may already be installed on the system and we will find it in the menu. Unfortunately, our printer is not yet installed, which is why we click on the „Select file“ button and enter our PPD file.

We then select the „Add printer“ button.
A window then appears in which we can set all the printer options.

Once the settings are complete, we now switch to the „Printer“ grid where we find our new printer.

If we click on the „Maintenance“ checkbox, we can select „Print test page“ from the menu and our first page will be printed.




en/ausbildung/der_raspberry_pi-lehrgang_v4.txt · Zuletzt geändert: 2024/09/17 09:35 von schnuppern