Use a Raspberry Pi to change default IP Addresses on newly installed devices in a remote Control Panel

We have many control systems out in the field connected to our office using IPSEC VPNs. Each control system needs its own subnet (usually a 192.168.x.x/24) to make this work. So, a problem arises if a new device is added that has a fixed static IP instead of using DHCP. Our router in the control panel will assign IP Addresses using DHCP, but many devices default to a fixed IP out of the box and must be manually configured with a static IP matching the control panel’s subnet.

If you can go on-site, or have someone on-site with some networking knowledge, this isn’t an issue. If you don’t, it can be a huge problem trying to explain to someone how to connect a notebook, give you remote access to that notebook, and plug you into the network so you can change the IP remotely.

A low cost solution is to add a Raspberry Pi to the control panel while it is being built. You can buy DIN rail mounts for the RPi that even protect the power cord from being disconnected. (See https://dinrplate.com/%5Bdrp2%5D ). Once you have the RPi installed and connected to the control panel router, you can give it multiple fixed IPs.

When a new device is installed that needs an IP change, ssh into the RPi, give the RPi’s NIC a second IP address on the new device’s subnet, and make the change. In case you are unaware of using mutliple IPs on a single NIC, they are not required to be on the same subnet and they will not interfere with each other.

Issue with assigning multiple fixed IPs to a Raspberry Pi

The Raspberry Pi OS (I believe since Jessie) uses dhcpcd to manage the network interfaces instead of the traditional networking service like other Linux distributions. The recommended method of setting a static IP (on either the ethernet or wlan interfaces) is to edit dhcpcd.conf . However, dhcpcd only supports a single static IP Address – you are out of luck if you need more.

So, you need to disable dhcpcd, re-enable the networking service, and edit the /etc/network/interfaces file. Before beginning this process, you will need to know your default gateway’s IP and what DNS servers you want to use since this info will be manually entered in /etc/network/interfaces.

If you are doing this re-configuration remotely, be sure to make all the edits before rebooting the RPi so you don’t leave it inaccessible.

Here is the original RPi interfaces file, including the original notes regarding dhcpcd.conf, edited with the new info:

# 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'

# 12/20/21 - dhcpcd service disabled to allow multiple IP addresses on eth0

auto lo eth0 eth0:0
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet static
	address 192.168.73.12/24
	
iface eth0:0 inet static
	address 192.168.1.100/24
	
gateway 192.168.73.1
dns-nameservers 192.168.73.2 

# Include files from /etc/network/interfaces.d:
#source-directory /etc/network/interfaces.d

Note that you are configuring a static IP for the eth0 interface (192.168.73.12) and a second static IP (192.168.1.100) using a new interface called eth0:0 . The new interface syntax is recognized by the networking service at boot and it will create the second IP for the RPi’s NIC.

If you want to do the same with the wlan0 interface instead of the eth0 interface, substitute wlan0 & wlan0:0 in the configuration above. Add this line to the end of the interfaces file, so your network’s WiFi credentials are configured properly (you may need to configure this file manually as well):

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Now that the interfaces file is ready to go, you need to configure the services. First, disable dhcpcd:

$ sudo systemctl disable dhcpcd

Then, enable the networking service:

$ sudo systemctl enable networking

Now perform a reboot:

$ sudo reboot

Testing the new configuration

Run ifconfig to check the assigned IPs:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.73.12  netmask 255.255.255.0  broadcast 192.168.73.255
        inet6 fe80::ba27:ebff:feb9:7135  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:b9:71:35  txqueuelen 1000  (Ethernet)
        RX packets 742587  bytes 51572238 (49.1 MiB)
        RX errors 0  dropped 242159  overruns 0  frame 0
        TX packets 8546  bytes 1113109 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b8:27:eb:b9:71:35  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2  bytes 182 (182.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 182 (182.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Both eth0 & eth0:0 have been configured with the correct addresses.

This procedure is designed to be used from the Terminal on a remote system using ssh. If you are running the GUI on the RPi, it may disable the GUI configuration panels and force you to make all changes to /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf manually going forward.

3 thoughts on “Access a device on another subnet connected to your current network

    1. I believe it will work fine. However, let me run a test tonight and verify the RPi is listening on eth0:0 as well as eth0. In my scenario, I only need to SSH into eth0 and then SSH out of the RPI on eth0:0. In your scenario, you probably need to connect to your Main Pi on the primary address through the gateway and also have your Cluster Pi’s connect to the Main Pi on its secondary IP and I didn’t test for that specifically.

Leave a Reply

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