Raspbian Wheezy Static / fixed IPv4 address

Raspberry Pi: Static / fixed IPv4 address for Raspbian Wheezy
Raspbian Wheezy Static / fixed IPv4 address

Static IPv4 address for Raspbian Jessie (Raspberry Pi)
If you are using the Raspberry Pi for the first time and would like to access it via SSH, you first have to find out the IPv4 address. Cleverly, the Raspberry Pi displays its IPv4 address on the screen after the boot process, provided it is put into operation with the keyboard and screen. Unfortunately, the IPv4 address changes again and again, because the IPv4 address assignment by the DHCP server in the local network is not always assigned the same address, but dynamically any of its address pool.

If you use the Raspberry Pi as a client, that's no problem. But if you want to operate the Raspberry Pi as a server within the local network or often want to access it via SSH, then a fixed IPv4 address is an advantage.

Note: In technical terminology, this is not a "fixed IP address" but a "static IP address" because, in contrast, there are dynamic IP addresses assigned by a DHCP server. In the case of a "static IP address" one speaks of a manual IP configuration.
Note: If you configure static IP addresses, they should not come from the DHCP pool of a DHCP server.
  • Determine a free IPv4 address and further IP configuration.
  • Change the IPv4 configuration to static.
  • Check the IPv4 configuration.
  • Check the network connection for function.
Note on static IPv4 configuration under Raspbian Wheezy on 2015-05-05
The procedure for the manual (static) IPv4 configuration of a Raspberry Pi depends on the distribution and its version. From Raspbian Wheezy on 2015-05-05 something has changed dramatically, so old descriptions, tutorials, and tutorials can lead to faulty network configurations. A popular bug is that a Raspberry Pi suddenly has two IPv4 addresses. Once assigned by DHCP and the second by a manual configuration in the file "/ etc / network / interfaces".

Starting with Raspbian Wheezy on 2015-05-05, a DHCP Client Daemon (DHCPCD) is active by default, which becomes a problem if you want to configure the IPv4 manually.
In order to avoid problems, one should determine whether the "dhcpcd" is active and can influence the network configuration.

The status of "dhcpcd" can be determined as follows.
sudo service dhcpcd status

If the output is dhcpcd: unrecognized service, then the daemon is not installed. Then you can make the manual IPv4 configuration quite regular.

If "dhcpcd" is active then it must be turned off first. Then you have to make sure that it is not restarted when booting.
sudo service dhcpcd stop
sudo update-rc.d -f dhcpcd remove

The latter command ensures that the "dhcpcd" is no longer started at boot time and that only the content of the file "/ etc / network / interfaces" is taken into account in the network configuration.

If you want to be radical, you can remove the "dhcpcd" altogether (not recommended).
sudo apt-get remove dhcpcd5

To undo the operation:
sudo apt-get install dhcpcd5 raspberrypi-net-mods
sudo reboot

Solution: Static / manual IPv4 configuration at Raspbian Wheezy until 2015-05-05 (old method)
To perform the IPv4 configuration statically or manually, open the file with the network settings.
sudo nano / etc / network / interfaces

If this file is empty, then close with "Ctrl + X" and use the following file.
sudo nano / etc / systemd / network

In a fresh system, there are the following lines, among others:
car eth0
iface eth0 inet dhcp
car eth0
allow-hotplug eth0
iface eth0 inet manual

These lines say that the interface "eth0" should get the IPv4 configuration via DHCP. That is, the Raspberry Pi polls a DHCP server on the local network for IPv4 configuration.
If the interfaces "eth0", "wlan0" or similar are set to "manual", then this means that the control and configuration of the interfaces is delegated to a network manager.

The DHCP server then provides, among other things, the IPv4 address, the subnet mask, the default gateway and the DNS server. The same information is required for the static IP configuration.

The lines above are replaced as follows:
# Ethernet
car eth0
allow-hotplug eth0
iface eth0 inet static
dns-domain raspberrypi.local # optional

This is an example configuration. This can work, but does not have to. Just trying it out does not make sense. You should first clarify what you have to enter here and not somehow play around. It helps to see what other clients have in their own network. When assigning the IP address, however, you must make sure that you select an IPv4 address that is NOT used and is not in the address pool of a DHCP server. Otherwise there will be connection problems in the network.

Some example configurations omit the specification of a name server (dns-nameservers). This may lead to problems with the name resolution. In general, there will be problems connecting to the Internet.
The options "broadcast" and "network" can be saved, because this results from the IPv4 address and the subnet mask.

Note: The value "allow-hotplug eth0" is important. If this entry is missing, then you must start the interface manually with the command "sudo ifup eth0". The allow-hotplug option automatically enables and configures the interface for a kernel event.

After making the changes you can save and close the file: Ctrl + O, Return, Ctrl + X.

By default, resolvconf is installed. If not, then the name resolution configuration must be done manually by making the following entries in the /etc/resolv.conf file.
domain localhost raspberrypi.local

One changed only the files now. However, the changes are not yet included in the current configuration. Basically, a reboot is recommended here, if you have made the configuration via SSH.
sudo reboot

Alternatively, you can switch the interface "eth0" off and on again. This is only useful if you are NOT connected via SSH, but sit locally with the screen and keyboard on the Raspberry Pi.
sudo service networking restart
sudo ifdown eth0
sudo ifup eth0

This terminates the eth0 interface and restarts. At startup, the settings are applied. After that, the Raspberry Pi would have to be reachable with its static IPv4 address.

Note: You should not get used to working with "ifdown" and "ifup". If you work locally on the Raspberry Pi, then that's certainly fine. Only if you make the remote via SSH, then you shoot with "ifdown" the interface and then no longer has access for "ifup". Then you have to take the Raspberry Pi from the power and put it back into operation. Unfavorable if you have no spatial access to the Raspberry Pi. So rather make a reboot. If you have not made a misconfiguration, then you can connect again.

Solution: Check IPv4 settings
Whether the IPv4 settings were correctly adopted, you should check.
ip a

The interface "eth0" must then have received the static configured IPv4 address in the line with "inet address".
Then check if the default gateway is registered.
ip r

If "default" points to the correct IPv4 address of the default gateway, then everything is fine.
Now the DNS server is missing.
cat /etc/resolv.conf

Is behind "nameserver" the IPv4 address of the DNS server, then everything is fine here.
Explanation of the file / etc / network / interfaces
How the file "/ etc / network / interfaces" looks depends on the distribution, its version and possibly your own changes. The explanations will be discussed using the original Raspbian Jessie file.
The file looks like this:
# Please note that this file is being used with dhcpcd.
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'.

car lo
iface lo inet loopback

car eth0
allow-hotplug eth0
iface eth0 inet manual

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

car wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

In this file the network configuration for the network interfaces is made. This file lists the interfaces "lo", "eth0", "wlan0" and "wlan1".
The interface "lo" is the so-called localhost. This is a virtual interface for the device. It always has to be there. If not, that leads to multiple mistakes.
The "eth0" interface is the Ethernet interface, which as RJ45 port connects the Raspberry Pi to the LAN via a cable. Another interface, via an Ethernet USB adapter, would be called "eth1" and so on.
The interfaces "wlan0" and "wlan1" are radio interfaces for WLAN or Wifi. However, these interfaces are only available if the kernel has detected a WLAN adapter and was able to install and initialize the driver for it. The configuration of the WLAN authentication can be done via the file "/ etc / network / interfaces" or "/etc/wpa_supplicant/wpa_supplicant.conf".

The initialization of a specific interface is done via the options "auto" and / or "allow-hotplug".
"auto <INTERFACE>" ensures that the interface is enabled during system startup and configured according to the iface entry when the kernel detects the physical interface. "allow-hotplug <INTERFACE>" causes the interface to be enabled and configured according to the iface entry as soon as the kernel receives a hotplug event from the interface. For example, the network cable is plugged into an active port or a configured WLAN is detected. The option "allow-hotplug" also includes "auto".

In the original file, the IPv4 configuration of the interfaces "eth0", "wlan0" and "wlan1" is set to "manual". That is, the control and configuration of the interfaces is delegated to a network manager. "manual" means that this file is not responsible for the IP configuration.
Other parameters for the iface option are static for static IP configuration, which requires additional information, and dhcp for obtaining IP configuration from a DHCP server.

If an interface with "auto <INTERFACE>" means that the interface is booted at system startup. In the case of "wlan0" or "wlan1" would then be searched for an access point and then depending on the configuration for the DHCP server.
If the DHCP server can not be reached because "eth0" does not have the network cable plugged in or because "wlan0" can not establish a wireless connection, the entire system boot process is delayed.
If possible you should omit "auto <INTERFACE>". Then the interface may be started later, but will not delay the boot process.

Raspberry Pi
December 1, 2016



Popular Posts

USB WiFi adapters that support monitor mode and wireless injection

usb wifi adapter with monitor mode and wireless injection (100% compatibl…

how to update Kali Linux and Fix update error

Kali Linux one of the best Linux distro for penetration testing it's freq…

Fix Kali Linux sources.list Repositories

Fix default repository First after installing a clean Kali Linux the sou…

Recent Comments

Contact Me