How ToIoT HardwaresRaspberry PiTutorials/DIY

How To Setup Static IP Address on Raspberry Pi

If you want to set the IP Address of Your Raspberry Pi So that it does not change. So in this post i am telling to you How To Setup Static IP Address on Raspberry Pi. This is simple, You need to edit the configuration file /etc/network/interfaces.
To edit this file, type the following command:

$ sudo nano /etc/network/interfaces 

You may like also: How To Use Raspberry pi in a truely headless mode


How To Setup Static IP Address on Raspberry Pi

First decide on an IP address to use. You need to pick one that is both unused by any other machine on the network and within the allowed range of IP addresses for your home hub. In this case, I will use 192.168.168.115. Modify the contents of the file, changing the word dhcp to static.

With the file changed as shown here, the static IP address 192.168.1.115 has been assigned to the eth0 interface.


auto lo

iface lo inet loopback
iface eth0 inet static
    address 192.168.1.115
    netmask 255.255.255.0
    getway 192.168.1.1
    
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


For most networks, the netmask setting should be set to 255.255.255.0 and the gateway should be the IP address of your home router irself. This will be the same as the IP Address you use to connect to the admin console of your router. After you edit and save the file, run the following commands to clear out all the existing DHCP leases, and restart your Pi so that changes will take effect.

$ sudo rm /var/lib/dhcp/*
$ sudo reboot

You may like also:


Buy now : Raspberry PI 3 Model B+ Motherboard

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin