The Raspberry Pi & local home networking — my experience

The Raspberry Pi and local home networking

Raspberry Pi's are popularly connected to a LAN with an internet connection. When many Pis are connected, their IP addresses need to be managed.

Introduction to home networking

A local area network (or LAN) is a computer network that connects devices (e.g. Raspberry Pis) within a limited area. In this case, the LAN is limited to a house or business premises.

The local network is managed by a network router. Devices are connected directly using an Ethernet cable, or wirelessly using Wi-Fi. Each device on a network has a unique IP that serves as an address for that device.

Local home networking hotel

Local home networking hotel.

The LAN can be seen as a hotel, occupied by guests. In the beginning, there is only the reception area, the kitchen and maybe one or two occupants. As the hotel gets popular, more guests will have to be accommodated at the same time.

Using the hotel analogy, the guests are devices and the kitchen is an example of another network protocol. The reception area, which has its own number, is the place where the clerk (the router) does his or her job of managing the hotel guests by assigning room numbers to them. Each room will have its own number, which is similar to an IP address.

Connecting a Raspberry Pi to a LAN

Raspberry Pis are made to connect to a LAN. This will allow the installation of new packages, the update/upgrading of existing packages, and access to the Raspberry Pi from a remote location. It will also allow the Raspberry Pi access to remote devices on the network.

The newer generation Raspberry Pis (Model 2B, 3B, 3B+ and 4B) are easily connected using their Ethernet port and since the Raspberry Pi 3 models, onboard Wi-Fi can also be used.

By connecting the Raspberry Pi to the network using the Ethernet cable, connectivity will be established automatically. Using Wi-Fi will be wireless, but is slightly more complex to connect.

A dynamic (vs. static) IP address will be assigned to the connecting Raspberry Pi in both cases. To see the latest IP address of the Raspberry Pi after it has been connected to a network, the hostname terminal command can be used:

hostname -I

The Raspberry Pi’s IP address is required for remote devices to connect to it.

Static vs. dynamic IP addresses

In a hotel, some guests will book any room that is available, while others will book the same room each time they stay over.

This is the same when devices connect to a network. Some devices will be assigned a new IP address each time it is connected (dynamic IP address or DHCP), while other devices will be assigned the same IP address (static IP address).

On a network, like the guests choosing their rooms, the connecting device determines whether the IP address should be dynamic or whether it should be static. By default, most devices are configured to have a dynamic IP address, until the device is configured otherwise (i.e. is set to have a static IP address).

If the device is configured to have a dynamic IP, the router (or “clerk”) will assign one depending on what IPs (or “rooms”) are available. If the device is configured to have a static IP address, the router will try to assign that IP address instead — if it is available.

IP address patterns and ranges

Just like hotels have different ways to number their rooms, e.g. adding floor numbers, networks can have different ways too. When looking at an IP address on a LAN, it will usually look similar to one of these:

  • 10.0.0.x
  • 192.168.1.x
  • 196.182.1.x

These are referred to as the network’s IP address pattern and are determined by the router. There might be other patterns too, but unless you’re able to set this manually, rather stick to the network’s default pattern.

Within this pattern, there will be an IP range (or IP pool range). Smaller LANs, like the ones used at home or small businesses, have relatively small IP ranges. The x will usually be in the range of 2 to 254.

Larger networks might have ranges, for example, of 10.0.0.0 through 10.255.255.255 or 192.168.0.0 through 192.168.255.255.

Static IP addresses

When the guest’s room is always the same each time they visit the hotel, getting hold of this guest, e.g. on the room’s telephone line, is much easier.

Setting a static IP address on a device (often done on Raspberry Pis) will make it easier to find that device on the network. The need to find, for example, a Raspberry Pi on the same network location each and every time is often seen in these cases:

  • Using SSH or SCP protocols, for example using PuTTY, WinSCP or other Raspberry Pis
  • Programming python and bash commands
  • Mounting network directories to a Raspberry Pi
  • Sharing a Raspberry Pi’s directories on a network

IP ranges and planning the network

To prevent unhappy guests, sometimes the hotel’s booking process will need some rules and planning. If a regular guest that always likes a certain room is proven to be unpredictable, it’s better to keep that room open in case the guest arrives.

The network router can have devices with static IP addresses and devices with dynamic IP addresses connected at the same time — as long as the router is not reserving dynamic IP addresses in the place of a static IP address. This is similar to the clerk is not trying to book guests into the same room.

When already connected, a device with a static IP address will take preference over those that are configured to have dynamic ones. This means that the first step is to prevent two devices from having the same static IP address. If this is not the case, the one connecting last will not be able to establish the connection.

Secondly, when a static IP address is going to be configured on a device, the following rules should also be followed:

  • Do not use the first address of the network, i.e. the address that ends with .1. It is reserved for the router.
  • Do not use addresses that end with .0 or .255. They are typically reserved for network protocols.
  • Only use addresses within the IP range .2 to .254.
  • Do not use addresses outside the reserved IP range (see below for what this is).

The router can also help to plan static IPs by setting an IP range reserved for dynamic addresses. By having the IP range for dynamic IPs, static IPs can be planned not to fall within this range.

The range for dynamic IP addresses is set under the router’s local network settings, usually in the same area as setting/enabling DHCP.

If for whatever reason DHCP ranges cannot be set using the router, the concept of IP ranges can be used.

Looking at one or two dynamic IP addresses can give an indication of what range the router uses for these IPs. Some literature suggests that DHCP will fall between xxx.xxx.x.100 and xxx.xxx.x.149. Most of mine are generated from about xxx.xxx.x.60 onward.

If the full IP range is between .1 and .255 and we envision the IP range as low, medium and high, this enables us to more or less predict what IP range to prevent for static addresses. These are the IP ranges I use for my own network — yours might be a bit different:

  • Low (potential static range): xxx.xxx.x.2 to xxx.xxx.x.59
  • Medium (dhcp range): xxx.xxx.x.60 to xxx.xxx.x.149
  • High (potential static range): xxx.xxx.x.150 to xxx.xxx.x.244

Conclusion

This post discussed my experiences with the Raspberry Pi and local home networking. Raspberry Pis are commonly connected to a LAN and commonly need a static IP address assigned to access them.

In order to prevent conflicts between Raspberry Pis on a network, static IPs need to be planned. This is done by following some rules and by voiding IPs that fall within the dynamic IP range.

Leave a Reply

Your email address will not be published. Required fields are marked *