Connect two Raspberry Pi 4s directly via Ethernet by assigning static IP addresses on the same subnet and disabling conflicting services like dhcpcd. This creates a stable point-to-point link for file sharing or SSH access without requiring a router, switch, or complex network configuration.
Hardware Requirements and Physical Connection
To establish a direct connection between two Raspberry Pi 4 models, you need minimal hardware. Both devices must have their built-in Gigabit Ethernet ports available. You will also need an Ethernet cable. Modern switches and routers often support Auto-MDI/MDIX, which allows standard patch cables to work regardless of wiring order. However, when connecting two devices directly without intermediate networking gear, it is safest to use a crossover cable to ensure the transmit pins on one device align with the receive pins on the other. If you only have a standard straight-through cable, many modern network interface controllers (NICs) can automatically detect the polarity and adjust internally, but a crossover cable guarantees compatibility across all hardware revisions. Connect one end of the cable to the Ethernet port of the first Raspberry Pi and the other end to the second Pi. Ensure both devices are powered on and connected to their respective power supplies. The link LEDs on the Ethernet ports should illuminate, indicating a physical layer connection has been established. If the lights do not turn on, check the cable integrity and ensure the ports are not obstructed by dust or debris.Configuring Static IP Addresses
The most critical step in this setup is assigning static IP addresses. By default, Raspberry Pi OS usesdhcpcd to request an IP address from a DHCP server via DHCP. Since there is no router or DHCP server in a direct peer-to-peer connection, the devices will fail to obtain an address unless we override this behavior. We must configure a static IP for each Pi on a private subnet that does not conflict with your main home or office network.
A common choice for a direct link is the 192.168.50.x range. Assign 192.168.50.1 to the first Pi and 192.168.50.2 to the second. Do not assign a gateway or DNS server, as these are irrelevant for local-only communication and can cause routing conflicts if the Pi attempts to reach the internet through the wrong interface.
Edit the network configuration file using a text editor with root privileges:
sudo nano /etc/dhcpcd.conf
Add the following lines at the bottom of the file, replacing eth0 with your actual interface name if different (check with ip addr):
interface eth0
static ip_address=192.168.50.1/24
nohook wpa_supplicant
Repeat this process on the second Pi, changing the ip_address to 192.168.50.2/24. The /24 suffix denotes the subnet mask 255.255.255.0, ensuring both devices recognize each other as being on the same local network segment. After saving the file, restart the networking service or reboot the device for changes to take effect:
sudo systemctl restart dhcpcd
Verify the configuration by running ip addr show eth0. You should see your assigned static IP listed under the interface.
Testing Connectivity and SSH Access
Once both Pis have their static IPs configured, test the connection from one device to the other. Open a terminal on Pi 1 and ping Pi 2:ping 192.168.50.2
If you receive replies, the physical and network layers are functioning correctly. You can now establish an SSH session to transfer files or manage the remote device. Use the following command from Pi 1:
ssh [email protected]
Replace pi with your actual username if you changed it during setup. Enter the password when prompted. For enhanced security and convenience, consider setting up SSH key-based authentication so you do not need to type passwords repeatedly. This direct link is ideal for low-latency tasks, such as transferring large datasets between devices or running distributed computing tasks locally.
Note that if you intend to share internet from one Pi to the other over this same cable, you would need to enable IP forwarding and set up NAT (Network Address Translation). However, for simple peer-to-peer communication, no additional routing configuration is required. Adding a default gateway in this scenario would be incorrect, as it might cause traffic intended for the local link to be routed out to your main internet connection incorrectly. For more complex networking scenarios involving multiple devices, see Modem/Router: One to Multiple Computers via Ethernet.
Troubleshooting Common Issues
If the ping fails, verify that firewalls are not blocking ICMP packets. On Debian-based systems, UFW (Uncomplicated Firewall) may be active. Check its status withsudo ufw status. If it is enabled, allow incoming ICMP traffic or SSH connections temporarily for testing:
sudo ufw allow from 192.168.50.0/24
Another common issue is interface naming. While eth0 was standard in older versions, newer Raspberry Pi OS releases may use end0 or similar names due to systemd-networkd integration. Always confirm the correct interface name using ip link before editing configuration files. Additionally, ensure that dhcpcd is not being overridden by NetworkManager or systemd-networkd, which can happen if multiple network management tools are installed simultaneously. Stick to one management tool to avoid conflicts.
For issues related to network masks or PoE configurations that might interfere with standard Ethernet links, refer to Flashed a wrong network mask in a PoE device.
Frequently Asked Questions
Can I use a standard straight-through Ethernet cable instead of a crossover cable?
Yes, most modern Raspberry Pi 4 Ethernet controllers support Auto-MDI/MDIX, which automatically detects the cable type and adjusts the pinouts accordingly. This means a standard patch cable will work just as well as a dedicated crossover cable for direct device-to-device connections.Why did my previous attempt result in "Destination Host Unreachable"?
This error typically occurs because the devices are on different subnets or lack a valid route to each other. Ensure both Pis have static IPs within the same subnet (e.g.,192.168.50.x) and that the subnet masks match exactly. Also, verify that no firewall rules are blocking ICMP echo requests.
Is the Raspberry Pi 4 Ethernet port limited to 100Mbps?
No, the Raspberry Pi 4 features a Gigabit Ethernet controller capable of speeds up to 1Gbps. The limitation to 100Mbps often seen in older models like the Pi 3 is not present here. Ensure your crossover cable is Cat5e or higher to support gigabit speeds.How do I stop these Pis from trying to connect to my main Wi-Fi network?
You can disable Wi-Fi entirely by addingdtoverlay=disable-wifi to the /boot/firmware/config.txt file. Alternatively, you can configure wpa_supplicant to ignore known networks or simply remove the Wi-Fi credentials if they are not needed for this isolated setup.
Can I share internet from one Pi to the other over this link?
Yes, but it requires additional configuration beyond static IPs. You must enable IP forwarding in/etc/sysctl.conf and set up iptables rules to perform NAT (Masquerading) on the Pi acting as the gateway. This turns the direct link into a routed connection rather than a simple peer-to-peer link.