GPIO from Arduino or raspberry 2 via network

Hello, everyone,
I don’t know if I’m right here, have the following question:
Is there a way to control / read out the GPIO from a separate Raspberry 2 or Arduino which are connected via a LAN cable? I don’t mean the Raspberry on which Home Assistant is running.
I would like to switch a few switches and read out motion detectors in an area where I have no WiFi but network.

Thanks very much.
Greetings Stephan