nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Cannot set static IP address.

Wed Nov 04, 2015 10:09 pm

Hello everyone,

I just got my Pi and want to set a static IP address. I have been having some trouble. When I first got the Pi the /etc/network/interfaces file was this and currently this is the only thing that I can get to work.

Code: Select all

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

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

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
When I type ifconfig with the above interface file I get this
  • eth0 Link encap:Ethernet HWaddr b8:27:eb:da:1c:58
    inet addr:192.168.1.196 Bcast:192.168.1.255 Mask:255.255.255.0
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:3424 errors:0 dropped:0 overruns:0 frame:0
    TX packets:1042 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:993523 (970.2 KiB) TX bytes:171663 (167.6 KiB)

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:15 errors:0 dropped:0 overruns:0 frame:0
    TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:1684 (1.6 KiB) TX bytes:1684 (1.6 KiB)
The crazy think is that my router is set to hand out dynamic addresses starting at 192.168.1.201 and my Pi is getting an address of 192.168.1.196 so it must be getting set somewhere just not at the interface file.

I tried to set a static IP with the following but this didn't work and I cannot get to the internet when Pi loads


I did some reading and tried to change it to this

Code: Select all

auto lo
face lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.195
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255


auto wlan0
allow-hotplug wlan0
face wlan0 inet maualwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
I have read about a network manager on some Linux Distributions, but cannot find out if it is on my raspberry.

So please help me if you can.

Thanks

User avatar
NormanDunbar
Posts: 111
Joined: Wed Nov 23, 2011 12:13 pm
Location: Leeds, West Yorkshire, England.
Contact: Website

Re: Cannot set static IP address.

Wed Nov 04, 2015 10:52 pm

Evening.

I'm not sure that you need the network line. I don't have it in mine. Also, in some books, Web sites etc, the various parameter lines are indented one tab and sometimes in upper case, although I don't think uppercase is strictly necessary. The tab might be - mine has tabs before address, netmask, gateway and broadcast.

You will need to restart the network after making changes. I usually reboot as I've had some occasional problems with just restarting:

Code: Select all

sudo /etc/init.d/networking restart
When it comes up, ping 8.8.8.8 to see if you have Internet access, this and 8.8.4.4 are Google's public DNS servers. If that's OK, ping Google.com and if that fails to resolve, /etc/resolve.conf might need these:

nameserver 8.8.8.8
nameserver 8.8.4.4

I've just upgraded to Jessie and things might have changed. I'm far away from my pi just now, so unfortunately, i cannot check things. Sorry.

There is a network icon, top right on the title bar of the desktop, but I found using that doesn't work for wired networks, and had to set mine up manually. I've also given my WiFi a static address in a similar manner for wlan0.

HTH

Cheers,
Norm.
Why do they put lightning conductors on churches?
Why did Tarzan never have a beard?

nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Re: Cannot set static IP address.

Wed Nov 04, 2015 11:24 pm

Thanks Norm,

So I tried to comment out the network line and put in tabs for the address and the rest. Still not working.

So I noticed when it starts up I get an error that

ifup: couldn't read interface file /etc/network/interfaces

So I saved the original file before I made any changes as interfaces_template and just cp this back to interfaces when I run into problems. I then edited the new interfaces and typed in all the stuff like before but i still does not work.

FYI I also reboot each time I make a change to ensure that I am getting a clean boot.

Maybe the problem is with ifup?

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Cannot set static IP address.

Thu Nov 05, 2015 12:47 am

nzdreamer55 wrote:Thanks Norm,

So I tried to comment out the network line and put in tabs for the address and the rest. Still not working.

So I noticed when it starts up I get an error that

ifup: couldn't read interface file /etc/network/interfaces

So I saved the original file before I made any changes as interfaces_template and just cp this back to interfaces when I run into problems. I then edited the new interfaces and typed in all the stuff like before but i still does not work.

FYI I also reboot each time I make a change to ensure that I am getting a clean boot.

Maybe the problem is with ifup?
This is mine, and it has been working for 18 months or so (even tho' it has a network statement):

Code: Select all

$ cat /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet static
address 192.168.0.25
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
$
Your first post had several 'face' instead of 'iface' which may be confusing the setup:

Code: Select all

face lo inet loopback
and

Code: Select all

face wlan0 inet maualwpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Re: Cannot set static IP address.

Thu Nov 05, 2015 2:20 am

Thanks for taking such a close look at it and sharing yours with me. I'll try to get it to work tomorrow as I am at work now. I'll post back what happens. Thanks again. :)

User avatar
rpdom
Posts: 16400
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Cannot set static IP address.

Thu Nov 05, 2015 6:18 am

If your Pi is set up using the latest method for networking (and it looks like it is with the "iface eth0 inet manual" entry), then the IP address is no longer set in /etc/network/interfaces.

Instead you need to add some lines to /etc/dhcdcd.conf, something like this

Code: Select all

    interface eth0
    static ip_address=192.168.1.195/24
    static routers=192.168.1.1
    static domain_name_servers=192.168.1.1

nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Re: Cannot set static IP address.

Thu Nov 05, 2015 10:33 am

Thanks. Have some questions

1) what is the 24 in static ip_address=192.168.1.195/24. If it is the port, do I have to specify the port? What if something else is using the port?
2) if I have multiple routers do I need to list them or only they gateway? static routers=192.168.1.1

3) If I have alternative DNS (say google 8.8.8.8. & 8.8.4.4) do I just list this twice=> static domain_name_servers=192.168.1.1?

4) Do I need to edit /etc/resolv.conf for DNS entries too?

5) Do I need to edit /etc/network/interfaces or just leave it as it was originally?

User avatar
rpdom
Posts: 16400
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Cannot set static IP address.

Thu Nov 05, 2015 11:46 am

nzdreamer55 wrote:Thanks. Have some questions

1) what is the 24 in static ip_address=192.168.1.195/24. If it is the port, do I have to specify the port? What if something else is using the port?
No, it's not the port and you don't specify a port here. It's the equivalent of the "netmask 255.255.255.0" and "network 192.168.1.0". The /24 means the netmask is 24 bits long and the first 24 bits (3 octets) are used for the network number.
2) if I have multiple routers do I need to list them or only they gateway? static routers=192.168.1.1
Routers an gateways are basically the same thing. List any you have. Most people only have the one, unless you have more than one network.
3) If I have alternative DNS (say google 8.8.8.8. & 8.8.4.4) do I just list this twice=> static domain_name_servers=192.168.1.1?
List them all on the same line, with a space in between each one.

Code: Select all

static domain_name_servers=192.168.1.1 8.8.8.8 8.8.4.4
4) Do I need to edit /etc/resolv.conf for DNS entries too?
That should get automatically generated from the "domain_name_servers" entry.
5) Do I need to edit /etc/network/interfaces or just leave it as it was originally?
Leave it as it was.

nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Re: Cannot set static IP address.

Thu Nov 05, 2015 1:25 pm

Thanks again. One more thing
No, it's not the port and you don't specify a port here. It's the equivalent of the "netmask 255.255.255.0" and "network 192.168.1.0". The /24 means the netmask is 24 bits long and the first 24 bits (3 octets) are used for the network number.
So does this mean now we don't need to include the netmask and the network because the /24 tells the computer how to calculate these things?

Routers an gateways are basically the same thing. List any you have. Most people only have the one, unless you have more than one network
Ok so I have 2 routers and 1 switch. One router is connected out to the internet, the other router in internal and just acts like a switch but it has an IP address. So if I do the following

static routers=192.168.1.1 192.168.1.2

Will this work (these are the 2 IP addresses for my routers)?

Again thanks for the help.

User avatar
rpdom
Posts: 16400
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Cannot set static IP address.

Thu Nov 05, 2015 4:21 pm

nzdreamer55 wrote:Thanks again. One more thing
No, it's not the port and you don't specify a port here. It's the equivalent of the "netmask 255.255.255.0" and "network 192.168.1.0". The /24 means the netmask is 24 bits long and the first 24 bits (3 octets) are used for the network number.
So does this mean now we don't need to include the netmask and the network because the /24 tells the computer how to calculate these things?
Yes.

You didn't need to include the network or broadcast in the old method either, as they were worked out automatically.
Routers an gateways are basically the same thing. List any you have. Most people only have the one, unless you have more than one network
Ok so I have 2 routers and 1 switch. One router is connected out to the internet, the other router in internal and just acts like a switch but it has an IP address. So if I do the following

static routers=192.168.1.1 192.168.1.2

Will this work (these are the 2 IP addresses for my routers)?

Again thanks for the help.
If the router is only acting as a switch then you shouldn't to add it to the router list.

nzdreamer55
Posts: 29
Joined: Wed Nov 04, 2015 12:56 am

Re: Cannot set static IP address.

Thu Nov 05, 2015 5:53 pm

OK something isn't right...

Here is what I put into the file File: /etc/dhcdcd.conf

Code: Select all

interface eth0
static ip_address=192.168.1.195/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
I rebooted my Pi and I can use the internet but it is assigning a static address and DNS to other places

Code: Select all

[email protected] ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:da:1c:58  
          inet addr:192.168.1.196  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:107 errors:0 dropped:0 overruns:0 frame:0
          TX packets:87 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9301 (9.0 KiB)  TX bytes:11326 (11.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:7 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
         RX bytes:580 (80.0 B)  TX bytes:580 (580.0 B)
[email protected] ~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 68.105.28.11
nameserver 68.105.29.11
nameserver 68.105.28.12
Why is it setting ip to 192.168.1.196 and DNS to 68.105.28.11...

What other settings can I look in to help trouble shoot this issue?

Return to “Networking and servers”