You are previewing Raspberry Pi Networking Cookbook - Second Edition.
O'Reilly logo
Raspberry Pi Networking Cookbook - Second Edition

Book Description

Connect your Raspberry Pi to the world with this essential collection of recipes for basic administration and common network services

About This Book

  • Install, administer, and maintain your Raspberry Pi

  • Explore a new world of computing with this low cost, credit-card sized computer

  • Connect your Raspberry Pi to other devices on local networks and utilise IoT services

  • Who This Book Is For

    This book is intended for students, scientists, and hobbyists who wish to connect their Raspberry Pi to other devices on a local area network or to the Internet of Things. Whether you are new to the Raspberry Pi, or already have a lot of experience with it, the recipes in this book will be a valuable reference to you and inspire your next project. You will want to have this book handy as a guide whenever you are working on networking projects for the Raspberry Pi.

    What You Will Learn

  • Install, update, and upgrade your Raspberry PI

  • Configure a firewall to protect your Raspberry Pi and other devices on your local area network

  • Set up file sharing, remote access, a web server, and your own wiki

  • Create a wireless access point and use it as an Internet gateway

  • Stream video, audio, and local device data to IoT services as well as your own websites

  • Control devices connected to the Raspberry Pi from your phone via the web

  • Create a giant video wall using multiple monitors and Raspberry Pis

  • In Detail

    With increasing interest in Maker Projects and the Internet of Things (IoT), students, scientists, and hobbyists are using the Raspberry Pi as a reliable, inexpensive platform to connect local devices to Internet services.

    This book begins with recipes that are essential to installing the Raspberry Pi and configuring it for network access. Then it continues with recipes on installing common networking services such as firewalls and file sharing.

    The final chapters include recipes for network monitoring, streaming data from the Raspberry Pi to IoT services, and using clusters of Raspberry Pis to store and analyze large volumes of data.

    Style and approach

    This book contains a collection of practical, engaging recipes that will guide you through enhancing your Raspberry Pi’s existing network.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Raspberry Pi Networking Cookbook Second Edition
      1. Table of Contents
      2. Raspberry Pi Networking Cookbook Second Edition
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the color images of this book
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Installation and Setup
        1. Introduction
        2. Preparing for the initial boot
          1. Getting ready
            1. The basic components
            2. Basic networking
            3. Media centers
            4. Desktop computers
            5. Network hubs
            6. Game consoles
            7. The initial setup
          2. How to do it...
          3. How it works…
          4. There's more…
            1. Interfaces
            2. On-board components
            3. Recommended accessories
            4. Power supply problems
              1. Symptoms
              2. Causes
              3. Solutions
          5. See also
        3. Downloading new SD cards
          1. How to do it…
          2. How it works…
          3. See also
        4. Booting with NOOBS
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Mac OS X disk utilities – diskutil and dd
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Image Writer for Windows – Win32DiskImager.exe
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Convert and copy for Linux – dd
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Booting Raspbian Linux for the first time
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Shutting down the Raspberry Pi
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      9. 2. Administration
        1. Introduction
        2. Executing commands with privileges (sudo)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Switch user (sudo –u)
            2. Password
            3. The sudo group
          5. See also
        3. Expanding the size of a filesystem (raspi-config)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Configuring memory usage (raspi-config)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Configuring remote access (raspi-config)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Obtaining remote access by using SSH
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Digital fingerprints
            2. Hostname
          4. There's more...
            1. Finding out the IP address of the Raspberry Pi
            2. Spoofing the secure fingerprint
            3. Each new install creates new digital fingerprints
          5. See also
        7. Obtaining remote access by using PuTTY
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Changing the login password (passwd)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Adding a user (useradd)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        10. Giving a user sudo privileges (id and usermod)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      10. 3. Maintenance
        1. Introduction
        2. Updating the operating system (apt-get)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        3. Upgrading Raspbian from wheezy to jessie using sources.list
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
            1. The sources.list and sources.list.d
            2. The sources.list file format
          5. See also
        4. Searching for software packages (apt-cache)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        5. Installing a package (apt-get)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
          5. See also
        6. Package management (aptitude)
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more...
            1. The command line interface
          5. See also
        7. Reading the built-in documentation (man)
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more...
          5. See also
        8. Reading the built-in documentation (info)
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more...
            1. Coreutils – the most common Raspbian Linux utilities
            2. Searching for info
          5. See also
      11. 4. File Sharing
        1. Introduction
        2. Mounting USB disks (pmount)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Device files
            2. Mount points
            3. Unmounting disks
            4. The plugdev group
            5. Other mount commands
            6. Disk performance
            7. The Raspberry Pi's power is limited
          5. See also
        3. Accessing another computer's files (smbclient)
          1. Getting ready...
          2. How to do it...
          3. How it works…
          4. There's more...
            1. help
            2. Changing remote directories
            3. Fetching a single file
            4. / versus \
          5. See also
        4. Sharing folders from other computers (mount.cifs)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Protected shares require a username and a password
            2. Unmounting disks
          5. See also
        5. Auto-mounting USB disks at boot (/etc/fstab)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Error recovery
            2. The fstab file format
          5. See also
        6. Auto-mounting a shared folder at boot
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Creating a file server (Samba)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Sharing an attached USB disk (Samba)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      12. 5. Advanced Networking
        1. Introduction
        2. Configuring a static IP address
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Creating a firewall with ufw
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Don't forget to enable remote access
            2. Disabling the firewall
            3. Allowing a file server through the firewall
            4. Allowing a web server through the firewall
            5. Application rules
            6. Resetting the firewall rules
          5. See also
        4. Remote access to a desktop session (xrdp)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. No streaming video (or Minecraft)
            2. It's not the display
          5. See also
        5. Remote access to the monitor (x11vnc)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. No streaming video (or Minecraft)
          5. See also
        6. Installing a web server (Apache, lighttpd, Nginx)
          1. Getting ready
          2. How it works...
          3. There's more...
            1. Configuration files, static content, and dynamic pages
            2. Other servers
              1. lighttpd
              2. Nginx
          4. See also
        7. Installing a wiki (mediawiki)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Creating a wireless access point with hostapd
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Check the wireless USB adapter
            2. Configure the DHCP server by using udhcpd
            3. Configure the Wireless Access Point server by using hostapd
            4. Set up IP Forwarding
            5. Configure the boot parameters
            6. Start the wireless access point
          4. There's more…
            1. Not all USB wireless adapters support AP mode
            2. Wireless firewall, file server, or web server
          5. See also
        9. Installing a network trace utility
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Installing a network protocol analyzer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Promiscuous mode
            2. Terminal-based user interface
            3. Capture filters
          5. See also
        11. Enabling the IPv6 network protocol
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Privacy extensions
            2. Use sysctl to change kernel parameters at runtime
          5. See also
      13. 6. IoT – Internet of Things
        1. Introduction
        2. Easy access to hardware
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Connect the pushbutton switch to GPIO port 23
            2. Connect the LED to GPIO port 24
            3. Power on and log in
            4. Navigating the Linux kernel with sysfs
            5. Export GPIO ports 23 and 24
            6. Configure each interface direction as input or output
            7. Testing the input device
            8. Testing the output device
            9. Using the input device to activate the output device
            10. Cleanup
          4. See also
        3. Installing the GrovePi
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Installing the GrovePi drivers and interfaces
            2. Attach the GrovePi to the Raspberry Pi
            3. Power on and log in
            4. Install the Python API
            5. Test the Grove pushbutton switch
            6. Test the Grove LED
            7. Pressing the pushbutton switch lights the LED
          4. There's more…
          5. See also
        4. Controlling devices from a web page
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Create and run the ledpage website
            2. Action URLs
            3. Use Ctrl+C to quit
          4. There's more…
            1. Initialization
            2. The request_handler class
            3. The html_page function
            4. The main loop
          5. See also
        5. Connecting to an IoT platform
          1. Getting ready
          2. How to do it...
          3. How it works…
            1. Register your Raspberry Pi with the IoT platform
            2. Install the IoT platform API
            3. Exchange signals with the IoT platform
          4. There's more…
            1. Initialization
            2. The signal handler
            3. The main loop
            4. IoT Rules
          5. See also
        6. Creating an IoT gateway
          1. Getting ready
          2. How to do it...
          3. How it works
            1. Creating the bootable SD card
            2. Configuring wireless networking
            3. The ThingBox is ready
            4. Running the example flow
            5. Go with the flow
            6. Creating the pushbutton LED flow
          4. There's more…
            1. There is a large library of available nodes
            2. Wait 40 seconds before powering off or rebooting
          5. See also
      14. 7. Clustering
        1. Introduction
        2. Installing a high-availability load balancer
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Setting up the web servers
              1. Installing Apache2 on each web server
              2. Creating unique test web pages for each web server
              3. Testing the web servers
            2. Setting up the load balancers
              1. Install haproxy and keepalived on each load balancer
              2. Configuring HAProxy for each load balancer
              3. Enable listening on virtual IP addresses for both load balancers
              4. Configuring Keepalived for both load balancers
              5. Testing the cluster
            3. Testing web server failure
              1. Testing load balancer failure
              2. Restoring normal operation
          4. There's more…
            1. Scaling horizontally by adding more web servers
            2. Session cookies
          5. See also
        3. Installing a distributed filesystem
          1. Getting ready
          2. How to do it...
            1. Installing the GlusterFS server on each Raspberry Pi
          3. How it works...
            1. Installing the GlusterFS server on each Raspberry Pi
            2. Creating a striped replicated volume in the trusted storage pool
            3. Mount the distributed striped replicated volume
            4. Testing the striped replicated volume
              1. Replication
            5. Striping
            6. Testing the high availability of the cluster
            7. Testing the healing of replicated peers
          4. There's more …
            1. Using Keepalived to create a virtual filesystem endpoint
          5. See also
        4. Creating a supercomputer
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Setting up secure communication between master and slaves
            2. Downloading the Apache Spark software distribution
            3. Installing Apache Spark on each Raspberry Pi in the cluster
            4. Configuring the Spark master
            5. Calculating pi without using the Spark cluster
            6. Calculating pi using the Spark cluster
          4. There's more...
          5. See Also
      15. Index