Static IP Address for Raspbian: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
Line 44: Line 44:
</pre>
</pre>


= Temporary Alias =
= Alias =
 
== Permanent ==
'''NOTE:'''Untested
<pre>
vi /etc/dhcpcd.conf
</pre>
 
<pre>
interface eth0:0
static ip_address=172.18.11.97/27
</pre>
 
 
== Temporary ==
To create a temporary alias rather than a permanent one you can issue the following command from the CLI.
To create a temporary alias rather than a permanent one you can issue the following command from the CLI.
<pre>
<pre>

Revision as of 00:18, 14 September 2016

interfaces

make sure the interfaces file has not been modified.

vi /etc/network/interfaces

The default settings are:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

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

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

dhcpcd.conf

vi /etc/dhcpcd.conf

Append the following. The entry of static will stop the server looking for an IP address from DHCP.

interface eth0
static ip_address=192.168.13.200/24
static routers=192.168.13.1
static domain_name_servers=8.8.8.8 8.8.4.4

Alias

Permanent

NOTE:Untested

vi /etc/dhcpcd.conf
interface eth0:0
static ip_address=172.18.11.97/27


Temporary

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


End of Document.

The following is now deprecated.


NOTE: Using the below seems to work with wheezy but I have pooblems with jessica. The above seems to work and works well for Debian/jessica.

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.

auto eth0
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

auto eth0
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 dhcpcd5

You can also optionally remove

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