Difference between revisions of "RPi Setting up a static IP in Debian"

From eLinux.org
Jump to: navigation, search
(Created page with "Using a static IP can be very useful in case you wish to easily access your RPi without need to get its IP address every time it boots or reconnects to the network (i.e. using SS...")
 
(link to related reference.)
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
{{NeedsMerge|Configuring a Static IP address on your Raspberry Pi}}
 +
 
Using a static IP can be very useful in case you wish to easily access your RPi without need to get its IP address every time it boots or reconnects to the network (i.e. using SSH, (S)FTP services).
 
Using a static IP can be very useful in case you wish to easily access your RPi without need to get its IP address every time it boots or reconnects to the network (i.e. using SSH, (S)FTP services).
  
 
To achieve this there are a few quick steps to be followed.
 
To achieve this there are a few quick steps to be followed.
  
You only need to modify the file /etc/networking/interfaces
+
You only need to modify the file /etc/network/interfaces
  
You can edit the file with any text editor such as vi or vim.
+
Before you do, backup the current version of the interfaces file, if there is already one present:
 +
  pi@raspberry: sudo cp /etc/network/interfaces /etc/network/interfaces.sav
 +
 
 +
You can edit the file with any text editor such as nano or vim.
  
 
We need root privileges, so we use sudo:
 
We need root privileges, so we use sudo:
   pi@raspberry:sudo vi /etc/networking/interfaces
+
   pi@raspberry: sudo vi /etc/network/interfaces
 +
 
 +
In the interfaces file look for a line such as:
 +
  iface eth0 inet dhcp
 +
 
 +
This is to enable the DHCP client. You do not want this to work any more.
  
In the file you must put the following content:
+
Put a hash at the beginning of the line to disable it or delete it:
 +
  #iface eth0 inet dhcp
 +
 
 +
In the file you must insert the following lines:
 
   # The loopback interface
 
   # The loopback interface
 
   auto lo
 
   auto lo
Line 25: Line 38:
 
   broadcast 192.168.1.255
 
   broadcast 192.168.1.255
  
Only the address and the netmask data are required.
+
Only the address and netmask data are strictly required.
  
 
If for example your LAN is configured to have IP adresses in the range x.x.x.1 to x.x.x.255, you will put x.x.x.0 in the network line.
 
If for example your LAN is configured to have IP adresses in the range x.x.x.1 to x.x.x.255, you will put x.x.x.0 in the network line.
  
"address" is the IP you want the RPi will assume (in the proper range, as described above). pay attention not to use an IP already used by another device in your LAN or that can be assigned to a device by your router by DHCP (set the DHCP range of the router wisely).
+
"address" is the IP you want the RPi will assume (in the proper range, as described above). pay attention not to use an IP already used by another device in your LAN or that can be assigned to a device by your router by DHCP (set the DHCP range of the router wisely in order to avoid potential overlaps).
  
 
"netmask" will "always" be 255.255.255.0   
 
"netmask" will "always" be 255.255.255.0   
Line 39: Line 52:
  
 
You may now be disconnected from your RPi if you are working through the network. Connect again to the RPi using the static IP you chose and you should now be fine.
 
You may now be disconnected from your RPi if you are working through the network. Connect again to the RPi using the static IP you chose and you should now be fine.
 +
 +
You may receive the following error upon executing this command, and no longer have network access even though the network indicators are active.
 +
"Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfaces"
 +
Solution if you experience this, connect keyboard and "sudo reboot", or do it the hard way.
 +
 +
This command may work if the 'restart' command fails:
 +
  pi@raspberry:sudo /etc/init.d/networking reload
 +
 +
== Fallback to static IP if DHCP fails ==
 +
 +
* [https://www.raspberrypi.org/forums/viewtopic.php?t=84767&p=616362 "dhcpcd: Fallback to static IP configuration if DHCP fails"].
 +
 +
== Further reading ==
 +
 +
* [https://wiki.debian.org/NetworkConfiguration Debian wiki: Network Configuration]
 +
* [http://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address "How to give your Raspberry Pi a Static IP Address"]. (in Raspbian)
 +
 +
[[Category:RaspberryPi]]

Revision as of 14:55, 27 July 2015

Merge-arrows.png

This page is may need to be merged with other page(s) including Configuring a Static IP address on your Raspberry Pi. Please help to merge the articles, or discuss the issue on the talk page.


Using a static IP can be very useful in case you wish to easily access your RPi without need to get its IP address every time it boots or reconnects to the network (i.e. using SSH, (S)FTP services).

To achieve this there are a few quick steps to be followed.

You only need to modify the file /etc/network/interfaces

Before you do, backup the current version of the interfaces file, if there is already one present:

 pi@raspberry: sudo cp /etc/network/interfaces /etc/network/interfaces.sav

You can edit the file with any text editor such as nano or vim.

We need root privileges, so we use sudo:

 pi@raspberry: sudo vi /etc/network/interfaces

In the interfaces file look for a line such as:

 iface eth0 inet dhcp

This is to enable the DHCP client. You do not want this to work any more.

Put a hash at the beginning of the line to disable it or delete it:

 #iface eth0 inet dhcp

In the file you must insert the following lines:

 # The loopback interface
 auto lo
 iface lo inet loopback
 auto eth0
 iface eth0 inet static
 #your static IP
 address 192.168.1.118  
 #your gateway IP
 gateway 192.168.1.1
 netmask 255.255.255.0
 #your network address "family"
 network 192.168.1.0
 broadcast 192.168.1.255

Only the address and netmask data are strictly required.

If for example your LAN is configured to have IP adresses in the range x.x.x.1 to x.x.x.255, you will put x.x.x.0 in the network line.

"address" is the IP you want the RPi will assume (in the proper range, as described above). pay attention not to use an IP already used by another device in your LAN or that can be assigned to a device by your router by DHCP (set the DHCP range of the router wisely in order to avoid potential overlaps).

"netmask" will "always" be 255.255.255.0

gateway is usually x.x.x.1 (your router IP or the one given by your ISP)

You now need to restart the network:

 pi@raspberry:sudo /etc/init.d/networking restart

You may now be disconnected from your RPi if you are working through the network. Connect again to the RPi using the static IP you chose and you should now be fine.

You may receive the following error upon executing this command, and no longer have network access even though the network indicators are active. "Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfaces" Solution if you experience this, connect keyboard and "sudo reboot", or do it the hard way.

This command may work if the 'restart' command fails:

 pi@raspberry:sudo /etc/init.d/networking reload

Fallback to static IP if DHCP fails

Further reading