Rpistaticip

From Dawid's Wiki
Jump to: navigation, search

Setup a static IP on Raspbian[edit]

Before doing any work, backup your current interfaces file sudo cp /etc/network/interfaces /etc/network/interfaces.old

Run the following command to obtain your current IP Address sudo ifconfig | grep -A 1 eth0 | grep inet* Make a note of the addr, Bcast, and Mask

Example:
IP Address (inet addr) = 192.168.1.110
Broadcast Range (Bcast) = 192.168.1.255
Subnet Mask (mask) = 255.255.255.0

Run the following command to obtain the Destination and Gateway sudo route -n Make a note of the gateway and destination

Example:
Gateway = 192.168.1.1
Destination = 192.168.1.0

With the information noted, lets run sudo nano /etc/network/interfaces to update the interfaces file

Look for iface eth0 inet dhcp and comment it out using the # character

Right after, insert the line
auto eth0
iface eth0 inet static

which tells the networking interface to use a static IP

After that insert the following lines with the data your gathered previously (make sure you pick an unused IP)
address {your ip address}
netmask {netmask}
network {destination}
broadcast {bcast}
gateway {gateway}

Example:
address 192.168.1.110
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Lastly, restart your networking interface sudo /etc/init.d/networking restart