I have been working on a series of Raspberry Pi projects, some trivial and some, less so. Recently at the Raspberry Pi non-event, I attempted to remote desktop into my Raspberry Pi, and had some success doing so, but after a request to show of the Pi Store, my little dalliance was over, and I felt like a complete idiot not being able to view the internet from the Pi.
The problem was that I had set up a static IP address for my Pi, and forgot how to tell the Pi to talk to anything else. The solution is a rather simple one, but I now have, at least what I would consider to be, a better way to do this in the future.
Problem
I wanted to be able to switch in and out of dynamic and static IP address systems and retain all of the functionality of a dynamic IP addressSolution
- Firstly I fired up the Pi, when I got home...
- After logging in, I switched to administrative privileges console mode by using the "
sudo -i
" command NOTE: This works right out of the box using every Raspberry Pi and Most *NIX systems, but please be careful in the sudo environment and remember to use the exit command when you are done! - type "
ifconfig eth0 && netstat -r
" This will show some information below
eth0 Link encap: Ethernet HWaddr aa:bb:cc:dd:ee:ff inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 ..... (Next few lines are un-important) Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default 192.168.0.1 255.255.255.0 UG 0 0 0 eth0 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
- Make a log of the following:-
- The Gateway (In our case 192.168.0.1)
- The Current Address (In our case 192.168.0.2)
- The Mask (In our case 255.255.255.0)
- The Network Address (In our case 192.168.0.0)
- The broadcast Address (In our case 192.168.0.255)
- The Gateway (In our Case 192.168.0.1)
- I then used the command
nano /etc/network/interfaces
- Once in this file I added a # at the beginning of the line for dhcp, so that rather than
iface eth0 inet dhcp
it read
#iface eth0 inet dhcp
- After completing this step add a newline by navigating to the end of the line just edited and pressing the
key - on the new line, begin to write the following
iface eth0 inet static address 192.168.0.125 netmask 255.255.255.0 network 192.168.0.1 broadcast 192.168.0.255 gateway 192.168.0.1 nameserver 192.168.0.1
These lines should basically mirror the numbers we took in step 3, with the nameserver generally being the same as the gateway...- Use
+X, followed by Y+ to save the file - Issue a reboot command
Now at this point you are done, the static IP address should be set-up, but the next few steps will allow you to chop and change more simply
- Now we need to use the "
sudo -i
" command again to get to the admin console- We then need to use the copy command to clone our config
cd /etc/network && cp interfaces interfaces.static && cp interfaces interfaces.dynamic
- We then need to edit the files using nano through the following command
nano interfaces.dynamic
- All you need to do in this file is remove the "#" character and remove the 7 lines following that line (leave the line you have just un-commented about)
- Now using
+X, followed by Y+ , you can save this file - Lastly use the following command(s) to delete the interfaces file and replace it with a link to the static or dynamic using the following commands
For Dynamic IP Address
rm interfaces && ln interfaces.dynamic interfaces
For Static IP Address
rm interfaces && ln interfaces.static interfaces
- on the new line, begin to write the following
This concludes our tutorial, I hope you enjoyed and look forward to hearing any critique of the techniques from any readers attending the next LUG Meeting Monday 11th February 2013.

