How to Set Up Peer-to-Peer VPN with Tinc on Ubuntu 22.04

How to Set Up Peer-to-Peer VPN with Tinc on Ubuntu 22.04

How to Set Up Peer-to-Peer VPN with Tinc on Ubuntu 22.04

Author: Łukasz Bodziony

Email: lukasz@bodziony.net.pl

DevOps Services: bodziony.net.pl

Published: June 2025

Introduction

Tinc is a mesh VPN daemon that supports peer-to-peer encrypted tunnels. Unlike hub-and-spoke VPNs, Tinc dynamically builds a full mesh network, allowing each node to communicate directly. In this tutorial, Łukasz Bodziony walks you through installing and configuring Tinc on Ubuntu 22.04 to create a resilient P2P VPN.

Prerequisites

  • Two or more Ubuntu 22.04 servers (or VMs) with public or private IPs
  • Sudo/root access on each node
  • Firewall ports UDP 655 (customizable) open between peers

Step 1: Install Tinc

sudo apt update  
sudo apt install -y tinc

Step 2: Create VPN Network Directory Structure

On each node replace myvpn with your desired network name:

sudo mkdir -p /etc/tinc/myvpn/hosts  
sudo mkdir -p /var/lib/tinc/myvpn

Step 3: Generate RSA Keys and Host Config

On each node:

sudo tincd -n myvpn -K4096

Create /etc/tinc/myvpn/tinc.conf:

Mode = switch  
Name = <nodename>  
AddressFamily = ipv4  
Interface = tinc-myvpn

Step 4: Configure Host Files

On each node edit /etc/tinc/myvpn/hosts/<nodename> and include:

Name = <nodename>  
Address = <node-IP-or-dns>  
Port = 655  
# PublicKey follows  
<Paste the public key from /etc/tinc/myvpn/rsa_key.pub>

Then copy each host file to all other peers:

scp /etc/tinc/myvpn/hosts/<nodename> user@peer:/etc/tinc/myvpn/hosts/

Step 5: Configure VPN Interface IPs

Create /etc/tinc/myvpn/tinc-up (make it executable):

#!/bin/sh  
ip link set $INTERFACE up  
ip addr add 10.0.0.<node-id>/24 dev $INTERFACE

Create /etc/tinc/myvpn/tinc-down:

#!/bin/sh  
ip addr del 10.0.0.<node-id>/24 dev $INTERFACE  
ip link set $INTERFACE down

Make both scripts executable:

sudo chmod +x /etc/tinc/myvpn/tinc-up /etc/tinc/myvpn/tinc-down

Step 6: Start Tinc Daemon on Each Node

sudo systemctl enable tinc@myvpn  
sudo systemctl start tinc@myvpn  
sudo systemctl status tinc@myvpn

Step 7: Test Connectivity

Ping peers over the VPN interface:

ping -c 3 10.0.0.<peer-node-id>

Conclusion

You now have a fully meshed P2P VPN running on Ubuntu 22.04 using Tinc. Each node can communicate directly with any other, making your network robust and scalable.

🚀 Run your P2P VPN on a high-performance Linux VPS: netcloud24.com/servers/vps-linux/

© 2025 Written by Łukasz Bodziony – All rights reserved.

Comments

Popular posts from this blog

How to Install Moodle LMS on Debian 12 Server - Manual & Docker

How to Install and Configure GlusterFS on Ubuntu 24.04

How to Install OpenEMR on Ubuntu 24.04 Server - Manual & Docker