Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.


Headless Raspberry Pi - Setup WiFi and Static IP Address

Here we will learn how to Setup headless Raspberry Pi. We want to setup Raspberry Pi headless to access it via PuTTY (ssh) on a different machine or PC (using the same WiFi 2.4GHz network) with a static IP address.

Method 1 (See updated: Headless Raspberry Pi Setup Guide)

Follow Step A to Step D for setup Raspberry Pi without connecting it to a keyboard and monitor.

Step-A Setup wifi manually

Once we wrote image to SD card(see, Step 1 Download and Write Image to SD card). We need to setup wifi manually for Headless Raspberry Pi. Create wpa_supplicant.conf file, enter country, ssid, psk (password) details.

# In this example I am using macOS
cd /Volumes/boot/
nano wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Step-B Enable SSH

To enable SSH on Raspberry Pi, please create an empty file with the name ssh (without any extension). Place this file in the root directory of the SD card.

# In this example I am using macOS
cd /Volumes/boot/
touch ssh

Step-C Scan IP address

Insert sd card in Raspberry Pi and power on. Wait for a minute.
Now search IP through one of the following app
(windows): https://www.advanced-ip-scanner.com/
(macOS): IP Scanner app (download from App Store)

# In this example I am using macOS

raspberry p IP Scanner

Step-D: Connect via ssh

Connect to your Raspberry Pi via ssh, use the IP address given in your result (Step-C)

# In this example I am using macOS (terminal app), on Windows you can use PuTTY.
ssh pi@ -p 22

Password 'raspberry'

Method 2

If above method is not working for you, you need to follow Step 1 to 7 by connecting Raspberry Pi to a keyboard and a monitor.

Step 1 Download and Write Image to SD card


Using 'Etcher' software to write 'RASPBIAN STRETCH LITE' Image to the SD card

Step 2 Power On

  • Plug in keyboard, monitor HDMI cable and insert SD card into Pi
  • Plug the power cable into Pi
  • Login with user name 'pi' and password 'raspberry'

Step 3 Switch to 'Root' user

To access Pi with 'Root' user, we will setup a new Password for the 'Root' user.

#login as a root user
pi@raspberrypi:~ $ sudo -i

#see the user name 'root'

#set a new password for the root user
root@raspberrypi:~# passwd

#Enter new UNIX password:
#Retype new UNIX password:
#passwd: password updated successfully

To access pi as a 'Root' user via ssh, we need to allow 'PermitRootLogin'.

#set 'PermitRootLogin' as 'yes'
root@raspberrypi:~# nano /etc/ssh/sshd_config

#Find 'PermitRootLogin prohibit-password' text and replace it as 'PermitRootLogin yes'
PermitRootLogin yes

#save sshd_config file (ctrl + x)

Step 4 Enable SSH Server

Enable remote command line access to your Pi using SSH

root@raspberrypi:~# raspi-config

#select -> '5 Interfacing Options Configure connections to peripherals'
#select -> 'P2 SSH Enable/Disable remote command line access to your Pi using SSH'
#'Would you like the SSH server to be enabled?' Yes

#'The SSH server is enabled' Ok

Step 5 Setup WiFi Network

Find SSID (You can use your mobile or computer)
find ssid of your wifi

You can also try the following command to find SSID via your Raspberry Pi.

root@raspberrypi:~# iwlist scan | grep SSID

lo        Interface doesn't support scanning.

eth0      Interface doesn't support scanning.

root@raspberrypi:~# raspi-config

# Select -> '2. Network Options Configure network settings'
# Select -> 'N2 Wi-fi Enter SSID and passphrase'
# 'Please enter SSID' 
# Ok
# 'Please enter passphrase. Leave it empty if none.'
# Ok
# Finish

#Reboot your Pi (see at the left bottom and type 'reboot' command) 
root@raspberrypi:~# reboot

# Login with user 'root' and Enter the password.

# Test outgoing traffic
root@raspberrypi:~# ping google.com
#64 bytes from xxxx-in-xx.xx.net (xxx): icmp_seq=1 ttl=53 time=49.9 ms
# press (ctrl + c)

Step 6 Setup static IP

#1. Enter following command
root@raspberrypi:~# ip -4 addr show dev wlan0 | grep inet
#output, ex.
inet brd scope global wlan0

#2. Enter Following command
root@raspberrypi:~# cat /etc/resolv.conf
# Generated by resolvconf, ex.
# nameserver

#3. Enter Following command to create a backup file
root@raspberrypi:~# cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup

#4. Open dhcpcd.conf file
root@raspberrypi:~# nano /etc/dhcpcd.conf 

#Based on the above information (#1 and #2), we will add following lines to the top of dhcpcd.conf
# We want to use static ip_address as (based on #1, it should be in between lower address bound and upper address bound, values of static routers and static domain_name_servers (based on #2)

interface wlan0
static ip_address=
static routers=
static domain_name_servers=

#save the file (Ctrl + x) and reboot your pi
root@raspberrypi:~# reboot

Step 7 Connect via an another machine

We can try to access Pi (Connection Type: SSH) with "Host Name:" and "Port: 22" via an another machine but using the same wi-fi network. You can use PuTTY. In the following example I am using 'Terminal' app on my Mac computer.

ssh root@ -p 22

#The authenticity of host ' (' can't be established.
#ECDSA key fingerprint is SHA256:A32M**************************************.
# Are you sure you want to continue connecting (yes/no)? yes

#Enter the password (That we set in Step 3 for the 'root' user)
root@'s password: 


Raspberry Pi Setup WiFi and Static IP

Happy Coding!
My Website (Learn Python) - https://PyBoys.com/
My Facebook Page - https://www.facebook.com/PythonMachineLearning/

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?