In order to set a static IP address on your Pi we will have to go into the configuration of your network adapter. So start the command line (or a terminal window) and start typing the following commands.

sudo nano /etc/network/interfaces

Once the configuration file is open delete all the content by holding down CTRL + K

Now copy and paste the following text into the configuration file.

allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet static

address 192.168.2.21
netmask 255.255.255.0
gateway 192.168.2.254

dns-nameservers 8.8.8.8 8.8.4.4
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

In this configuration the ethernet port will stay on DHCP (dynamic IP address). The WiFi adapter (wlan0) will get a static IP address. In my example this will be 192.168.2.21 with a class C subnet (255.255.255.0) and my gateway is 192.168.2.254. Feel free to use your personal IP ranges instead.

The DNS addresses are from Google. Also feel free to replace them with other DNS name server addresses.

Save and Exit Nano by typing CTRL + X then press Y followed by ENTER.

sudo reboot now

After the reboot your WiFi IP should read 192.168.2.21 (or the ip you choose).

To check this use the command

ip addr

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.