Connect to network RPi with Ubuntu

Computers like Raspberry Pi (RPi) can be connected to a network – to provide them an access to the Internet or connect to them remotely. This article describes how network connections can be configured on RPi with Ubuntu Mate 15.10 with GUI tools and in terminal mode.

Wired network connection

The easiest way to get connected to a network is using a network cable. Wired connection  usually does not require configuration and normally starts working when it is connected.

Default network interfaces contain: Local Loopback and wired network interface (later – to connect via network cable).
Command ifconfig shows existing network interfaces and its parameters

ifconfig

RPi-Network-001

enx” is a prefix of wired network interface name, followed by MAC address. MAC address also presented by “HWaddr” (“hardware address”). In many articles and manuals interfaces have names eth1 or wlan0Predictable Network Interface Names.

hint Raspberry Pi 3 has build-in Wi-Fi adapter

Wireless network interface name of RPi 3 is wlan0

RPi-Network-054

Connect the network cable to the wired network port and to the router. Run ifconfig to check the state of the network interfaces

ifconfig

RPi-Network-002

The IP address 192.168.1.13 was assigned to the wired network interface. Try to ping it from another computer connected to the same network

ping

Raspberry-Pi-CLion001

When remote computer is not connected to network with specified IP – ping reports “Destination Host Unreachable” (actually its possible to decline the request of ping with special settings, when needed, so ping is not always works)

Raspberry-Pi-Net001

If the router is connected to the Internet – RPi should have an access to the internet as well.

Wireless network connection

Plug-in to the RPi USB port a Wi-Fi adapter (also known as “Wi-Fi USB dongle”).

Connect to Wi-Fi network with GUI list of network connections

When RPi is connected to the wired network – the particular icon is shown (and notification when mouse hovers over this icon)

RPi-Network-005

Unplug the network cable from the wired network port – the wireless network icon is shown. While RPi is not connected to any Wi-Fi networks – the icon is empty

RPi-Network-006

Click with the left mouse button on the network icon to invoke the menu with a list of available Wi-Fi networks and click on the item with the name of preferred one (in this example myWiFiNet)

RPi-Network-009

Enter the password in the “Wi-Fi Network Authentication Required” and hit on “Connect” button

RPi-Network-010

Wait while the connection is established – network connection icon is changed

RPi-Network-011

Click on the network connection icon invokes the menu with available Wi-Fi networks and some network operations

RPi-Network-012

Command ifconfig shows a status of Wi-Fi network interface with an IP address assigned to it

RPi-Network-013

Connect to Wi-Fi network with GUI tool Network Manager

Click with the right mouse button on the network icon to invoke the menu and click on the item ¨Edit Connections…¨

RPi-Network-007

The dialog of the tool Network Manager is shown. Click on the button ¨Add¨ to create a new connection

RPi-Network-008

Select “Wi-Fi” in the “Choose a Connection Type” dialog and click the button “Create…”

RPi-Network-014

Enter some connection name for and type Wi-Fi connection name in the field “SSID”

RPi-Network-015

hint Specify Wi-Fi adapter for connection

Particular adapter can be specified for the connection – select it from the list “Device MAC address”

RPi-Network-018

On the tab “Wi-Fi Security” select required security type (usually “WPA & WPA2 Personal”) and type the password

RPi-Network-016

Leave other parameters as is (e.g. on the tab “IPv4 Settings” leave “Automatic (DHCP)” to get IP automaticlly) and hit the button “Save”

RPi-Network-017

If buttons on the Network Manager dialog are disabled (“grayed”)  – run the Network Manager from the terminal with sudo permissions

sudo nm-connection-editor
Direct connection Raspberry Pi and computer via network cable

Connection RPi to computer via a router reduce the speed of data-transfer. To connect RPi to a computer with network cable – change settings in wire network connection. Open the Network Manager, select a wired network connection  and hit the button “Edit”

RPi-Network-028

In the tab “IPv4 Settings” select Method “Shared to other computers” and hit the button “Save”

RPi-Network-029

Now plug the network cable to wired network ports of RPi and the computer. Check IP with the commang ifconfig. Notice the IP address is very different then in case of connection to a router

RPi-Network-030

hint Data transfer speed examples

Copy of 522MB file from RPi to a computer (PC) with command scp (“secure copy”). In parallel system-monitor GUI was shown remotely from RPi (run command mate-system-monitor over SSH connection with option “-X”)

RPi -> network cable -> PC (direct connection between RPi and PC)

RPi-Network-035

RPi-Network-034

RPi -> network cable -> router -> Wi-Fi -> PC

RPi-Network-039

RPi-Network-037

RPi -> Wi-Fi (adapter #1) -> router -> Wi-Fi -> PC

RPi-Network-045

RPi-Network-043

RPi -> Wi-Fi (adapter #2) -> router -> Wi-Fi -> PC

RPi-Network-051

RPi-Network-050

RPi -> Wi-Fi (adapter #2) -> router -> network cable -> PC (without transferring system-monitor GUI remotely)

RPi-Network-052

RPi -> Wi-Fi (adapter #2) -> router -> Wi-Fi -> PC (without transferring system-monitor GUI remotely)

RPi-Network-053

Last two cases show not much difference.

Connect to Wi-Fi network in terminal mode
Create the connection with nmcli tool

Find the wireless interface name using ifconfig

ifconfig

RPi-Network-003

wlx” is a prefix of wireless network interface name, followed by MAC address. Second plugged Wi-Fi adapter adds one more network interface

RPi-Network-004

nmcli tool (“network manager client”) allows to check, add, delete, modify wireless connections (examples).

Find an available wireless network (option “d” stands for “device”, “dev” or “device” can be used as well)

nmcli d wifi list

RPi-Network-020

Create a new connection for Wi-Fi network for Wi-Fi adapter – following two commands (separated with “&&”) adds the connection and also modifying its security settings to WPA-PSK

sudo nmcli c add con-name myWiFiNetConnection type wifi ifname wlx002401098bd4 ssid myWiFiNet && sudo nmcli c modify myWiFiNetConnection wifi-sec.key-mgmt wpa-psk

Start-up the created wireless connection and enter the requested password – this password will be stored in the connection parameters file

sudo nmcli --ask c up myWiFiNetConnection

Check that a file with connection settings has been created in the folder /etc/NetworkManager/system-connections

sudo ls /etc/NetworkManager/system-connections
sudo cat /etc/NetworkManager/system-connections/myWiFiNetConnection

RPi-Network-025

Wait while wireless connection is established – it gets an IP address (check with ifconfig). If it is not connected – try to reboot the RPi or unplug the network cable from RPi, if it is connected.

Potential issues

  • When Wi-Fi adapter is replaced with another one – the existing connection would not work with this new adapter, because the network interface’s names contain their MAC addresses and created network connections bound to these unique interface names. In such case – a new similar connection can be created with another name – this allows to have connections for multiple Wi-Fi adapters.
  • When a network connection is created with Network Manager GUI tool, most likely it sets property permissions=user:user-name; Such connection is not started-up before this user user-name is not logged (in terminal mode as well). In such case – open the file with connection settings and remove the permissions.
Alternative solutions of terminal mode connections

Following approaches were tried but did not work well.

1. Specify network settings in the file /etc/network/interfaces  and use command dhclient wlan0

auto wlan0
iface wlan0 inet dhcp 
      wpa-ssid <network-ssid>
      wpa-psk <network-password>

2. Use console tool wicd and wicd-curses

sudo apt-get install wicd wicd-curses

3. Component wpa_supplicant implementing WPA key negotiation to provide improved layer of security for wireless networks.

 

 

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published. Required fields are marked *