Linus
Posts: 23
Joined: Sat Mar 03, 2012 9:49 am

Static IP

Fri Jul 27, 2012 2:24 am

Hey all,

I'm having some problems getting my Pi a static IP for my local network.
My Pi currently has the local-ip address 192.168.2.2 (while being connected to my laptop via ethernet) and I need it to get a static IP of the form 10.0.1.XX so that the airport extreme will be able to connect it to the internet via NAT.

I've gone through all the static IP tutorials for the Rpi but after each reboot it won't even show up on the network even though I've set address gateway and netmask values correctly.

Thanks for your help!

NickBurns2000
Posts: 3
Joined: Wed Jul 25, 2012 5:48 pm

Re: Static IP

Fri Jul 27, 2012 2:35 am

All you need to do is edit your /etc/network/interfaces file
sudo nano /etc/network/interfaces
Here is what mine looks like:

iface lo inet loopback
iface eth0 inet static
address 192.168.1.205
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255

Save the file with CTL-X and restart the Pi.

Hope that helps.

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Sun Jul 29, 2012 5:40 pm

I tried this option but i do not know what to mention for broadcast ? I have the following details :
IP, Netmask, Gateway and DNS

Finally the content of my file is as follows :

#auto lo
iface lo inet loopback
iface eth0 inet static
address X.X.X.X
netmask Y.Y.Y.Y
gateway Z.Z.Z.Z
network K.K.K.K (i used the value of my dns)


But still i get the following error :
can not resolve hostname
what could be going wrong ?
I commented the auto io becoz that line was not mentioned in your post but even if it is uncommented, it does not solves the prob.
I also tried marking it as eth0 but it didnt work.

User avatar
PeterO
Posts: 3641
Joined: Sun Jul 22, 2012 4:14 pm

Re: Static IP

Sun Jul 29, 2012 5:53 pm

In the general case your network address will be similar to your ip address.
So if
ip = a.b.c.d
and
netmask = 255.255.255.0
then
network = a.b.c.0

So if
ip = 10.0.1.XX
and
netmask = 255.255.255.0
then
network = 10.0.1.0

HTH
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Sun Jul 29, 2012 6:45 pm

Can that resolve the Hostname ?
and what do we do abt the auto lo line ?

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Mon Jul 30, 2012 4:08 am

PeterO wrote:In the general case your network address will be similar to your ip address.
So if
ip = a.b.c.d
and
netmask = 255.255.255.0
then
network = a.b.c.0

So if
ip = 10.0.1.XX
and
netmask = 255.255.255.0
then
network = 10.0.1.0

HTH
PeterO
in my case it ends with 1 instead of 0
and i am still not sure abt the 'auto lo' line

vmp32k
Posts: 14
Joined: Fri Jul 27, 2012 3:05 pm

Re: Static IP

Mon Jul 30, 2012 4:18 am

The 'lo' interface is the loopback interface, you should keep the 'auto lo' part uncommented (without the # infront) to not break applications that rely on it.

The DNS server address goes into /etc/resolv.conf, like this:
nameserver 192.168.6.10
You can put as many lines in there as you want, though 2 is usually enough.
Here's an example using GoogleDNS via both IPv4 and IPv6:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

User avatar
PeterO
Posts: 3641
Joined: Sun Jul 22, 2012 4:14 pm

Re: Static IP

Mon Jul 30, 2012 6:50 am

Does it ? What is "it" ? Ip address,netmask or network ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Mon Jul 30, 2012 9:03 am

raspfly wrote:
PeterO wrote:In the general case your network address will be similar to your ip address.
So if
ip = a.b.c.d
and
netmask = 255.255.255.0
then
network = a.b.c.0

So if
ip = 10.0.1.XX
and
netmask = 255.255.255.0
then
network = 10.0.1.0

HTH
PeterO
in my case it ends with 1 instead of 0
and i am still not sure abt the 'auto lo' line
IT is the network details and i hav tried using both one ending with 0 and 1 non works.

User avatar
PeterO
Posts: 3641
Joined: Sun Jul 22, 2012 4:14 pm

Re: Static IP

Mon Jul 30, 2012 9:15 am

Please post the contents of /etc/network/interfaces

Are you sure your "airport" can't supply a config for your RPI via DHCP ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Mon Jul 30, 2012 9:16 am

vmp32k wrote:The 'lo' interface is the loopback interface, you should keep the 'auto lo' part uncommented (without the # infront) to not break applications that rely on it.

The DNS server address goes into /etc/resolv.conf, like this:
nameserver 192.168.6.10
You can put as many lines in there as you want, though 2 is usually enough.
Here's an example using GoogleDNS via both IPv4 and IPv6:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
I just hav to use the following 4 details to access internet from the proxy server.
IP, NETMASK, GATEWAY, DNS
auto lo
iface lo inet loopback
iface eth0 inet static
address X.X.X.X - this i think is the IP
netmask Y.Y.Y.Y
gateway Z.Z.Z.Z
network K.K.K.K - this is perhaps the DNS
broadcast L.L.L.L - this i am not sure of.

I hope my /etc/network/interfaces file should look as above

Apart from this i need to write the DNS in /etc/resolv.conf, like this:

nameserver K.K.K.K

(i know and hav been successfully using just one DNS since a long time.)

Am i right ?

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Mon Jul 30, 2012 9:39 am

PeterO wrote:Please post the contents of /etc/network/interfaces

Are you sure your "airport" can't supply a config for your RPI via DHCP ?

PeterO
What is this airport ?
I have been using this proxy since many years and never had any prob, i just had to enter the 4 details.
/etc/network/interfaces looks like this just the values are replaced by alphabets here and there are some comments mentioned here.

auto lo
iface lo inet loopback
iface eth0 inet static
address X.X.X.X - this i think is the IP
netmask Y.Y.Y.Y
gateway Z.Z.Z.Z
network K.K.K.K - this is perhaps the DNS
broadcast L.L.L.0 - this i am not sure of.

User avatar
Burngate
Posts: 5046
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Static IP

Mon Jul 30, 2012 11:23 am

Broadcast is for when one machine wants to talk to all the other machines on the local network. This is the address they would call, and the address it should respond to.

It's normally at the top of the address range, so if your Pi has an address of 192.168.15.3 and a netmask of 255.255.255.0 then the broadcast address would be 192.168.15.255.

If your Pi has an address of 10.0.0.5 and netmask 255.255.0.0 then the broadcast address would be 10.0.255.255

You could set the broadcast address to something different, but you would have to ensure that all machines on your local network, including your router, have the same one. That's why (a) sticking to defaults makes life easier and (b) using DHCP is used - it sets everything on your local network to something consistent.

User avatar
PeterO
Posts: 3641
Joined: Sun Jul 22, 2012 4:14 pm

Re: Static IP

Mon Jul 30, 2012 11:29 am

raspfly wrote:
PeterO wrote:Please post the contents of /etc/network/interfaces

Are you sure your "airport" can't supply a config for your RPI via DHCP ?

PeterO
What is this airport ?
I hadn't noticed you had hijacked the OP's thread...

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Tue Jul 31, 2012 1:15 am

Burngate wrote:Broadcast is for when one machine wants to talk to all the other machines on the local network. This is the address they would call, and the address it should respond to.

It's normally at the top of the address range, so if your Pi has an address of 192.168.15.3 and a netmask of 255.255.255.0 then the broadcast address would be 192.168.15.255.

If your Pi has an address of 10.0.0.5 and netmask 255.255.0.0 then the broadcast address would be 10.0.255.255

You could set the broadcast address to something different, but you would have to ensure that all machines on your local network, including your router, have the same one. That's why (a) sticking to defaults makes life easier and (b) using DHCP is used - it sets everything on your local network to something consistent.
Thanx

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Tue Jul 31, 2012 1:21 am

vmp32k wrote:The 'lo' interface is the loopback interface, you should keep the 'auto lo' part uncommented (without the # infront) to not break applications that rely on it.

The DNS server address goes into /etc/resolv.conf, like this:
nameserver 192.168.6.10
You can put as many lines in there as you want, though 2 is usually enough.
Here's an example using GoogleDNS via both IPv4 and IPv6:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
Thanx every one :) /etc/resolv.conf entry worked.
I can access internet in Midori browser but APT still cannot access internet. I think i need to provide details like www.example.com : port, username, password in some place, but i do not know where, can any one kindly help me with that.

raspfly
Posts: 132
Joined: Sun May 27, 2012 1:42 am

Re: Static IP

Tue Jul 31, 2012 6:57 am

I found out, those info goes in apt.conf file :)

User avatar
programingfrik
Posts: 1
Joined: Sat Nov 18, 2017 2:12 pm

Re: Static IP

Sat Nov 18, 2017 4:05 pm

I'm having troubles triying to configure an static IP for my Raspberry Pi. I've made experiments with the 2 methods presented in this thread, configuring /etc/network/interfaces and configuring /etc/dhcpcd.conf, neither seems to work. There is some tutorial mentioned on the firsts posts but I don't know where is that. I'm thinking that may be the network configuration should have something to do with systemd, and as these are post from 2012 maybe are outdated.

Has anyone had a static ip configured for her/his raspberry pi on Raspbian 9 (stretch)?

pcmanbob
Posts: 2204
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Static IP

Sat Nov 18, 2017 7:35 pm

Just follow the instructions provided by raspberry.org/learning

https://www.raspberrypi.org/learning/ne ... p-address/

Been the same since Jessie and now stretch.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

jahboater
Posts: 1937
Joined: Wed Feb 04, 2015 6:38 pm

Re: Static IP

Sat Nov 18, 2017 8:26 pm

programingfrik wrote:
Sat Nov 18, 2017 4:05 pm
Has anyone had a static ip configured for her/his raspberry pi on Raspbian 9 (stretch)?
Yes, and it works perfectly - by altering /etc/dhcpcd.conf.

The instructions in the link @pcmanbob provided are good.

mrjordanriver
Posts: 1
Joined: Tue Dec 05, 2017 11:26 pm

Re: Static IP

Wed Dec 06, 2017 6:46 pm

Okay, so the Raspberry Pi Zero W doesn't use an ethernet connection, so will this method of creating a static IP address still work? If not, how can I do this completely wirelessly using PuTTY to connect to my Pi via SSH?

pcmanbob
Posts: 2204
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Static IP

Thu Dec 07, 2017 2:42 pm

Yes it will still work just put your static IP in the settings below "interface wlan0"

just be aware it you move to another wifi network your settings my not be valid.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 11 guests