Benutzer-Werkzeuge

Webseiten-Werkzeuge


en:ausbildung:der_raspberry_pi-lehrgang_v3

Setting up and learning to use the Raspberry Pi

All steps contain links in the form of video guides and images that explain how to implement this step. During this task you will need a Raspberry Pi, a micro SD card, a Windows PC and a monitor with HDMI port, a MiniHDMI-HDMI cable, a USB C charger, two keyboards, two mice and a normal monitor. All these items should be available at your workplace or handed to you by a responsible trainer. Information on the Raspberry Pi device and the associated OS can be found at

https://www.raspberrypi.com/documentation/ respectively https://www.raspberrypi.com/software/

if sd card already has the RaspiOS → set up again

if empty → reset

Step 1: Get the Raspberry Pi ready to boot

To set up the Raspberry Pi, you need an SD card and an SD card reader to install the image. The following video shows how to load the ISO file (Raspberry Pi OS (64 bit)) onto the SD card using the Raspberry Pi Imager:

Now insert the SD card into the SD card slot on the Raspberry Pi.

Step 2: Booting the Raspberry Pi and initial setup

Now that you have equipped the Raspberry Pi with a bootable SD card, connect the mouse and keyboard to the device, using an unused USB A port for each.

Next, connect the Ethernet cable to the Raspberry Pi and the switch on the table.

Next, connect the Raspberry Pi and the screen using the mini HDMI-HDMI cable. Make sure that the screen is connected to the Storm and switched on. Once you have connected all the hardware to the main module, you can plug the USB C charger connected to the power supply into the Raspberry Pi and flip the toggle switch on the cable if necessary. You should now be able to see the Raspberry Pi start up on the screen. If this is not the case, check the HDMI plug. If this does not solve the problem, check the power plug on the socket side and on the Raspberry Pi side. These procedures should resolve the most common sources of error. If the problem persists, remove the power supply from the Raspberry Pi and remove the SD card. Now repeat the procedure described in step 1 above to write a new image to the SD card. Then repeat step 2. If the problem is still not resolved, please contact your instructor.

Now that the Raspberry Pi is starting, you have to wait for a moment, then a window should open. Here you select your „Country“ (Switzerland), your „Language“ (Swiss High German) and your „Timezone“ (Zurich9 and confirm your entry. Then enter your „username“ (sysadmin) and your „password“ (Password1) and confirm your entry. Under „Set Up Screen“ select „Reduce the Size of the desktop on this monitor“ and confirm your entry. Skip the WiFI network setup and confirm on the next screen that you want to update the software. Then restart the Raspberry Pi by selecting „Restart“.

Step 3: Updates and control centre

Now that you have set up the Raspberry Pi, you can update your programmes again. Open the console and type in

                     sudo apt-get update

Use this command to check whether your data packages require an update.

If the answer is yes, you can use the command

                     sudo apt-get upgrade

command to install the corresponding packages.

Assign a fixed IP address

We give our Pi a fixed IP address. To do this, we call up the network settings by left-clicking on the opposing arrows at the top right of the screen and select Advanced Options/Edit Connections. In the following window, double-click the Wired connection 1. Then switch to the tab IPv4 Settingstab, select the method Manual and enter the following information:

IPv4 Adress: 172.16.51.2
Netmask: 255.255.255.0
Gateway: 172.16.51.1
DNS Server: 8.8.4.4, 172.16.51.2, 8.8.8.8

Then confirm and restart the device.

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

Installing the desktop server on the RasbpberryPi

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

sudo apt-get install xrdp


Create remote desktop user

On the Raspberry Pi:
Create new rdp user :

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


sudo passwd crt


(set password)

Use remote desktop client on Windows PC

Use the Remote Desktop programme from Windows to connect to the RaspberryPi:


Or you can also use ssh:

ssh 172.16.51.2 -l crt

Installation DHCP server

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

sudo apt-get install isc-dhcp-server



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-get install nano

command.
The functions of the nano editor that are required for this guide are as follows: - „CTRL“ + „O“, followed by „Enter“ to save the changes made to a file -CTRL„ + „X“ to exit the editor Alternatively, a cheatsheet can be found under the following link „https://www.nano-editor.org/dist/latest/cheatsheet.html configuration
Example configuration
- The rogue DHCP server should be activated does not allow other DHCP servers in the network
- The server serves the network 172.16.51.0
- The clients are assigned IP addresses between 172.16.51.21 and 172.16.51.99
- 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 dhcpd.conf file in the /etc/dhcp directory

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.21 172.16.51.99;
interface eth0;
option domain-name-servers 172.16.51.2, 8.8.8.8;
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 start and stop the server with the following commands or query the status.

sudo /etc/init.d/isc-dhcp-server start



sudo /etc/init.d/isc-dhcp-server stop



sudo /etc/init.d/isc-dhcp-server status


Installation DNS server

Installation

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

sudo apt-get 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 8.8.8.8
• 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


Default server: ns1.raspi.home
Address: 172.16.51.2

The first DNS server in the system is now displayed. Then enter the IP address in the prompt and confirm with Enter:


The name must be resolved correctly.

Installing the 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-get 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:
User root
PWD Password1
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.
First we copy the file for security.

sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd2.conf


Then we edit the file.

sudo nano /etc/cups/cupsd.conf


The following parameters are entered at the bottom of the file:

# Only listen for connections from the local machine.\\
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:
for the local PC:

http://localhost:631/admin


or for another PC:

http://172.16.51.2:631/admin


The following interface appears.

In order to install a printer, we need the following information:
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.

Now switch to the Administration grid on the CUPS start page 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: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 enable the printer in the network and also activate colour management.
Confirm with continue.

The following menu appears.

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.

We leave most of the settings as they are. We only set the following point under the „General“ grid and confirm with the „Set default settings“ button.

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“ in the menu and our first page will be printed.

en/ausbildung/der_raspberry_pi-lehrgang_v3.txt · Zuletzt geändert: 2023/12/07 10:02 von e.rueefli