Static IP Address for Raspbian: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
Line 71: Line 71:
To fix this problem if DHCP is not required
To fix this problem if DHCP is not required
<pre>
<pre>
yum autoremove dhcpd5
apt-get autoremove dhcpd5
</pre>
</pre>



Revision as of 05:45, 3 June 2015

Static IP Address

To create a static IP address for Raspbian.

vi /etc/network/interfaces

Change the line

iface eth0 inet dhcp

to

iface eth0 inet static

and add the following lines immediately after the line above otherwise adding the lines to the end of the file will assign the information to the wireless network wlan0.

address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

Add an IP Alias

iface eth0:0 inet static
address 192.168.22.1
netmask 255.255.255.0
network 192.168.22.0
broadcast 192.168.22.255
auto eth0:0

Temporary Alias

To create a temporary alias rather than a permanent one you can issue the following command from the CLI.

ifconfig eth0:0 192.168.22.1/24

Config Example

Here is an example of my config file.

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.13.252
netmask 255.255.255.0
network 192.168.13.0
broadcast 192.168.13.255
gateway 192.168.13.254

iface eth0:0 inet static
address 192.168.22.1
netmask 255.255.255.0
network 192.168.22.0
broadcast 192.168.22.255
auto eth0:0

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Bug

As of 3rd June 2015 there is a known bug with Raspbian that always obtains an IP address from DHCP even if a static IP address is configured. This means that the rPi will obtain 2 individual IP address on the NIC. the static been the primary and the DHCP IP been the additional.

To fix this problem if DHCP is not required

apt-get autoremove dhcpd5

You can also optionally remove

apt-get autoremove isc-dhcp-client isc-dhcp-common