In this article, we will guide you through the process of setting up a VPN (Virtual Private Network) on CentOS using an Ubuntu connection. This will allow you to securely connect to a remote network and access resources as if you were directly connected to that network.
Prerequisites
Before we begin, make sure you have the following:
- A CentOS system with internet access
- An Ubuntu system with internet access, acting as the VPN server
- A non-root user account with sudo privileges on both systems
Installing VPN Software
On the CentOS system, we will be using the openvpn client. To install it, open a terminal and run the following commands:
sudo yum update
sudo yum install openvpn
On the Ubuntu system, we will be using the openvpn server. To install it, open a terminal and run the following commands:
sudo apt update
sudo apt install openvpn easy-rsa
Configuring the VPN Server
On the Ubuntu system, navigate to the /usr/share/easy-rsa/ directory and copy the example.cfg file to a new directory for our VPN configuration.
cd /usr/share/easy-rsa/
sudo cp /usr/share/easy-rsa/example.cfg /usr/share/easy-rsa/myvpn/
Now, navigate to the new directory and edit the myvpn/vars file to set the parameters for the VPN, such as the encryption key size and the VPN subnet.
cd myvpn/
nano vars
Once you have set the parameters, build the necessary certificates and keys by running the following commands:
./clean-all
./build-ca
./build-key-server server
./build-dh
./build-key client
./build-key client2
Now, we need to create a configuration file for the VPN server. Copy the myvpn/openssl-1.0.0.cnf file to a new directory for the server configuration.
sudo cp /usr/share/easy-rsa/myvpn/openssl-1.0.0.cnf /etc/openvpn/server/
Now, create a new configuration file for the VPN server by copying the myvpn/sample-server.conf file and editing it to set the correct paths for the certificates and keys.
sudo cp /usr/share/easy-rsa/myvpn/sample-server.conf /etc/openvpn/server/server.conf
sudo nano /etc/openvpn/server/server.conf
Finally, start the VPN server and enable it to start at boot time.
sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server
Configuring the VPN Client
On the CentOS system, we need to create a configuration file for the VPN client. Copy the myvpn/sample-client.conf file and edit it to set the correct path for the client certificate and key.
cp /usr/share/easy-rsa/myvpn/sample-client.conf /etc/openvpn/client.conf
nano /etc/openvpn/client.conf
Now, start the VPN client and enable it to start at boot time.
sudo systemctl start openvpn@client
sudo systemctl enable openvpn@client
Testing the VPN Connection
To test the VPN connection, try pinging the VPN server from the VPN client.
ping
If the ping is successful, you have successfully set up a VPN connection between the CentOS and Ubuntu systems.
References
| Resource | Link |
|---|---|
| OpenVPN on CentOS 7 | https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-centos-7 |
| OpenVPN on Ubuntu 16.04 | https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-16-04 |
Congratulations, you have now successfully set up a VPN connection between a CentOS and Ubuntu system! This will allow you to securely access resources on the remote network as if you were directly connected to it.
If you have any questions or comments, please leave them in the comments section below. And don't forget to check out our other articles for more helpful tips and tricks!
Thanks for reading, and happy VPNing!