0

I have an OpenVPN Server on a linux virtual machine (Google Cloud Compute Engine instance running Ubuntu 20.04).

I have a linux laptop in my office (running Ubuntu 20.04). It is connected wirelessly to my office router for internet access. I connected this laptop to the OpenVPN server, so now it acts as a VPN client. I have connected a PLC (Programmable Logic Controller) to my laptop via an ethernet port.

I have another desktop (Windows PC) which is also connected to the OpenVPN Server. So this acts as a second VPN client.

  • IP Address of the VPN Server (Ubuntu Virtual Machine) : 10.8.0.1
  • IP Address of the VPN Client 1 (Ubuntu Laptop): 10.8.0.2
  • IP Address of the VPN Client 2 (Windows PC): 10.8.0.3
  • IP Address of the PLC connected to the Ubuntu Laptop: 10.0.0.60

The goal is to be able to ping the PLC from the Ubuntu Server (Virtual Machine) or the Windows PC (Client 2).

As I understand that they are in different subnets, I configured my Ubuntu laptop to act as a gateway between my VPN connection (tun0) and the ethernet port (eno1). Following are the details corresponding to these adapters from my 'ifconfig output:

tun0

eno1

I performed the following commands to achieve the gateway functionality:

sudo ip addr add 10.0.0.1/24 dev eno1
sudo iptables -A FORWARD -o tun0 -i eno1 -s 10.0.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
(And uncommented net.ipv4.ip_forward=1 from /etc/sysctl.conf)

I am still not able to ping my PLC from any of the other machines (VM or Windows PC).

I am not well-versed with networking. So if there are some other configurations on the Ubuntu laptop or the Virtual Machine that I missed, please let me know. Any help would be appreciated.

1 Answer 1

1

You must configure the openvpn gateway settings on your laptop via the openvpn server. There are examples in the server config file, look for "Thelonious"

Essentially, you will need to create a file on the server in /etc/openvpn/ccd with the name shown in the /etc/openvpn/openvpn-status.log when your client is connected. Inside that file add iroute 10.0.0.0 255.255.255.0. This should configure the client to be a gateway.

You will also need to enable the ccd location, add the route and allow client to client comms in the openvpn server Configuration file. Take a look at the config file comments, they are very good and should cover everything you need.

2
  • Thank you, that was really useful. Initally I had trouble understanding what you were referring to since my server.conf didn't have any comments at all. But I found a sample configuration file on their GitHub page which seemed to have everything you mentioned. Now I am able to ping as desired May 13, 2021 at 15:19
  • 1
    Ah, My mistake for assuming that you would have a commented server.conf, when you install openvpn it normally puts a sample config in place for you I am pleased that you got it working though :) May 13, 2021 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .