This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

RaspberryPi

Learn about working with Raspberry Pi

1 - Raspberry Pi OS

How to configure a static IP address

  • Find the available interfaces using : ip a
  • Add static ip configuration in dhcpcd.conf file
  • Restart dhcpcd service
#/etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.2.123/24
static routers=192.168.2.254
static domain_name_servers=8.8.8.8

## reload the service configuration
sudo systemctl daemon-reload

## restart dhcpcd service
sudo systemctl restart dhcpcd.service

2 - Ubuntu Server for Pi

How to enable wifi and configure a static IP address

  • Find the available interfaces using : ip a

  • [or] use networkctl to Query the status of network links

sriram@ubuntu:~$ networkctl
IDX LINK  TYPE     OPERATIONAL SETUP
  1 lo    loopback carrier     unmanaged
  2 eth0  ether    no-carrier  configuring
  3 wlan0 wlan     routable    configured

3 links listed.
  • Use netplan to configure the interface
# edit /etc/netplan/50-cloud-init.yaml
# add entry for wlan0
# add entry for static ip address, gateway and nameservers.
# below is an example configuration

sriram@ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml
network:
    ethernets:
        eth0:
            dhcp4: true
            match:
                driver: bcmgenet smsc95xx lan78xx
            optional: true
            set-name: eth0
    version: 2
    wifis:
      wlan0:
        dhcp4: no
        addresses:
          - 192.168.2.123/24
        gateway4: 192.168.2.254
        nameservers:
          addresses: [8.8.8.8, 1.1.1.1]
        optional: true
        access-points:
          "ACCESSPOINT-NAME":
            password: "password"

## apply the changes with netplan
sudo netplan apply