Author Topic: Static IP for the Pi gateway? HOW to do it?  (Read 14566 times)

LaneF

  • NewMember
  • *
  • Posts: 47
Static IP for the Pi gateway? HOW to do it?
« on: September 26, 2015, 01:43:22 PM »
I've been scouring the web looking for instructions to create a static IP.

I found one site with following instruction.  I think the instructions are good but somethings missing, location, directory tree, something.

Quote
sudo nano /etc/network/interfaces
Remove the line that reads
iface eth0 inet dhcp
Add the following
iface eth0 inet static
address 192.168.0.6
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
Save the file by pressing CTRL-X and select Y to save the changes.

After the save command I release all attached leases with:
Quote
sudo rm /var/lib/dhcp/*

Issue the reboot command:
Quote
sudo reboot

The Pi reboots with two lines of warnings that the Interfaces "FAILED" in BIG RED LETTERS

Does anyone have the missing link on why the Static IP wouldn't work or perhaps a link to a great article or post on the topic?

Thanks
Lane F
« Last Edit: September 28, 2015, 11:39:28 AM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Install Static IP ??? HOW ?
« Reply #1 on: September 27, 2015, 10:35:48 PM »
Hi Lane,
I think better than doing that is going into the router configuration and reserving a specific IP for the Pi on the DHCP list.
My router allows picking the IP I want and then either type in the MAC address or pick an already DHCP-ed device and assign it that MAC, then the router restarts and the device should now always have that IP while reserved/paired with its MAC id.
That's why I left DHCP enabled on the Pi image i published, since it can be a bit daunting to set a static IP on the Pi itself. This way you don't have to guess your way through your network settings, just go in the router, assign a specific DHCP IP to the device and you're done.
I hope this helps.

Note that different images on the Pi will likely yield different MACs and your router will assign different IPs, which is probably a good thing.

LaneF

  • NewMember
  • *
  • Posts: 47
Re: Install Static IP ??? HOW ?
« Reply #2 on: September 27, 2015, 11:53:26 PM »
Felix,

Great idea... I made it too hard.

"Sometimes a Zebra's just a Horse"

Lane

MikesTechBlog

  • NewMember
  • *
  • Posts: 21
    • Mike's Tech Blog
Re: Static IP for the Pi gateway? HOW to do it?
« Reply #3 on: May 17, 2016, 03:40:09 PM »
I set static IP's on linux PC's all the time. Including my Pi gateway. You should only have to edit the /etc/network/interfaces file. As far as "releasing all attached releases" like you mentioned in issuing the sudo rm /var/lib/dhcp/* command, I believe that is only if you are setting up your raspbi as the dhcp server, as opposed to setting up a static IP for it.

All I have ever done is edit the/etc/network/interfaces file and do the following:

# The primary Network Interface
auto eth0
iface eth0 inet static
        address 192.168.0.6
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1


Save the file, and reboot. - Of course these numbers are for your specific network. Those with different address range (such as 192.168.1.x) will need to make the appropriate changes.
My Tech Blog:

Mike's Tech Blog

captcha

  • Full Member
  • ***
  • Posts: 108
  • Country: au
Re: Static IP for the Pi gateway? HOW to do it?
« Reply #4 on: May 17, 2016, 07:04:31 PM »
Not trying to confuse further, but I think the 'network' and 'broadcast' entries can be left out entirely as the netmask line already defines these values. I never add these lines to my /etc/network/interfaces and it works just fine. Makes the file look a little neater too.

You'll also need to set a DNS server if you ever want to run updates on your Pi or simply access the Interwebs from it.

The dns address goes in /etc/resolv.conf

Example /etc/resolv.conf
Code: [Select]
search .
nameserver 192.168.0.1

(Assuming that your dns server is also hosted on your gateway)

jra

  • Jr. Member
  • **
  • Posts: 81
  • Country: us
Re: Static IP for the Pi gateway? HOW to do it?
« Reply #5 on: May 17, 2016, 08:33:19 PM »
How much control do you have over your local dhcp server and/or dns server?  What I do for all of the various laptops/PC's/smart phones/pi's/esp8266's/etc. I have laying around is to determine what their MAC addresses are and then configure dhcp/dns to map the MAC addresses to fixed names/addresses.  That way all of the clients can continue to use dhcp but they will be assigned known/consistent IP addresses, names, netmasks, gateways, NTP servers, etc.  that can be maintained in a central location. That way if you travel with your laptop/smartphone you don't need to constantly reconfigure it to use dhcp on the road and static addresses at home.