4

I did a bunch of work with my raspberry pi about a year ago. I got busy with other projects, but have started to work with the pi again. I somehow set my IP address to 192.168.1.123, but I don't see how this is happening. I check the configuration settings on my router, and it says 192.168.1.123 has a dhcp lease on its IP. I check /etc/network/interfaces, and it has no reference to static. If I cycle the power on the pi, each time the IP address gets assigned the same value, as if it was static. How is this possible? Could it be that my router associates the MAC address of my pi with a static IP I assigned in a previous version of /etc/network/interfaces?

Here is the current version of /etc/network/interfaces

pi@raspberrypi ~ $ cat /etc/network/interfaces auto lo

iface lo inet loopback
iface eth0 inet dhcp

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

Here is /etc/wpa_supplicant/wpa_supplicant.conf

pi@raspberrypi ~ $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="LFI92"
key_mgmt=NONE
auth_alg=SHARED
wep_key0=3f8blahblahblah
}
3
  • 1
    Your router may have a MAC mapping. In any event rebooting the Pi will NOT cause the router to allocate a new IP. You should release or renew the IP on the Pi; even then you may get the same, depending on the router's algorithm.
    – Milliways
    Commented Oct 10, 2014 at 22:38
  • THe files above show DHCP is in use, perhaps you set up a DHCP reservation in the router.
    – Tyson
    Commented Oct 11, 2014 at 1:57
  • Normally the DHCP client (your Pi) tries to get the same IP address it received before. When it is still available it will be assigned; if not another one will be choosen. Commented Oct 17, 2014 at 20:03

3 Answers 3

2

Your original configuration using DHCP was most likely fine. You could use a DHCP Reservation to tell your router to issue a particular IP address to your Raspberry Pi every time, rather than using static IP addresses which can cause other issues.

DHCP = Dynamic Host Configuration Protocol, and is the method your network router uses to hand out IP addresses those devices on your network which are configured to use DHCP.

IP addresses are leased by your network router to each device. After a period of time (e.g. 7 days) if the IP address is no longer being used it is returned to the pool so another device can use it.

When set to use DHCP your Raspberry Pi is asking for an IP address and your router responds with one.

You can tell your router to always assign your Raspberry Pi the same IP address, by setting up a DHCP reservation. This will bind an IP address to the MAC address of your device (your Pi).

Setting up a DHCP reservation is usually fairly easy, as long as you have access to your router. The advantages are:

  • Settings are automatically configured by your router including subnet mask, default gateway and DNS servers - all important for network and Internet access from your Pi
  • Accidental IP address conflicts are avoided, so another device won't be given the same IP address as your Pi
  • Connecting your device to another network won't require you to reconfigure it
1

I had an issue in having multiple/more than one WiFi router i wanted to connect with, and to each router with different subnet, ip, ...

Here is the trick:

First to establish connection with WiFi (negotiate protocols, pass), you have 2 options: 1) do it through GUI tool:

  • WiFi config
  • Current Status
  • Scan
  • Double click the network
  • provide pass
  • save it
  • Manage Networks
  • IDString: [b][/b]
  • Priority: 0
  • File -> Save Configuration

2) Do it manually (you have already abovementioned advice from other users). This is what i did set: sudo joe /etc/wpa_supplicant/wpa_supplicant.conf

network={
    ssid="Chupavi D-Link"
    psk="xxx"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    auth_alg=OPEN
    id_str="wifi_oslo"
}

network={
    ssid="rudani"
    psk="xxx"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    auth_alg=OPEN
    id_str="wifi_bg"
}

You will notice that there are TWO networks, and that PSK is the pass that you set to your own pass, same as SSID and other parameters. ID_STR you also choose.

Finally you have to provide IP parameters:

sudo joe /etc/network/interfaces

iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface wifi_oslo inet static
    address 192.168.0.125
    netmask 255.255.255.0
    gateway 192.168.0.1
    network 192.168.0.0
    broadcast 192.168.1.255

iface wifi_belgrade inet static
    address 192.168.2.125
    netmask 255.255.255.0
    gateway 192.168.2.1
    network 192.168.2.0
    broadcast 192.168.2.255

You can see that you simply refer to ID_STR you created in the first step and set any IP parameters you want.

Good luck!

0

I decided to set up a static IP address for wlan0. Here is the new version of /etc/network/interfaces

auto lo    
iface lo inet loopback    
iface eth0 inet dhcp    
allow-hotplug wlan0    
auto wlan0    
iface wlan0 inet static    
address 192.168.1.123    
netmask 255.255.255.0    
network 192.168.1.1    
broadcast 255.255.255.255    
gateway 192.168.1.1    
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf    
iface default inet dhcp
1
  • While this answer is technically fine on its own, you might want to include some explanation of why you have your interfaces file set up this way, as it will be more useful for those who view this Q/A later. Commented Oct 12, 2014 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.