0% found this document useful (0 votes)
92 views14 pages

Install Rasperry Pi OS On Your SD Card With The Raspberry Pi Imager

This document provides instructions for setting up a Raspberry Pi as a wireless access point and standalone network using hostapd and dnsmasq. It describes downloading and installing the required software, configuring a static IP address, setting up the DHCP server with dnsmasq, configuring the wireless access point with hostapd, and enabling IP forwarding and masquerading for outbound traffic. Key steps include editing configuration files for dhcpcd, dnsmasq, and hostapd to set the wireless network name, password, IP range, and other settings and then restarting the relevant services.

Uploaded by

jessryl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views14 pages

Install Rasperry Pi OS On Your SD Card With The Raspberry Pi Imager

This document provides instructions for setting up a Raspberry Pi as a wireless access point and standalone network using hostapd and dnsmasq. It describes downloading and installing the required software, configuring a static IP address, setting up the DHCP server with dnsmasq, configuring the wireless access point with hostapd, and enabling IP forwarding and masquerading for outbound traffic. Key steps include editing configuration files for dhcpcd, dnsmasq, and hostapd to set the wireless network name, password, IP range, and other settings and then restarting the relevant services.

Uploaded by

jessryl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Install Rasperry Pi OS on your SD card with the Raspberry Pi Imager

Many vendors sell SD cards with a simple Rasperry Pi OS installer called NOOBS
preinstalled but you can really easily install Rasperry Pi OS yourself using a computer
that has an SD card port or using an SD card reader.

Using the Raspberry Pi Imager is the easiest way to install Rasperry Pi OS on your SD
card.

Note: More advanced users looking to install a particular operating system should use
this guide to installing operating system images.

Download and launch the Raspberry Pi Imager

o Visit the Raspberry Pi downloads page.


o Click on the link for the Raspberry Pi Imager that matches your operating system.

o When the download finishes, click on it to launch the installer.

Using the Raspberry Pi Imager


All data stored on the SD card will be overwritten during formatting and lost
permanently, so make sure that you back up the card or any files you want to keep
before running the installer.
When you launch the installer, your operating system may try to block you from running
it. For example, Windows may give the following message:

o If you get this, click on More info and then Run anyway.


o Insert your SD card into the computer or laptop’s SD card slot.
o In the Raspberry Pi Imager, select the OS that you want to install. The first
option, Rasperry Pi O, is the recommended OS.
o Select the SD card you would like to install it on. Different platforms will display the
drives in different ways. Mac OS, for example, will show you all drives including you
main operating sysytem.

Note: Make sure you are selcting the correct drive. The drives memory capacity can be
a useful indication of which drive you are selecting.
Once you have selected both the OS and the SD card, a new WRITE button will appear.
o Then simply click the WRITE button.
o Wait for the Raspberry Pi Imager to finsh writing.
o Once you get the following message, you can eject your SD card.

Apache installation
Before installing the server, make sure we have an up-to-date machine. To do
this we must have administrator rights, either because of the sudo command.

sudo apt update

sudo apt upgrade

sudo apt update

Once the Raspberry Pi is up to date, we will install the Apache server.

sudo apt install apache2

By the way, we’ll take advantage of it to give rights to the apache file that you can
easily manage your sites. To do this, run the following commands:
Let’s execute the following commands to install the required packages
first on your system. Then import packages signing key. After that
configure PPA for the PHP packages on your system.

sudo apt install ca-certificates apt-transport-https

wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -

echo "deb https://packages.sury.org/php/ stretch main" | sudo tee


/etc/apt/sources.list.d/php.list

Now use one of the below options to install PHP of your requirements.

Installing PHP 5.6


Execute the following commands for installing PHP 5.6 on your Debian
9 Stretch system.

sudo apt update

sudo apt install php5.6

Also install required php modules.

sudo apt install php5.6-cli php5.6-common php5.6-curl php5.6-mbstring


php5.6-mysql php5.6-xml
Install MySQL
Now we install the MySQL database engine by typing the following command:

sudo apt-get install mysql-server php-mysql -y


sudo service apache2 restart

Install phpMyAdmin
In order to manage our MySQL databases, it’s far easier to use phpMyAdmin so let’s go
ahead and install it by entering the following command, but note* you’ll be asked the
following questions during the installation process:

Automatic Configuration? – Choose [*]apache2 with your Spacebar, hit Tab then Enter
Configure database for phpmyadmin with dbconfig-common? – Choose Yes
phpMyAdmin application password – [enter new password] [confirm new password] this
is for logging into the phpMyAdmin web interface
Once you are ready, type the following command:

sudo apt-get install phpmyadmin –y

Now let’s check if phpMyAdmin is working by entering the IP address of your Pi into
your web browsers address bar appended with /phpmyadmin/, like this:
http://192.xxx.x.xxx/phpmyadmin/ hit Enter and you should be presented with the
standard phpMyAdmin login page as shown below:

These steps differ for both Apache and NGINX so make sure you follow the correct list
of steps.

Configuring Apache for phpMyAdmin


7a. To begin setting up Apache for use with phpMyAdmin enter the following
command into the terminal:
sudo nano /etc/apache2/apache2.conf
7b. Now at the bottom of this file enter the following line:
Include /etc/phpmyadmin/apache.conf
Once done save & exit by pressing CTRL +X and then y.
7c. Now restart the Apache service by entering the following command:
sudo /etc/init.d/apache2 restart
~ sudo mysql_secure_installation

~ sudo mysql -u root –p

~ sudo apt-get install python-mysqldb


sudo apt-get install python-mysql.connector

Creating a Database user

~ sudo mysql -u root -p ~ GRANT ALL PRIVILEGES ON mydb.* TO 'root'@'localhost' IDENTIFIED


BY '1234';

Setting up a Raspberry Pi as an access point


in a standalone network (NAT)

The Raspberry Pi can be used as a wireless access point, running a standalone


network. This can be done using the inbuilt wireless features of the Raspberry Pi 3 or
Raspberry Pi Zero W, or by using a suitable USB wireless dongle that supports access
points.

Note that this documentation was tested on a Raspberry Pi 3, and it is possible that
some USB dongles may need slight changes to their settings. If you are having trouble
with a USB wireless dongle, please check the forums.

To add a Raspberry Pi-based access point to an existing network, see this section.

In order to work as an access point, the Raspberry Pi will need to have access point
software installed, along with DHCP server software to provide connecting devices with
a network address. Ensure that your Raspberry Pi is using an up-to-date version of
Raspbian (dated 2017 or later).

Use the following to update your Raspbian installation:

sudo apt-get update


sudo apt-get upgrade

Install all the required software in one go with this command:


sudo apt-get install dnsmasq hostapd

Since the configuration files are not ready yet, turn the new software off as follows:

sudo systemctl stop dnsmasq


sudo systemctl stop hostapd

To ensure that an updated kernel is configured correctly after install, reboot:

sudo reboot

Configuring a static IP

We are configuring a standalone network to act as a server, so the Raspberry Pi needs


to have a static IP address assigned to the wireless port. This documentation assumes
that we are using the standard 192.168.x.x IP addresses for our wireless network, so
we will assign the server the IP address 192.168.4.1. It is also assumed that the
wireless device being used is  wlan0 .

To configure the static IP address, edit the dhcpcd configuration file with:

sudo nano /etc/dhcpcd.conf

Go to the end of the file and edit it so that it looks like the following:

interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant

Now restart the dhcpcd daemon and set up the new  wlan0  configuration:

sudo service dhcpcd restart


Configuring the DHCP server (dnsmasq)

The DHCP service is provided by dnsmasq. By default, the configuration file contains a
lot of information that is not needed, and it is easier to start from scratch. Rename this
configuration file, and edit a new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig


sudo nano /etc/dnsmasq.conf

Type or copy the following information into the dnsmasq configuration file and save it:

interface=wlan0 # Use the require wireless interface - usually wlan0


dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h

So for  wlan0 , we are going to provide IP addresses between 192.168.4.2 and


192.168.4.20, with a lease time of 24 hours. If you are providing DHCP services for
other network devices (e.g. eth0), you could add more sections with the appropriate
interface header, with the range of addresses you intend to provide to that interface.

There are many more options for dnsmasq; see the dnsmasq documentation for more
details.

Configuring the access point host software (hostapd)

You need to edit the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to


add the various parameters for your wireless network. After initial install, this will be a
new/empty file.

sudo nano /etc/hostapd/hostapd.conf

Add the information below to the configuration file. This configuration assumes we are
using channel 7, with a network name of NameOfNetwork, and a password
AardvarkBadgerHedgehog. Note that the name and password should not have quotes
around them. The passphrase should be between 8 and 64 characters in length.

To use the 5 GHz band, you can change the operations mode from hw_mode=g to
hw_mode=a. Possible values for hw_mode are:

 a = IEEE 802.11a (5 GHz)


 b = IEEE 802.11b (2.4 GHz)
 g = IEEE 802.11g (2.4 GHz)

 ad = IEEE 802.11ad (60 GHz).

interface=wlan0

driver=nl80211

#driver=rtl871xdrv

ssid=RFIDServer

hw_mode=g

channel=6

macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=2

wpa_passphrase=raspberry

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

We now need to tell the system where to find this configuration file.

sudo nano /etc/default/hostapd

Find the line with #DAEMON_CONF, and replace it with this:

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Start it up

Now start up the remaining services:

sudo systemctl start hostapd


sudo systemctl start dnsmasq

sudo systemctl unmask hostapd


sudo systemctl enable hostapd

sudo systemctl start hostapd

Add routing and masquerade

Edit /etc/sysctl.conf and uncomment this line:

net.ipv4.ip_forward=1

Add a masquerade for outbound traffic on eth0:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Save the iptables rule.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot.

iptables-restore < /etc/iptables.ipv4.nat

Reboot

sudo apt purge libpam-chksshpwd


installing EV DEV for rfid functionality

- sudo pip install evdev

Collecting evdev
Downloading https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b738
Building wheels for collected packages: evdev
Running setup.py bdist_wheel for evdev ... done
Stored in directory: /root/.cache/pip/wheels/f6/ad/e1/5d30bce69dba5c09b23c054a
Successfully built evdev
Installing collected packages: evdev
Successfully installed evdev-1.1.2

Installation of GSM Module

This is a very short helping tutorial explaining how to get gammu working with an USB 3G modem (in my
case a Huawei K3565) in CentOS which will be used in sending out alert messages for critical events.

Start by connecting the modem and figuring out if it is recognised by the system:
# lsusb
Bus 001 Device 002: ID 045e:0779 Microsoft Corp. LifeCam HD-3000
Bus 003 Device 002: ID 04d9:1203 Holtek Semiconductor, Inc. Keyboard
Bus 004 Device 002: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

We can see the device correctly identified (it uses the same chip as several other Huawei models).

Next we figure out which ttyUSB device the modem shows up as. Looking at the list above it is on Bus
004, Device 002 with two other devices on precedent buses, so that would make it ttyUSB2 (with
ttyUSB0 being the camera and ttyUSB1 the keyboard).

Install gammu (it is available via the RPMForge repository).

Open /etc/gammurc and change the settings to:

port = /dev/ttyUSB2
connection = at115200

Now run gammu –identify (this may take a while):

# gammu --identify
Manufacturer : huawei
Model : unknown (K3565)
Firmware : 11.608.10.51.00
IMEI : phone_imei_number
SIM IMSI : sim_imsi_number

Additional commands are available for more info:

# gammu --networkinfo
Network state : home network
Network : 226 03 (Cosmote), LAC 3A55, CID 4393

# gammu --monitor 1
Press Ctrl+C to break...
Entering monitor mode...
Enabling info about incoming SMS : No error.
Enabling info about incoming CB : No error.
Enabling info about calls : No error.
Enabling info about USSD : No error.
SIM phonebook : 0 used, 250 free
Own numbers : 0 used, 1 free
Battery level : 0 percent
Charge state : battery connected and is being charged
Signal strength : -73 dBm
Network level : 100 percent
SIM SMS status : 6 used, 0 unread, 40 locations
Phone SMS status : 0 used, 0 unread, 23 locations
Network state : home network
Network : 226 03 (Cosmote), LAC 3A55, CID 4393
Leaving monitor mode...

We can now send a test message:


# echo "Testing a test." | gammu --sendsms TEXT +123456789012
If you want break, press Ctrl+C...
Sending SMS 1/1....waiting for network answer..OK, message reference=9

If you want to check for received SMS messages, use


gammu --getallsms

If you’ve received the test message on your target number then gammu works and you can use the
above command to programatically send SMS messages out of any other application or script.

You might also like