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.
ProblemI 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 address
- 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)
iface eth0 inet dhcp
#iface eth0 inet dhcp
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...
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
sudo -i" command again to get to the admin console
cd /etc/network && cp interfaces interfaces.static && cp interfaces interfaces.dynamic
For Dynamic IP Address
rm interfaces && ln interfaces.dynamic interfaces
For Static IP Address
rm interfaces && ln interfaces.static interfaces
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.