Static I.P. on the Pi


12 posts
by D.E.L.B. » Fri Jul 06, 2012 7:34 am
I had a look at this video:
http://www.youtube.com/watch?v=kcqQwBpB3Rw&feature=plcp

I got my gateway, IPv4 address and subnet mask through IP config on Windows, and changed the I.P. address from my router onto the Pi, I changed the last digit to 121.

It didn't work, and now my Internet has also messed up, what can I do to fix this?

I went through:
Code: Select all
cd /etc/network
sudo nano interfaces


Changed the DHCP to static, and all of the things that the video suggested, changed the last digit of my IP to make it static, and it didn't work.
User avatar
Posts: 92
Joined: Sat Jun 09, 2012 7:16 pm
Location: Wales, UK
by Jokke » Fri Jul 06, 2012 4:08 pm
Hi,

It's a bit difficult to tell as we do not have info about your network configuration. I think the safer way to do that is record your PI's MAC address (# ifconfig -a) leave the interface setting to DHCP and log in to your router. From the routes DHCP menu you can set up static lease for the RPis MAC address. This way if you did miss something or have typo there, you will not break your network, the RPi will just get dynamic IP.
Posts: 11
Joined: Tue Jul 03, 2012 3:50 pm
by D.E.L.B. » Fri Jul 06, 2012 4:18 pm
Jokke wrote:Hi,

It's a bit difficult to tell as we do not have info about your network configuration. I think the safer way to do that is record your PI's MAC address (# ifconfig -a) leave the interface setting to DHCP and log in to your router. From the routes DHCP menu you can set up static lease for the RPis MAC address. This way if you did miss something or have typo there, you will not break your network, the RPi will just get dynamic IP.

I messed up my configuration really bad I had to reformat the SD card :P.

I will try the Static IP shortly, and will take in what you've just said in-case anything does mess up again! Before I reformatted the SD card, I potched about with the settings so much that not even I knew what the hell was going on.
User avatar
Posts: 92
Joined: Sat Jun 09, 2012 7:16 pm
Location: Wales, UK
by bredman » Fri Jul 06, 2012 4:57 pm
Before editing a configuration file, it is a good idea to make a copy of the original file. For example to make a copy of the network interfaces file
sudo cp /etc/network/interfaces /etc/network/interfaces.backup

If you really mess things up, you can copy the backup file back to the original location
sudo cp /etc/network/interfaces.backup /etc/network/interfaces
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by bredman » Fri Jul 06, 2012 5:00 pm
If you want to configure a static IP address, search the internet for tutorials on IP networks.

You will need to understand concepts such as
- subnetwork
- network address
- dynamic (DHCP) address range
- static address range

You can't pick a network address at random. It must be an address in the static address range within your subnetwork.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by D.E.L.B. » Fri Jul 06, 2012 5:11 pm
bredman wrote:If you want to configure a static IP address, search the internet for tutorials on IP networks.

You will need to understand concepts such as
- subnetwork
- network address
- dynamic (DHCP) address range
- static address range

You can't pick a network address at random. It must be an address in the static address range within your subnetwork.

http://www.penguintutor.com/blog/viewblog.php?blog=6306

What does this mean exactly?
In this case the local network has valid addresses from 192.168.1.1 to 192.168.1.254. The router is at address 192.168.1.1 and any DHCP requests will be given entries between 192.168.1.100 and 192.168.1.150 (you can change the range of the DHCP addresses if required). I have used 192.168.1.4 for this server.

To change to static IP address


How is that so? Why between 100 to 150, if it goes up to 254 surely it can be between 1 and 254 right?
User avatar
Posts: 92
Joined: Sat Jun 09, 2012 7:16 pm
Location: Wales, UK
by bredman » Fri Jul 06, 2012 5:29 pm
The dynamic address range is set in the router's admin page. In this case, the router is allowed to dynamically serve any address between .100 and .150. A static address can be in the range .2 to .99 or .151 to .254.

When picking a static address, you must not collide with the dynamic address range.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by D.E.L.B. » Fri Jul 06, 2012 5:47 pm
Alright now I see where the 100 and 150 comes from, but now why ranging from 2 to 99, and 151 to 254?
User avatar
Posts: 92
Joined: Sat Jun 09, 2012 7:16 pm
Location: Wales, UK
by bredman » Fri Jul 06, 2012 7:41 pm
Because .1 is used by the router and .100 to .150 are used by DHCP. All the others are available for you to use.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by geezbeez » Sat Jul 07, 2012 8:38 am
As I think someone said above, if you want to allocate a specific IP to the Rasp PI when connected to your network the usual way is to leave everything connecting to the router using DHCP. i.e dont change anything on the Rasp PI but on your router allocate specific IP addresses to the various mac addresses of the equipment on your network.
If however your not connecting to a half decent router or something else running a proper DHCP server you might want to use a static IP.

So if your ethernet router/pc/laptop was 192.168.1.1
/etc/network/interfaces would have:
iface eth0 inet static
address 192.168.1.91
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

I'm connecting Rasp PI to my laptop which is running Window Internet Connection Services. I set a static IP similar to above although I'd prefer to be able to allocate a specific IP to the PI from my Laptop/PC/Router depending on what I connect the Rasp PI to. This is easy from a router which provide options for this, or from linux, ( most routers run linux like the Rasp PI but provide menus to make admin easier.) From windows 7 it seems (to me anyway) to be a lot more complicated
Posts: 28
Joined: Mon Jul 02, 2012 9:19 pm
by Pi-Scan » Sat Oct 27, 2012 1:37 am
Remember!!

If you have a webserver of some sort running (like the Adafruit-WebIDE), you NEED to have this at the beginning of your file:

Auto lo
Iface lo inet loopback
Posts: 25
Joined: Fri Jul 06, 2012 9:16 pm
by pluggy » Sat Oct 27, 2012 4:13 am
All 3 of my headless Pi's have static IP addresses and they all can access the internet, so it's definitely your end. Some routers will tolerate you using one of their DHCP range as a static. They check the address isn't already in use (using ping) before blindly shoving out the same one, but it isn't universal. Choosing one at the extremes of the range (Last octet below 50 or above 200) is usually safe if you don't know. All the router's I've dealt with dole out IP addresses in the middle somewhere.
Don't judge Linux by the Pi.......
User avatar
Posts: 2595
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK