My system consists of a host PC that has two ethernet cards. What I want to do is use one for connecting to the inernet and the other to run a private network of Raspberry Pi computers.
My first ethenet card is easy, it's basically grabbing its setting via DHCP from my router. What I need to do is create a different subnet for the second card. So first of all I need to look up current IP address. On linux I can run ip a
I need to find the address and mask from there. In my case it's the line starting inet 192.168.86.36/24
The 24 is mask, in this case the last digit of the IP address are all on the same subnet. See https://www.calculator.net/ip-subnet-calculator.html here if you want to calculate your own range.
For the second card I need to pick a static IP address that's on a different subnet. There are a number of IP address that are reserved for private networks so it's best to use one of these.
Class A- 10.0.0.0 to 10.255.255.255
Class B- 172.16.0.0 to 172.31.255.255
Class C- 192.168.0.0 to 192.168.255.255
Here I picked 192.168.100.1
and used 24 for the Netmask. This means I can have any address from 192.168.100.1
to 192.168.100.254
on my subnet. There are a number of ways of setting these values. I used the graphic network setting dialog to set mine. Don't supply any gateway address.
On your Raspberry pi you can configure static IP address for the ethernet card by editing /etc/dhnpcd.conf
to include for example
interface eth0
static ip_address=192.168.100.10/24
static routers=192.168.100.1
static domain_name_servers=192.168.0.1 8.8.8.8
I should now be able to ssh into the Rasberry pi from the host PC. The pi is not yet connected to the internet, this needs to configured in the hosts firewall.
sudo apt install isc-dhcp-server
edit /etc/dhcp/dhcpd.conf
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.20 192.168.100.254;
option routers 192.168.100.1;
option domain-name-servers 192.168.100.1, 8.8.8.8;
}
subnet 192.168.86.0 netmask 255.255.255.0 {
}
Here we serve IP address on the correct subnet, but importantly not on the WAN subnet.
Edit /etc/default/isc-dhcp-server
to restrict DHCP to the correct interface, in my case
INTERFACESv4="ens1"
INTERFACESv6=""
Then sudo systemctl restart isc-dhcp-server
See https://linuxconfig.org/what-is-dhcp-and-how-to-configure-dhcp-server-in-linux
A list of leases is contained in less /var/lib/dhcp/dhcpd.leases
To view the logs journalctl -u isc-dhcp-server