Static IP Address for Raspbian: Difference between revisions

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


= Static IP Address =
= IPv6 =
To create a static IP address for Raspbian.
I haven't figured out a way for this to work with configuration file dhcpcd.conf.
 
<pre>
<pre>
vi /etc/network/interfaces
vi /etc/network/interfaces
</pre>
</pre>


Change the line
<pre>
iface eth0 inet dhcp
</pre>
to
<pre>
iface eth0 inet static
</pre>
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.
<pre>
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
</pre>
== Add an IP Alias ==
<pre>
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
</pre>
=== Temporary Alias ===
To create a temporary alias rather than a permanent one you can issue the following command from the CLI.
<pre>
ifconfig eth0:0 192.168.22.1/24
</pre>
= Config Example =
Here is an example of my config file.
<pre>
<pre>
auto lo
iface eth0 inet6 static
iface lo inet loopback
address 2321:3fa4:4f7a:d100::1234
 
netmask 56
auto eth0
gateway 2321:3fa4:4f7a:d100::ffff
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
</pre>
</pre>


= Bug =
Edit dhcpcd.conf for name servers
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
<pre>
<pre>
apt-get autoremove dhcpcd5
vi /etc/dhcpcd.conf
</pre>
</pre>


You can also optionally remove
<pre>
<pre>
apt-get autoremove isc-dhcp-client isc-dhcp-common
static domain_name_servers=2001:4860:4860::8888 2001:4860:4860::8844
</pre>
</pre>


[[Category : Raspbian]]
[[Category : Raspbian]]

Revision as of 02:34, 2 April 2017

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

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

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

IPv6

I haven't figured out a way for this to work with configuration file dhcpcd.conf.

vi /etc/network/interfaces
iface eth0 inet6 static
address 2321:3fa4:4f7a:d100::1234
netmask 56
gateway 2321:3fa4:4f7a:d100::ffff

Edit dhcpcd.conf for name servers

vi /etc/dhcpcd.conf
static domain_name_servers=2001:4860:4860::8888 2001:4860:4860::8844