Page 1 of 1

Static IP not working

Posted: Sat Mar 01, 2014 4:30 am
by doni49
I've been trying to get my RasPi working with static IP and it just refuses to make the connection.
Here's the output from ifconfig and netstat -nr and below that is the contents of my interfaces file (from /etc/network). The ifconfig and netstat results are both while set to dynamic IP.

NOTE: when it gets the IP address via dynamic, it gets 10.1.1.103 but I want a static IP of 10.1.1.1. That's the reason for that discrepancy -- I did however try using a static IP of 10.1.1.103. And I also deleted the IP lease from the router's memory before rebooting the RasPi with the static IP assigned.

Any ideas?
eth0 Link encap:Ethernet HWaddr b8:27:eb:86:c3:a4
inet addr:10.1.1.103 Bcast:10.1.1.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fe86:c3a4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1546 errors:0 dropped:0 overruns:0 frame:0
TX packets:627 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:127067 (124.0 KiB) TX bytes:194397 (189.8 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:212 errors:0 dropped:0 overruns:0 frame:0
TX packets:212 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:20155 (19.6 KiB) TX bytes:20155 (19.6 KiB)

Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.1.1.1 0.0.0.0 UG 0 0 0 eth0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet static
address 10.1.1.3
netmask 255.255.255.0
network 10.1.1.0
broadcast 10.1.1.255
gateway 10.1.1.1


Re: Static IP not working

Posted: Sat Mar 01, 2014 5:09 am
by Richard-TX
Here is what works for me.

Code: Select all

    auto lo

    iface lo inet loopback
    iface eth0 inet static
    address 10.232.1.81
    netmask 255.255.255.0
    gateway 10.232.1.1


 

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:22 am
by blachanc
Richard-TX wrote:Here is what works for me.

Code: Select all

    auto lo

    iface lo inet loopback
    iface eth0 inet static
    address 10.232.1.81
    netmask 255.255.255.0
    gateway 10.232.1.1

sorry for a bit of highjacking the thread, but I always wondered what is the benefit from setting the IP via the PI vs reserving the IP via the router? I am sure there is a good reason, but fail to capture it.

Ben

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:26 am
by Richard-TX
Ther reason for a fixed IP address is so that the IP address is always known. With DHCP, it is like a box of chocolates.

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:35 am
by doni49
I think he was asking about doing it directly on the device as opposed to reserving the IP at the router. In my case, my router doesn't do that -- my only options are leave it as dynamic IP or set up the device to do static IP.

I've got another RasPi on the same network and it's working on static IP fine.

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:44 am
by blachanc
doni49 wrote:I think he was asking about doing it directly on the device as opposed to reserving the IP at the router. In my case, my router doesn't do that -- my only options are leave it as dynamic IP or set up the device to do static IP.

I've got another RasPi on the same network and it's working on static IP fine.
Yes, you are right this is what I was wondering. I missed the obvious ;)
Based on your explanation, I will make sure my next router still allows DHCP reservations :D

thanks to both of you for the explanations.

Ben

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:47 am
by doni49
I just copied this from the RasPi that IS working. I had previously copied this over to the other one (and changed the address from 10.1.1.2 to 10.1.1.3) and it refused to work. I know there's not anything else on the network using this address. I just set this router up tonight (just bought it used and did a factory reset myself then changed the ip address).

With the exception of these two RasPi Devices, everything on my network uses dynamic IP (the router is configured so that all dynamic addresses are in the range 10.1.1.100 to 10.1.1.50 and I've confirmed that all the other devices on my network are in this range).

In addtion, just to be sure, I did try using the following addresses:
10.1.1.11
10.1.1.15
10.1.1.103 (this is the IP that was assigned to it under dynamic)

I've also since tried copy pasting your code into my file (of course changing the address/gateways to for my network).

No joy anywhere. :?

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet static
      address 10.1.1.2
      netmask 255.255.255.0
      gateway 10.1.1.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Re: Static IP not working

Posted: Sat Mar 01, 2014 5:52 am
by doni49
Also: the code that I originally posted is a little different from what you posted as well as from what is working on the other RasPi. When I started experiencing this problem, I started searching for answers. I came across this posting which is where I got this info:

https://www.modmypi.com/blog/tutorial-h ... ip-address

Re: Static IP not working

Posted: Sat Mar 01, 2014 7:04 am
by rpdom
I can't see an "auto eth0" or "allow-hotplug eth0" line in that interfaces file.

Re: Static IP not working

Posted: Sat Mar 01, 2014 7:11 am
by doni49
Does it matter which one I use? What's the difference between them?

I don't know where I got what I have now. But since it works, I tried copying it over to the new one.

Re: Static IP not working

Posted: Sat Mar 01, 2014 7:29 am
by doni49
Ok. I found something that helped. Based on that, I put the hotplug line in and rebooted it. It's working now. Thanks for the help! I appreciate it!

http://www.debian.org/doc/manuals/debia ... nterfaces

"auto <interface_name>" start interface <interface_name> upon start of the system
"allow-hotplug <interface_name>" start interface <interface_name> when the kernel detects a hotplug event from the interface

Re: Static IP not working

Posted: Sat Mar 01, 2014 7:34 am
by ripat
Strange because looking at the result of the ifconfig you posted, your interface was UP and the RX/TX packets counter were showing something.

Glad your fixed that.

Re: Static IP not working

Posted: Sat Mar 01, 2014 7:38 am
by doni49
The IFConfig that I posted was from being run as dynamic. I provided that info so that anyone trying to assist would be able to see the network settings that I needed to get the RasPi to use in static mode.