I have a device that is connected to Raspberry Pi via Ethernet cable. The Pi is connected to internet via WiFi. The device should not be visible from the main home network, which has 10.0.0... ip address range. How do I setup a 192.168... subnet on Raspberry’s ethernet so it can communicate with the device via UDP ? The device itself does not need to access wan.
3 Answers
The easiest way is to use static IP addresses, if your device supports that. Give the device IP address 192.168.1.100 netmask 255.255.255.0 and your pi's ethernet adapter the address 192.168.1.101, same mask.
Another fairly easy way would be to buy a cheap router/switch thing with a DHCP server in it. You probably won't need gigabit speeds. This has another advantage: you can connect the "wan" interface to your home-network and allow port forwarding to the Pi. And you will probably have a few spare ports on the 192.168-lan, which can be useful.
Of course, it is also possible to set-up a DHCP server on the Pi. In that case, you can connect the device directly to Pi (no switch or cross-over cables are needed). There are plenty tutorials on how to set-up such a server (see reply by @ingo)

- 2,491
- 9
- 15
-
I think a potential issue with this is you need to be able to configure the connected device with the static IP in advance. – goldilocks Oct 28 '20 at 19:38
-
@goldilocks: not with the second option. At the prices of (second hand) soho-devices, I think that could actually the easiest option. – Ljm Dullaart Oct 28 '20 at 21:23
-
-
This doesn't sound right... have you tried this yourself & seen it work? – Seamus Oct 29 '20 at 02:56
-
@Seamus: what option does not sound right? usig static IP addresses, using a SOHO router or using a DHCP server? I've used the two first, but a DHCP server should not be such a problem. – Ljm Dullaart Oct 29 '20 at 03:46
-
I overlooked the limited aspect of device's networking: no routing to 192.168.1.0/24 from the LAN, and no routing from the device to the LAN. So maybe fixed IP does work... if you can either set the device's IP beforehand or it uses link-local addressing. Otherwise, my apologies for the noise :) – Seamus Oct 29 '20 at 05:25
-
Thanks, @LjmDullaart. I actually tried to set the static IP address before I posted this question and it did not work for me. ifconfig did not show it. It appeared that I needed to actually connect the device to the ethernet in order for the configured IP address to show. All is working fine now. Since the pi is dedicated to serve that device for now I do not need a managed switch yet. – user2555515 Oct 29 '20 at 15:49
-
@user2555515 Can you please create a short answer with your solution and accept it after two days with a click on the tick on its left side? Only accepting an answer will finish your question and prevents it from being shown as a unsolved Post to the community and saves them/us a lot of work. – Ingo Oct 29 '20 at 16:33
You can use systemd-networkd that provides everything out of the box, including a DHCP server. You only have to configure it, no need to install additional helper programs. First setup the WiFi connection. You can Use systemd-networkd for general networking, following section ♦ Create interface file for a WiFi connection.
Then create this file for the wired interface to the device:
rpi ~$ sudo -Es # if not already done
rpi ~# cat > /etc/systemd/network/04-wired.network <<EOF
[Match]
Name=e*
[Network]
Address=192.168.0.1/24
MulticastDNS=yes
DHCPServer=yes
EOF
Because there is no ip forwarding or routing enabled, only the RasPi can connect to the device and there is no way for the device to your local network and vice versa and to the internet.
If the device supports multicast DNS (mDNS) or Link-Local Multicast Name Resolution (LLMNR) you can try to address it with its name, e.g. ping devicename.local
(mDNS) or ping devicename
(LLMNR).

- 42,107
- 20
- 85
- 197
As suggested by @LjmDullaart I set static ip address to ethenet adapter in /etc/dhcpcd.conf
static ip_address=10.0.0.15/24
in section eth0 with no other changes. Please note you will not see the change in ifconfig unless someting is connected to the ethernet port. So now my device is connected to pi and there is no access to it from the outside world, just what I need.

- 113
- 4
-
Please mark the answer as the accepted one with a click on the tick on its left side. That prevents your Question from being shown as an unsolved Post to the community and saves them/us a lot of work. – Ingo Nov 03 '20 at 16:46
hostapd
https://raspberrypi.stackexchange.com/questions/tagged/hostapd You also need a dhcp server; the standard one available in Raspbian isisc-dhcp-server
, aka dhcpd (<- not dhcpcd!) – goldilocks Oct 28 '20 at 15:10hostapd
or anything much butroute
: https://raspberrypi.stackexchange.com/a/37596/5538 – goldilocks Oct 28 '20 at 19:38