Cool Bug
Did you mess up?
Switch to a Terminal
At the login screen, press Ctrl+Alt+F5 to switch to a TTY. You’ll be prompted to enter a login. At the login prompt, enter your username and press Enter. You’ll then be prompted for your password. You will not see your password as you are typing it; just type it and press “Enter.”
get info:
ip address
ifconfig
sudo nano /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
FILES:
sudo nano /etc/netplan/00-install-config.yaml
sudo nano /etc/netplan/50-cloud-init.yaml
Got Ethernet to have an IP address
If you are using an ethernet cable and are not connected to the network at this point you may need to run:
sudo dhclient eth0
so now I can see:
ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:d6:c4:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic eth0
valid_lft 86393sec preferred_lft 86393sec
inet6 fe80::dea6:32ff:fed6:c4f6/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether dc:a6:32:d6:c4:f7 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.4/24 brd 192.168.1.255 scope global dynamic wlan0
valid_lft 84439sec preferred_lft 84439sec
4: wlan1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 1c:bf:ce:55:e6:0b brd ff:ff:ff:ff:ff:ff
and I can see both in router
How Do I Set a Static IP Address on Raspberry Pi?
UPDATED MAR 12, 2022
Set a static IP
To set a static IP you need to replace the
dhcp4: true
line in the network-config file with lines that specify the intended IP address as well as its default gateway and DNS server. You can do this for either the eth0 or wlan0 interface (or both). It is important that you get the indenting right for this work correctly
For example, if you were planning to give the pi the address 192.168.1.17 in the 192.168.1.0/24 subnet with a default gateway of 192.168.1.1 and a DNS server of 192.168.1.53 then the following text would work. The same structure works for both the eth0 or wlan0 sections in the file:
ethernets:
eth0:
addresses:
- 192.168.1.17/24
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.53]
optional: true
How to Set Static IP Address
The following is an example Netplan file with a network interface that has a static IP address. The interface’s name is en01 and it has been assigned static IP addresses 192.168.1.25/24
for IPv4, and 2001:1::1/64
for IPv6.
As both IPv4 and IPv6 have been assigned static IP addresses, each has a gateway set too.
DNS Name servers are also defined in this file. We’ll cover DNS a little further down in this tutorial.
network:
version: 2
renderer: networkd
ethernets:
en01:
addresses:
- 192.168.1.25/24
- "2001:1::1/64"
gateway4: 192.168.1.1
gateway6: "2001:1::2"
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
To apply changes to netplan you will need to reload your Netplan network configurations.
sudo netplan apply
If you're using your Raspberry Pi as a media or game server, setting a static IP address will make things far easier.
If you’re using your Raspberry Pi as a home server or often need to access it remotely from another device, setting a static IP address for it is a very good idea. This means you’ll be able to find it at the same Raspberry Pi fixed IP address every time, rather than a new address being set dynamically whenever it is rebooted. This is also useful to avoid confusion when you have multiple Raspberry Pi devices connected to your network.
MAKEUSEOF VIDEO OF THE DAY
Fortunately, once you know how, it's a fairly simple and quick process to set a Raspberry Pi static IP address. We’ll show you how to change the IP address in Raspberry Pi OS to make it permanent.
What Is an IP Address?
An Internet Protocol (IP) address is used to uniquely identify each device on a computer network, or the network itself on the internet – more on that later. The IP address is normally written in ‘dot-decimal’ notation: four decimal numbers, each ranging from 0 to 255, separated by dots. An example is 192.168.1.107.
By default in Raspberry Pi OS, which is a Linux-based operating system, your Raspberry Pi’s IP address is reconfigured automatically each time you reboot it, so it may well change. Naturally, this is not ideal when you need a reliable address at which to connect to the Raspberry Pi from another device, such as when using it as a server. So it’s better to set a static IP address on Raspberry Pi.
Private vs. Public IP
A public IP address is used to identify your local network on the wider internet. This typically changes every time your router connects to the internet, although you may be able to make it static depending on your internet service provider.
You can find the public IP address on a Linux system such as Raspberry Pi OS by entering a special Terminal command, or simply by doing a web search for ‘What's my IP?’. It is only required if you intend to connect to a device from outside your network, which we won’t cover here.
Instead, we are looking at the private IP addresses used to identify each device on your own local network. While it may be possible to reserve a certain address for your Raspberry Pi in your wireless router’s settings for the same purpose, here we’ll be showing you how to set a static IP from the Raspberry Pi itself.
1. DHCP Configuration
Raspberry Pi OS (formerly know as Raspbian) uses DHCP (Dynamic Host Configuration Protocol) to assign an IP address to the Raspberry Pi automatically whenever it is rebooted. You can find out more in our guide to DHCP.
To change Raspberry Pi OS's behavior so that it uses the same static IP address each time, you will need to modify the configuration file for the DHCP client daemon, dhcpcd.conf.
Before that, you will need some information on your current network setup so you can add the required details to the configuration file. You will require the following info:
• The type of network connection. This is either wlan0 if your Raspberry Pi is connected to the router wirelessly, or eth0 if it’s connected using an Ethernet cable.
• The Raspberry Pi’s currently assigned IP address – it’s safest to reuse this for its static IP so that you can be sure the latter hasn’t already been to another device on the network. If not, make sure another device isn't already using it.
To find the Raspberry Pi’s current IP address, enter the following command in a Terminal window:
hostname -I
• Your router’s gateway IP address – the one used to contact it from the local network, not its public IP. It varies depending on the router model, but typically starts with 192.168.
To find it, enter the following command and note the first IP address given:
ip r | grep default
• Your router’s DNS (Domain Name System) IP address. This is typically the same as its gateway address, but may be set to another value to use an alternative DNS – such as 8.8.8.8 for Google, or 1.1.1.1 for Cloudflare.
To find the current DNS IP address, enter the command:
sudo nano /etc/resolv.conf
Note the IP address after nameserver – that's the DNS address – and then press Ctrl + X to close the file.
2. Add Static IP Settings
Now you have found all your network connection information, it’s time to edit the dhcpcd.conf configuration file to add the settings you need to set up a static IP address for your Raspberry Pi:
sudo nano /etc/dhcpcd.conf
If you haven’t edited the file previously, it will mainly contain various comment lines preceded by a hash (#) symbol. At the bottom, add the following lines, replacing the emboldened names with your own network details:
interface NETWORK
static ip_address=STATIC_IP/24
static routers=ROUTER_IP
static domain_name_servers=DNS_IP
Replace the emboldened names as follows:
• NETWORK – your network connection type: eth0 (Ethernet) or wlan0 (wireless).
• STATIC_IP – the static IP address you want to set for the Raspberry Pi.
• ROUTER_IP – the gateway IP address for your router on the local network.
• DNS_IP – the DNS IP address (typically the same as your router’s gateway address).
Here is an example configuration to set the static IP to 192.168.1.120 with a wireless connection to a router at 192.168.1.254:
interface wlan0
static ip_address=192.168.1.120/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.254
Once you have entered the settings, press Ctrl + X and then Y and ENTER to close and save the modified configuration file.
3. Reboot the Raspberry Pi
With the dhcpcd.conf configuration file modified, restart your Raspberry Pi to effect the changes and set the static IP address for it:
sudo reboot
Rather than using an address assigned automatically by DHCP, the Raspberry Pi will now attempt to connect to the router using the new static IP address that you set in the dhcpcd.conf file.
To check that it is working correctly, enter the following command:
hostname -I
You should now see the static IP address that you set in the dhcpcd.conf configuration file.
Set a Static IP Address: Success
Congratulations: you have set up a static IP address on your Raspberry Pi, and it should now retain that address automatically whenever it boots up. Now you can go ahead and use your Pi system as a NAS, media or game server, and connect to it reliably at the same Raspberry Pi fixed IP address every time.
How to set WiFi Authentication
While WiFi is not something you would commonly configure Ubuntu server for, it it is prevalent enough you may consider using it in some use cases. To the following with walk you through configuring WPA and EAP wifi modes.
Systemd does not have native wifi support. In order for your network device to work with wifi you will need wpasupplicant installed.
Configuring WPA and EAP WiFi Connections
The most common home wifi configurations use mode WPA or EAP, while EAP is more common in enterprise. These two modes use a basic form of authentication using a password or shared-key.
For home users, the WPA mode is the simplest to use with a compatible wifi device. Devices that support WPA can automatically join wifi networks by pressing the WPA button on a compatible wifi router.
To configure WPA or EAP on Ubuntu using Netplan, you would add the auth scalar to your netplan configuration file. In the example below, we’ve added it to a ethernet interface named id0.
ethernets:
id0:
[...]
access-points:
mode: infrastructure
bssid: mywifi
band: 5GHz
channel: 5
auth:
key-management: none | psk | eap
password: my-password-string
The access-points scalar sets how the wifi connection will be established.
- mode set the mode type for your wifi network interface. For connecting to access points the value should be set to infrastructure, which is the default.
- bassid is the name of your wifi connection, as configured on your access point.
- band is used to set the wireless band. It accepts two values: 5GHz and 2.4GHz. If left unset, the wifi endpoint and your network device will automatically establish the best band. By setting this value you will force the connection to use a specific band.
- channel is used to set your wifi channel, and only takes affect if the band property is set.
WPA and EAP connection modes accept the following configurations.
-
key-management
sets how the supported key management mode.
- none to disable key management
- psk for WPA with pre-shared key, common for home wifi.
- eap for WPA with EAP, which is common for enterprise wifi networks.
-
password sets the pre-shared key or password for your wifi network, when the mode is set to either psk or eap.
NetPlan Files
Network interfaces in Ubuntu 20.04 are configured in NetPlan YAML files, which are stored under /etc/netplan
. The default file networking interfaces for a new Ubuntu 20.04 install is /etc/netplan/00-installer-config.yaml
.
To edit the default netplan file, use the following command.
sudo vi /etc/netplan/00-installer-config.yaml
Alternatively, a simpler text editor by the name of nano can be used instead of vim.
sudo nano /etc/netplan/00-install-config.yaml
From the examples on netplan.io, I would assume your file should look something like this:
network:
version: 2
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
access-points:
"my_ssid":
password: "my_password"
dhcp4: true
optional: true
3 obvious errors in your file was:
- that
version: 2
had incorrect indentation, - that you defined your AP under the
ethernets
section, where it should be under thewifis
section, and - that you missed the
dhcp4: true
statement for your wifi.
In addition, you might need to run these commands:
sudo netplan --debug apply
sudo systemctl enable wpa_supplicant
sudo systemctl start wpa_supplicant
sudo netplan generate
sudo netplan apply
To fix this you need to go into the correct file and correct the issue. Run:
sudo nano /etc/netplan/50-cloud-init.yaml
so you can edit the file. Edit it so it looks like this again, the indentation needs to be correct for the .yaml to work:
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"home network":
password: "123456789"
Save and exit the file with Ctrl + S
and Ctrl + X
.
Run sudo netplan apply
and sudo reboot
and when you log back in, you will be connected to your wifi.
sudo apt install net-tools
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.15 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dea6:32ff:fed6:c4f6 prefixlen 64 scopeid 0x20<link>
ether dc:a6:32:d6:c4:f6 txqueuelen 1000 (Ethernet)
RX packets 51 bytes 5242 (5.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 47 bytes 6514 (6.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 218 bytes 17377 (17.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 218 bytes 17377 (17.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.4 netmask 255.255.255.0 broadcast 192.168.1.255
ether dc:a6:32:d6:c4:f7 txqueuelen 1000 (Ethernet)
RX packets 1827 bytes 344168 (344.1 KB)
RX errors 0 dropped 2 overruns 0 frame 0
TX packets 904 bytes 131822 (131.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 1c:bf:ce:55:e6:0b txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pre-setup files
info is still useful
Edit the network-config
file to add your Wi-Fi credentials. An example is already included in the file, you can simply adapt it.
To do so, uncomment (remove the “#” at the beginning) and edit the following lines:
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
<wifi network name>:
password: "<wifi password>"
For example:
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"home network":
password: "123456789"
Note: network name must be enclosed in quotation marks.
Save the file and extract the card from your laptop.
Note ⓘ: During the first boot, your Raspberry Pi will try to connect to this network. It will fail the first time around. Simply reboot
sudo reboot
and it will work.
Boot Ubuntu Server
Duration: 2:00
If you are using an HDMI screen and a USB keyboard, ensure they are plugged in before powering the Pi. You will be able to see the boot process on the screen.
Warning
During your first boot a tool called cloud-init 77 is doing configuration. WAIT for it to finish before trying to log in. It typically takes less than 2 minutes but there is a break between the log-in prompt and cloud-init completing. If you interrupt the process you have to start again. You’ll know it’s done when it outputs some more lines after the log-in prompt has appeared.
Once cloud-init 77 finishes log in using “ubuntu” as both the password and login ID. After a minute or so, Ubuntu on your Raspberry Pi will have fully booted and connected to the network.
If you are using an ethernet cable and are not connected to the network at this point you may need to run:
sudo dhclient eth0
Connect remotely to your Raspberry Pi
To connect to your Raspberry Pi remotely, you need two things (we’ll help you find them):
- Its IP address on the local network
- An SSH client (SSH is a communication protocol between machines)
You have to do this if you are running your device headless, but you might also want to do this if you are not so you can access your Pi from anywhere.
Determining the Pi’s IP address
To determine the IP address of your board, open a terminal and run the arp
command:
On Ubuntu and Mac OS:
arp -na | grep -i "b8:27:eb\|dc:a6:32\|e4:5f:01"
Information
Depending on your version of Ubuntu, you may need to install thenet-tools
package. Install it withsudo apt install net-tools
and try thearp
command again.
On Windows:
arp -a | findstr b8-27-eb dc-a6-32 e4-5f-01
This will return an output similar to:
? (xx.xx.xx.x) at b8:27:eb:yy:yy:yy [ether] on wlp2s0
Where the x’s are the IP address of any Raspberry Pi connected to the local network. Note it down.
If the command doesn’t return an IP address, you may need to wait a little longer for your Pi to join the network. If you still can’t see it after a few tries, which can happen with some home or office network configurations, we recommend you use a USB keyboard and HDMI screen to interact with your device.
Using an SSH client
On Ubuntu and Mac OS, an SSH client is already installed. Some versions of Windows 10 also include an SSH client too, but if yours does not or you’re unsure, follow these steps 55to install one.
Open a terminal and run the following command:
ssh ubuntu@<Raspberry Pi’s IP address>
You will be asked to confirm the connection:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type “yes” to confirm.
Changing the password
When prompted, use “ubuntu” for the password. (The cursor won’t move when you type the password.) The first thing Ubuntu will do is to ask you to change it to a secure password. Once done, you can reconnect again with the SSH command and the new password.
Success! You are now connected to Ubuntu Server running on your Raspberry Pi.
Still not connected to the internet?
Sometimes the structure of the network-config file that you modified before boot gets messed up when you boot. This would cause your Pi not to be able to connect to your wifi.
To fix this you need to go into the correct file and correct the issue. Run:
sudo nano /etc/netplan/50-cloud-init.yaml
so you can edit the file. Edit it so it looks like this again, the indentation needs to be correct for the .yaml to work:
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"home network":
password: "123456789"
Save and exit the file with Ctrl + S
and Ctrl + X
.
Run sudo netplan apply
and sudo reboot
and when you log back in, you will be connected to your wifi.
How to Configure Networking in Ubuntu 20.04 with NetPlan
Overview
In this tutorial, you will learn how to configure networking in Ubuntu 20.04 with Netplan. You will learn how to set static IP addresses, DHCP addresses, as well as how to configure DNS and Wifi.
Introduced back in 18.04, April 2018, networking was redone using a new system called Netplan – a YAML based configuration network configuration system for NetworkManager and SystemD.
NetPlan Files
Network interfaces in Ubuntu 20.04 are configured in NetPlan YAML files, which are stored under /etc/netplan
. The default file networking interfaces for a new Ubuntu 20.04 install is /etc/netplan/00-installer-config.yaml
.
To edit the default netplan file, use the following command.
sudo vi /etc/netplan/00-installer-config.yaml
Alternatively, a simpler text editor by the name of nano can be used instead of vim.
sudo nano /etc/netplan/00-install-config.yaml
Apparently they go in numeric order - 10/ 0 / 50 don't mean anything different - just are engaged in order
How to Set Static IP Address
The following is an example Netplan file with a network interface that has a static IP address. The interface’s name is en01 and it has been assigned static IP addresses 192.168.1.25/24
for IPv4, and 2001:1::1/64
for IPv6.
As both IPv4 and IPv6 have been assigned static IP addresses, each has a gateway set too.
DNS Name servers are also defined in this file. We’ll cover DNS a little further down in this tutorial.
network:
version: 2
renderer: networkd
ethernets:
en01:
addresses:
- 192.168.1.25/24
- "2001:1::1/64"
gateway4: 192.168.1.1
gateway6: "2001:1::2"
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
To apply changes to netplan you will need to reload your Netplan network configurations.
sudo netplan apply
How to set DHCP Addresses
Dynamically addressed can be assigned for IPv4 and IPv6, provided your network has a DHCP server.
The following example shows how to enable DHCP for both IPv4 and IPv6. To enabled just one, you would remove the network IP version not needed.
network:
version: 2
renderer: networkd
ethernets:
en01:
dhcp4: true
dhcp6: true
To update your netplan configurations, run the netplan apply
command.
sudo netplan apply
How to Set DNS
The following is an example of a network interface id0
with nameservers
configured.
ethernets:
en01:
[...]
nameservers:
search: [lab, home]
addresses: [8.8.8.8, "FEDC::1"]
- search is a list of search domains, which are used when a non-fully qualified hostname is given. For example, if you were to ping
server1
rather thanserver1.lab
. - addresses is a list of IPv4 or IPv6 ip addresses for the DNS name servers. IPv6 must be quoted.
How to set WiFi Authentication
While WiFi is not something you would commonly configure Ubuntu server for, it it is prevalent enough you may consider using it in some use cases. To the following with walk you through configuring WPA and EAP wifi modes.
Systemd does not have native wifi support. In order for your network device to work with wifi you will need wpasupplicant installed.
Configuring WPA and EAP WiFi Connections
The most common home wifi configurations use mode WPA or EAP, while EAP is more common in enterprise. These two modes use a basic form of authentication using a password or shared-key.
For home users, the WPA mode is the simplest to use with a compatible wifi device. Devices that support WPA can automatically join wifi networks by pressing the WPA button on a compatible wifi router.
To configure WPA or EAP on Ubuntu using Netplan, you would add the auth scalar to your netplan configuration file. In the example below, we’ve added it to a ethernet interface named id0.
ethernets:
id0:
[...]
access-points:
mode: infrastructure
bssid: mywifi
band: 5GHz
channel: 5
auth:
key-management: none | psk | eap
password: my-password-string
The access-points scalar sets how the wifi connection will be established.
- mode set the mode type for your wifi network interface. For connecting to access points the value should be set to infrastructure, which is the default.
- bassid is the name of your wifi connection, as configured on your access point.
- band is used to set the wireless band. It accepts two values: 5GHz and 2.4GHz. If left unset, the wifi endpoint and your network device will automatically establish the best band. By setting this value you will force the connection to use a specific band.
- channel is used to set your wifi channel, and only takes affect if the band property is set.
WPA and EAP connection modes accept the following configurations.
-
key-management
sets how the supported key management mode.
- none to disable key management
- psk for WPA with pre-shared key, common for home wifi.
- eap for WPA with EAP, which is common for enterprise wifi networks.
-
password sets the pre-shared key or password for your wifi network, when the mode is set to either psk or eap.