RaspberryPi:Networking

From UCT EE Wiki
Revision as of 09:13, 6 February 2020 by CRNKEE002 (talk | contribs)
Jump to navigation Jump to search

There are many ways to interface with the Pi. This page will cover types of network connectivity.

A Brief Overview of Networks

It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read this article from Microsoft: https://tinyurl.com/y2z8x9za

Assigning a Static IP to the Pi

This section will assign a static Ethernet address to the Raspberry Pi. This is useful for your first configuration. If you have not done so, it is recommended you follow the instructions in RaspberryPi:Installation to configure your Raspberry Pi.

  1. Insert the SD card into your computer and navigate to the BOOT partition

  2. Open “cmdline.txt” and append the following to the line (don’t create a new line)

    ip=192.168.137.15

    This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15

  3. Enable SSH by creating a file called "ssh" on the boot partition. Note, no file extension!.

  4. You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in Assigning a Static IP to your Computer.

Assigning a Static IP to your Computer

In order to use Ethernet for SSH, VNC, etc, it is required that the Pi and your computer all be on the same subnet. This section details how to do it.

Windows

To change the IP of your Ethernet port on Windows 10, complete the following steps:

  • Right click on your network option in Windows taskbar
  • Select “Open Network & Internet Settings”, on the lower right hand side of the screen.
  • Select “Change Adapted Options”
  • Right click on the Ethernet Connection and select “Properties”
  • Select “Internet Protocol Version 4 (TCP/IPv4) and click "Properties"
  • Select “Use the following IP address:” and enter in the following options
    • IP Address: 192.168.137.1
    • Subnet Mask: 255.255.255.0
  • You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.
File:Figures/WindowsIPConfig
caption The IPv4 configuration screen in Windows 10

Ubuntu

To change the IP of your Ethernet port on Ubuntu, complete the following steps:

  • Click the network interface icon on the status bar and select Wired Settings
  • Click the gear button of the interface you’d like to change
  • Select the IPv4 Tab, and change the IPv4 method to Manual
  • Under “Addresses” enter in the following:
    • IP Address: 192.168.137.1
    • Subnet Mask: 255.255.255.0
  • You can leave Gateway and DNS blank
File:Figures/ubuntustaticip
caption The IPv4 configuration screen in Ubuntu 18.10

Ensuring connectivity

Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ping command. Ping sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.

To use the ping command, open a command prompt window or terminal and type the following:

$ ping 192.168.137.15

If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get

Reply from 192.168.137.15: bytes=32 time<1ns TTL=64

This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.

NB: Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.

Networking Protocols

For a more detailed overview on useful networking protocols, see Network Protocols

SSH

Enabling SSH

If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.

To enable SSH, add it as an enabled service in the raspi-config menu. If you do not have access to the Pi as yet, do the following:

  1. Insert the SD card into a computer
  2. Navigate to the BOOT partition
  3. Create a file called “ssh”. Note there is no file extension!
  4. Your Pi will enable SSH upon next boot

Using SSH

To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).

Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.

$ ssh <username>@192.168.137.15

If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:

  1. Open PuTTY
  2. In the “Hostname” field, enter in “192.168.137.15”
  3. Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.
  4. You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.
  5. You should now successfully connected to your Raspberry Pi via SSH

VNC

To learn about how to install VNC, see

  1. Ensure the VNC service is enabled on the Pi
  1. Connect to the Pi through VNC.
  2. Set your preferred resolution for Raspbian
    1. In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.
    2. Select a more appropriate resolution (1280*720 suggested)
    3. Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.
  3. Set the VNC resolution
    1. Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height
    2. On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.