Static IP Address

As the device asks DHCP server for IP address when it connects, the IP address changes over time. Static IP allows the device reserves an IP address and doesn’t change over time. It is not compulsory but highly recommended. A static address allows quick access if you would like to setup remote access in LAN, and it’s essential if you would like to run a server and allow access from internet via NAT.

Static IP can be configured on router or on Raspberry Pi. To eliminate the possibility of IP address conflict, configure on router is recommended.

To configure on router:

First, check your MAC address by the following command:

  • ifconfig <interface>

If you’re using ethernet cable, the interface would be “eth0”.

If you’re connected to wifi, the interface would be “wlan0”.

The HWaddr is the MAC address and the inet addr is the IP address we need, record these addresses.

Second, login to your router, look for static IP settings. It’s usually under or close to DHCP Server settings. Enter the MAC address and IP address recorded before and save. If you like (and you know how it works), you may also bound the device to another IP address.

This IP address now permanently belongs to your pi on your network. Reboot the device to make it in effect.

To configure on Raspberry Pi:

First, check your default gateway and DNS settings by the following commands:

  • ifconfig <interface>
  • route

If you’re using ethernet cable, the interface would be “eth0”.

If you’re connected to wifi, the interface would be “wlan0”.

For the first command, The inet addr is the device IP address and mask is subnet mask we need, record these address. We also need the Bcast address.

For the second command, the gateway address for default destination is the IP address of the router, we need these as well.

Second, edit the interface file by command:

  • sudo nano /etc/network/interface

Find the appropriate interface, Enter the detail as the following format under it:

  • iface <interface> inet manual static
  •     address <IP address of Raspberry Pi>
  •     netmask <subnet mask>
  •     gateway <IP address of router>
  •     network <Bcast address, replace the last 255 with 0>
  •     broadcast <Bcast address>

Originally, The last word of the first line is manual and we need to replace it with static. You may also use another IP address if you like (and know what you’re doing).

Third, we also need to update DNS address on resolv.conf:

  • sudo nano /etc/resolv.conf

Enter the detail as the following format at the end:

  • nameserver <IP address of router>

If you’re using another DNS server, you can use the one you prefer.

Note that this method may result in IP conflict, therefore it’s not recommended. Reboot your Raspberry Pi to make them in effect.

Leave a Reply