Skip to main content

Run your Raspberry Pi with wifi and static IP addresses


In this post I'm going to go through steps I took to get my quite old raspberry pi (Model B Rev. 2) up and running again for some future projects. We will install NOOBS, change hostname, setup the wifi, and finally we setup static IP addresses on the pi to make it easily available on our private network.

Installation

Installation is very easy if you follow the original raspberry pi instructions. You just download NOOBS, format your SD card with SD Formatter, and copy NOOBS files to your SD card. And then you boot your raspberri pi, and follow the instructions on the screen.

A couple of tools that will come handy after the installation are:

  • Win32 Disk Imager to get backups of your SD card, after installing and configuration of different stuff. So spare some hard disk space on your computer for the backups.
  • A good SSH client. I use mobaXterm. There are of course plenty of them out there. 

After NOOBS installation just run two below commands. It's good to run them every now and then to keep your pi updated and upgraded.

> sudo apt-get update
> sudo apt-get upgrade

It's time now for a backup of your SD card using Win32 Disk Imager.

Hostname

It's a good idea to have your customized hostname for your pi, especially if you have a few of them in the same network. So here's how to change the hostname from the default "raspberrypi":

First edit the localhost entry in /etc/hosts, and change the line with "127.0.0.1 raspberrypi" to your desired hostname, here "mypi":

> sudo pico /etc/hosts
127.0.0.1    localhost 
::1          localhost ip6-localhost ip6-loopback 
ff02::1      ip6-allnodes 
ff02::2      ip6-allrouters 
127.0.1.1    mypi 

After this, you should also edit /etc/hostname file and change the content to mypi as above.

> sudo pico /etc/hostname
mypi

Now you can commit the changes and reboot your pi with the new hostname:

> sudo /etc/init.d/hostname.sh
> sudo reboot

After it boots you can test your hostname by running the command "hostname".

Wifi on pi

To setup your wifi correctly first we check the /etc/network/interfaces file. It should look like below. Note that both eth0 and wlan0 use dhcp. By the way I use Edimax EW-7811Un wifi adapter on my pi.

> sudo pico /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Then to get wifi working you need to give the SSID name and your wifi password to your pi. Here's how to do it, you add the lines with "network=..." to wpa_supplicant.conf file:

> sudo pico /etc/wpa_supplicant/wpa_supplicant.conf
country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="SSID_NAME"
    psk="YOUR_WIFI_PASSWORD"
}

By now you should have both eth0 and wlan0 working with DHCP. Check that you get IP addresses on both of your interfaces by issuing "ifconfig".

Static IP addresses

You can set static IP addresses for your eth0 and wlan0 on your router if your router supports this function. In my case I am using a pretty cheap and simple router set up by our Internet and TV provider, and there are no options on it to do that. But there's another way, and that's from your raspberry pi. You edit /etc/dhcpcd.conf and add the lines below:

> sudo pico /etc/dhcpcd.conf
interface eth0

static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

interface wlan0

static ip_address=192.168.0.11/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

In our case we have set up 192.168.0.10 for eth0 and 192.168.0.11 for wlan0 while our router's IP address is 192.168.0.1. Now you edit /etc/network/interfaces as below:

> sudo pico /etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
auto wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

That's it! if you reboot your pi now, you will get the static IP addresses on it. Your pi is ready to rock and roll, but don't forget to backup your SD card before anything!

Comments

  1. Best 777 Casino Hotel - Mapyro
    777 Casino Hotel is an excellent choice for 광명 출장샵 travelers who want an 남원 출장샵 unforgettable experience and 광양 출장마사지 stay at an unforgettable casino hotel. 안산 출장마사지 This casino is close  Rating: 4 · ‎3 reviews 광명 출장샵

    ReplyDelete
  2. Sports Betting - Mapyro
    Bet worrione the moneyline from 1:25 PM https://octcasino.com/ to 11:00 PM. See more. goyangfc.com MapYO Sportsbook 출장샵 features live odds, live streaming, and detailed febcasino.com information.

    ReplyDelete
  3. Merkur Futur Adjustable Safety Razor - Sears
    Merkur Futur https://septcasino.com/review/merit-casino/ Adjustable Safety Razor is ventureberg.com/ the perfect balance of performance, safety, 토토 사이트 and comfort. Made in Solingen, Germany, poormansguidetocasinogambling this razor has a perfect balance of deccasino

    ReplyDelete

Post a Comment

Popular posts from this blog

Bring your old printer online with Raspberry Pi

If you have an old printer at home that does not have a network interface, but has a USB port, you can connect it to your raspberry pi. Since your pi is reachable in your private network ( see my previous post ), you can make it a print server for your printer and make it available on your LAN. Using  Google Cloud Print , you can even take a step further and make your printer reachable over the internet. This good article explains how to set up the print server on your pi. I will repeat the steps here for the record and go on to the Google Cloud Print part.  For the print server on the pi, you need CUPS (Common Unix Printing System) . But before that, to make your pi visible to your Windows machines, you need samba : > sudo apt-get install samba > sudo apt-get install cups These may take a few minutes to install. Just follow the instructions that may come on the screen and you'll be fine. After installing CUPS, you need to add your current user (by default: pi)