I am purchasing another RPi because my original is broken, but not entirely, so I would like to chain them together via and ethernet cable. Each Pi will also have access to the internet via wifi, but can I take the wifi adapter out of the first and use ssh via the local connection made by the ethernet cable? Is there any software I need for this, and how whould I go about doing this?
This is using a regular (not cross-over) ethernet cable, although I think it is the same either way (contemporary NICs, including the one on the pi, don't require a cross-over).
I don't use normal network autoconfiguration; in order to try this you'll probably have to disable that (see here).
I attached wifi adapters to both pis so I could ssh in and configure them, since they are headless, then plugged an ethernet cable between them. After booting the wifi adapters were on and the lights came on both sides of the cable indicating a link.
All commands require root privileges or
First, the interface has to be set "up":
ip link set eth0 up
Next, set a private subnet IP address on the interface, such as:
ip addr add 10.66.66.1/24 dev eth0
This is the point where I first got snafu'ed. If you don't specify the CIDR mask explicitly (
/24 in this case), the system may use
/32. This would make that address the only one on the subnet, meaning you won't be able to reach anyone else this way.
To explain the CIDR address and mask briefly:
10.x.x.xis reserved for private networks, i.e., there are no WWW IPs here, so you can use them for your own purposes. Sometimes LAN routers use them; the other common one is
192.168.x.x. You can use that instead, but notice it has fewer x's, meaning it's smaller.
The mask: Each number in an IPv4 address is 8 bits wide, and the mask indicates how many bits starting from the left hand side are significant. The reason
/32isn't much good for anything is because it means all four numbers must be a match (i.e., there's only one possible address, and it's yours).
/24indicates only the first three must match, and by using
10.66.66I've hopefully avoided any other subnets which might be set on another interface. If you don't have any
10.address on your LAN, you can use anything there, and
/8to indicate only the
The other pi I set to
10.66.66.2/24. Then I tried pinging from one to the other, which should work as long as you don't have any iptables (firewall) rules preventing it.
I could then also use
ssh over the eth0 interface from one pi to the other and shut wifi down and remove the adapter on the other pi. If you enabled this at boot, you could thus connect to the other pi without any wifi or other network attached.
With one of the pi's off the main LAN, i.e., just connected to to the other one via an ethernet cable, you can forward requests through the other pi that does have wifi connected. Referring to the latter as "outside" (with the .1 address) and the former "inside" (with the .2 address):
On the outside pi:
sysctl -w net.ipv4.ip_forward=1 iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
If you already have firewall rules, you'll have to do more than that to allow traffic:
iptables -I FORWARD -i eth0 -o wlan0 -j ACCEPT iptables -I FORWARD -i wlan0 -o eth0 -j ACCEPT
On the inside pi:
ip route add default via 10.66.66.1
If you get a comment WRT to the address already existing,
ip route del default first. I had a problem the first time I tried all this, after disabling the wifi then setting the route using ssh (from outer to inner), despite using the eth connection for ssh. However, it worked fine by setting the route, then disabling the wifi (which requires removing the default first).
You should now be able to, e.g.,
ping 220.127.116.11 from the inside pi and do all other internet-y things normally.
You can automate this by scripting the commands in order; this works at boot via
/etc/rc.local with no wifi on inner.
Yes, you can do it.
You can use a crossover cable, but you don't need one (most modern interfaces automatically detect).
You don't need any special software. (At least if you are running a recent version of Raspbian which uses
The hard part is finding the IP of the "slave". I have
avahi on my Pi so I can "discover" with hostname.local. (You probably want to make sure each has a unique
hostname). I am pretty sure
avahi starts automatically on newer kernels, or by
I connect with
ssh to work over a link-local address, otherwise you may need to use
dhcp or assign static IP.
One drawback of the above is that the date will not be set. You can copy the date from the host by running
ssh email@example.com sudo date -s$(date -Ins) before connection.
I would recommend using a Crossover Cable between the two pis. This would be the fastest network you could make with two pis.
Then you could create a small network between the two pis on the ethernet interfaces. The netmask, network, and broadcast needs to be the same in order for them to see eachother, but the IPs obviously needs to be different. Or, you could use a dhcp server on one of the pis to assign an ip automatically to the other one.
An alternative to using a crossover would be to use two normal ethernet cables, and plug each pi into a single switch. You will still need to static each pi, or use a dhcp server.