I would like to create static local IP addresses so I can ssh and network Pis easier. I've found some tutorials online for how to make static IP address such as for setting up a public server. Because I'm only networking Pis across a switch, I don't need the extra work of making them publicly accessible. What is the most minimalist way to create only a locally static IP address on raspbian? What range of addresses can I use?
You need to set up a DHCP reservation on your router. DHCP is the protocol used by routers to dynamically assign IP addresses to devices on the network. You can tell the router the MAC address of your Raspberry Pi and the IP address you want it to have, and it will always reserve this address for the Pi, even if it's disconnected for a time. This doesn't require any configuration on the Pi's end.
Routers have all kinds of different interfaces, but I am pretty confident that this is a feature all will have. I can't give a guide for all routers, but here is a tutorial that might help, and Googling around with the name/model of your router will probably turn up more specific results.
As far as I know, you can use just about any IP address in the private network range. I would go for anything with 192.168.1.X where X is from 2 to 255. 192.168.1.1 is usually reserved for the router itself. If you want more info see the Wikipedia article about Reserved IP addresses.
Add the addresses to /etc/hosts on each machine.
192.168.1.66 machine_1 192.168.1.67 machine_2
The 192.168.X.X addresses are non routeable so are quite safe to use.
I believe this command is the true easiest way to set a static IP address
$ sudo ifconfig eth0 your_ip_addr
STEP 1 Find your default gateway IP by
$ route -ne
Under the Gateway column, you will find your Default Gateway IP (192.168.1.0 in my case) for each interface . Note it down .
STEP 2 Find out the IP addresses of your domain name servers by
$ cat /etc/resolv.conf
note down the IP's displayed ( simply copy numbers n text (may be ) after nameserver , ( there will be one / many , just copy them
Generated by resolvconf
nameserver 192.168.1.1 (copy 192.168.1.1 )
nameserver XXX.xx.XX.xx:ff (copy XXX.xx.XX.xx:ff )
nameserver xx.xx.xx.xx (copy xx.xx.xx.xx)
for me i got only '192.168.1.1 '
STEP 3 Editting dhcpdc.conf
$ sudo nano /etc/dhcpcd.conf
you will find few lines with # in the beginning , scroll to the end and add these lines
> IMPORTANT THIS IP'S ARE AS PER MY HARDWARE <
static ip_address=192.168.1.100 #your desired static IP (eth0)
interface wlan0 static ip_address=192.168.1.99 #your desired static IP (wlan0)
static routers=192.168.1.1 #default gateway IP address (from STEP 1)
static domain_name_servers=192.168.1.1 XXX.xx.XX.xx:ff xx.xx.xx.xx #IP’s found in the /etc/resolv.conf file,(from STEP 2) Seperate each IP with a single space.
Save the changes made
Ctrl-X and Y
$ sudo reboot
check that everything is working correctly lets ping Google
sudo ping www.google.com
As others have mentioned, one way to do this is to configure it at the router, and assign a static address that way.
Alternatively, ssh into the pi and set the appropriate settings in your /etc/network/interfaces file. Before you begin you can examine the existing settings by running
One other thing to be mindful of-- set your static IP to something not already taken, I.E. not your gateway or another computer or you'll run into trouble. It is generally easier to find unallocated addresses in the IP range on the higher end of the spectrum.
I believe what OP has marked answered is correct only for temporarily setting it. It will reset on reboot?
The way to do it is to
sudo cp /etc/network/interfaces /etc/network/interfaces.backup sudo nano /etc/network/interfaces
In the nano editor file, ensure you enter the following:
#This is a static IP configuration auto eth0 iface eth0 inet static #Your static IP based on your router config address 192.168.1.xx #Leave the netmask as usual netmask 255.255.255.0 #Your router IP gateway 192.168.1.x auto lo iface lo inet loopback
Make sure you save by CTRL+O to writeout and save.