Sunday 15 September 2019

Raspbian Raspberry Pi Static IP Address

Introduction


This page will describe how to set a static IP address for your Raspberry Pi using Raspbian.
See separate post on how to do the same for Lubuntu / Ubuntu 20.04



Steps


Begin by finding your current IP address :

hostname -I

You will receive back one or more IP address, such as ;

192.168.1.70 
192.168.1.69

From this you learn that your computer is on the 192.168.1.0 network.

Then run :

sudo apt-get install nmap
sudo nmap -sP 192.168.1.0/24

adjusting 192.168.1.0 according to your network.

From this I learnt that my router (dsldevice.lan) has the IP address 192.168.1.254

The DNS server, which is often the same iP address as your router can be found via :

cat /etc/resolv.conf

which gave:

nameserver 192.168.1.254

Now go into your router's admin pages and find the DHCP range.

The next step, while in the router's admin pages, is to limit the DHCP Network Range to 192.168.1.50 - 192.168.1.99. This provides 50 available dynamic IP addresses, which is sufficient for most households.

What this means is that 192.168.1.100 - 192.168.1.253 or 154 IP addresses are available to be set as static IP addresses. 

Again while in the router's admin pages, looking at the IP addresses connected to my router I found that only 192.168.1.201-192.168.202, and of course 192.168.1.254 for the router itself, had static IP addresses.

All other connected devices had dynamic DHCP addresses within the 192.168.1.50 - 192.168.1.99 range.

See the bottom of this page for screen captures from my router.

Running on my Raspberry Pi :

ifconfig

showed that the address for eth0 was 192.168.1.70 and wlan0 was 192.168.1.69

I therefore chose to setup my main Raspberry Pi using a static IP address for its Ethernet (eth0) connection, but to leave its wireless wlan0 to be dynamically set via DHCP.


sudo nano /etc/dhcpcd.conf


I added the following text to the end of the /etc/dhcpcd.conf file.

interface eth0
static ip_address=192.168.1.205/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.254

sudo ip link set eth0 down
sudo ip link set eth0 up
ifconfig

Running ifconfig should show the change in IP address.

If the static IP address does not show up try running ifconfig several times, it sometimes takes a few seconds to show.






No comments:

Post a Comment