Search code examples
networkingiotopenvpn

connecting iot device with openvpn


I have deployed OpenVPN access server & the client on my system, i want to connect my IoT devices with VPN, how to do that??My guess is if i connect my computer with VPN and with my computer's net i connect my device then they both will be on VPN. Tell me if i am right or tell me other ways. If i do that maybe my sub nets of IPs will change,i am so confused, well my primary goal is to connect the device with vpn and then receive their data on cloud. I am new in networking and all, so it's difficult to do it properly.

i am performing an example, the devices i can take is, esp8266, ultrasonicsensor, esp32 etc... i just want to connect a normal device with vpn so that i can have an image in my mind how it works. lets say for example, if i want to connect this basic ESP8266 with VPN, how will i do that? Should i edit its code in arduino? and provide the VPN ip to it to connect with vpn??? Doing SSH or anything isn't my first priority. My first priority is to somehow connect my esp with vpn, then afterwards if i can ssh, then its much good but for now just help me with doing the baby step.


Solution

  • It depends on the way that you configured your OpenVPN connection. It doesn't matter what is your client on the IoT device, but it matters what interface it binds your connection on your system. When you connect to another network (here, your server of course) via OpenVPN, it creates a virtual interface called "TUN" or "TAP" which are quite different. You need to create an OpenVPN server on your system, to connect the IoT device to the machine. Then you have two interfaces and it means you need to connect these two somehow. The first interface is for connecting to your server, and another is for handling your clients (IoT devices) If it's a TAP device, you can create a bridge between two interfaces.

    • tap0: YOUR_SYSTEM ==> SERVER
    • tap1: IoT_DEVICE ==> YOUR_SYSTEM
    • br0: TAP1 <==> TAP0

    But, if it's a TUN device (which is more common), then you need to FORWARD/ROUTE all packets from tun0 to tun1 and vice versa. The tool that you can handle this with, depends on your OS on the system. In Linux, you can use iptables.