Setting up Static IP in Raspberry Pi
Easy way to set Static IP Address in Raspberry Pi running Raspbian OS.
Usually DHCP is enabled by default.
Means Pi will get new random IP on most cases. But building a Project with Dynamic IP is Pain, Because the IP changes frequently.
Why Static IP?
My Raspberry Pi hosts lot of In-house tools, If IP Address changes frequently either i have login to the Router and Check Pi Address or Using the Fing app does the Job.
How about giving static IP to Pi which never changes.
Follow the below instruction to set static IP address in Raspberry pi.
Open the Terminal and run following commands.
sudo nano /etc/dhcpcd.conf
This will open up DHCP Configuration file.
Paste the below line inside the file.
If you connected in Raspberry Pi via Ethernet Cable
static ip_address=192.168.1.31/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
If you connected in Raspberry Pi via WiFi
interface wlan0 static ip_address=192.168.1.31/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
Once you're done. Press CTRL+O to save the file, Then CTRL+X to exit.
Now, Perform reboot.
Let's break the above lines...
interface eth0is the Network Interface I'm using. Here it means ethernet port
192.168.0Network ID and
10means host address
static routers=192.168.0.1means IP Address of my router
static domain_name_servers=192.168.0.1Means, Domain Name Server. It can be anything like your router IP or
Google Public DNS 188.8.131.52
Note: IP Address of your router may vary
To check the IP Address. Run the Below Command in Terminal
If you face any issue. Feel free to comment below.