To connect multiple Ubuntu devices (clients) to one central Ubuntu server and share the connection securely over a VPN, here’s a detailed, step-by-step guide.
Step 1: Set Up the Ubuntu Server as a VPN Gateway
This server will act as the central point, allowing other devices to connect to it.
1.1 Install OpenVPN on the Server
- Log into your central Ubuntu server.
- Update package lists:
- Install OpenVPN:
1.2 Set Up Easy-RSA for Key and Certificate Management
OpenVPN requires certificates and keys for secure connections.
- Install
easy-rsa
to help with certificate creation: - Create a new directory for the PKI (Public Key Infrastructure):
- Initialize the PKI:
- Build the CA (Certificate Authority) and follow the prompts:
- Generate the server certificate and key:
- Sign the server certificate:
- Generate Diffie-Hellman parameters:
- Copy the keys and certificates to OpenVPN’s directory:
1.3 Configure the OpenVPN Server
- Create a configuration file for the server:
- Paste the following configuration into
server.conf
:
1.4 Enable IP Forwarding for Internet Sharing
- Open
/etc/sysctl.conf
: - Find or add the line below to enable IP forwarding:
- Apply the change immediately:
1.5 Set Up Firewall Rules for OpenVPN
- Allow OpenVPN traffic through the firewall:
- Enable NAT (Network Address Translation) to allow VPN clients to reach the internet through the server:
Replace
eth0
with your server’s network interface if it differs.
1.6 Start and Enable the OpenVPN Service
- Start the OpenVPN service:
- Enable it to start at boot:
Step 2: Set Up VPN Clients (Each of the 10 Ubuntu Devices)
Each client needs its own certificate and configuration to connect securely to the VPN server.
2.1 Create a Certificate for Each Client
On the server:
- Go back to the
~/openvpn-ca
directory: - Generate a certificate and key for each client (e.g.,
client1
,client2
, etc.): - Copy the client’s certificates and keys to a separate directory to transfer them:
2.2 Create Client Configuration File
- On the server, create a client configuration file for each client (e.g.,
client1.ovpn
): - Add this configuration, replacing
your_server_ip
with the server's public IP address:
2.3 Install OpenVPN on Each Client Device
On each Ubuntu client:
- Install OpenVPN:
- Copy the
client1.ovpn
configuration file from the server to each client.
2.4 Connect Each Client to the VPN
On each client device, use the configuration file to connect:
To run this automatically on boot, copy the configuration to /etc/openvpn/client/
as client.conf
and enable the OpenVPN service:
Step 3: Testing and Sharing Data Across Clients
- Verify VPN Connectivity: From each client, ping the VPN server to ensure the connection.
- Enable File Sharing (Optional): Use SSH/SCP or set up an NFS shared folder on the VPN server to allow clients to access shared data.
By following these steps, you will connect 10 Ubuntu devices through a VPN to a central Ubuntu server, securely sharing resources and internet access across the network.