RaspberryPi:Networking
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see RaspberryPi:AdvancedConnectivity.
Contents
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.
Ethernet Connectivity
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).
Static IPs
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this wiki, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using network sharing on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet.
Setting a static IP on your Desktop
Windows
[Show/hide]
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.
Ubuntu
[Show/hide]
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
Setting a static IP on the Pi
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.
From the boot partition
[Show/hide]
Insert the SD card into your computer and navigate to the BOOT partition
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
Enable SSH as per Section [sec:SSH].
You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.
In dhcpcd (while the Pi is running)
[Show/hide]
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:
# Static IP profile for eth0 profile static_eth0 static ip_address=192.168.137.15/24 static routers=192.168.137.1 static domain_name_servers=192.168.137.1 8.8.8.8 # Ethernet interface configuration interface eth0 fallback static_eth0 # Wireless configuration interface wlan0 metric 200
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:
- Insert the SD card into a computer
- Navigate to the BOOT partition
- Create a file called “ssh”. Note there is no file extension!
- 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:
- Open PuTTY
- In the “Hostname” field, enter in “192.168.137.15”
- 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.
- You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.
- You should now successfully connected to your Raspberry Pi via SSH
VNC
To learn about how to install VNC, see
- Ensure the VNC service is enabled on the Pi
- Connect to the Pi through VNC.
- Set your preferred resolution for Raspbian
- In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.
- Select a more appropriate resolution (1280*720 suggested)
- Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.
- Set the VNC resolution
- Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height
- 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.