paint-brush
How VPNs Work: A Simplified Breakdown for Non-Techiesby@jiniuspark
373 reads
373 reads

How VPNs Work: A Simplified Breakdown for Non-Techies

by Jin ParkFebruary 20th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This guide sheds light on the workings of Virtual Private Networks (VPNs) While commercial providers often overpromise, it's essential to grasp the fundamental mechanisms behind their capabilities. We'll use plain-language explanations and simplified Python code samples to illustrate core principles. True VPNs implement IP masking, encryption, and tunneling at deeper system levels for robust real-world protection.
featured image - How VPNs Work: A Simplified Breakdown for Non-Techies
Jin Park HackerNoon profile picture

This guide sheds light on the workings of Virtual Private Networks (VPNs). While commercial providers often overpromise, it's essential to grasp the fundamental mechanisms behind their capabilities.


We'll use plain-language explanations and simplified Python code samples to illustrate core principles.


Important Note: These simulations showcase concepts on a smaller scale—true VPNs implement IP masking, encryption, and tunneling at deeper system levels for robust real-world protection.

Core VPN Fundamentals

  1. IP Address Masking
  • What IP masking is
  • Terminology: IP Obfuscation, Proxy
  • Simplified Python Simulation


  1. Data Encryption
  • Encryption as a data scrambler; emphasis on confidentiality.
  • Terminology: Encryption protocols (AES, etc.)
  • Simplified Python Simulation


  1. Secure Connections (Tunneling)
  • The "private pipe" analogy for establishing secure tunnels.
  • Terminology: Tunneling protocols (OpenVPN, Wireguard, etc.)
  • Simplified Python Simulation


What VPNs Can (and Cannot) Do

  • Enhanced Online Privacy
  • Secure Data Transmission
  • Bypassing Geo-restrictions
  • Limitations of VPNs (no complete anonymity, malware protection, etc.)'

1. IP Address Masking

Mechanism Explanation

Picture your internet traffic as letters you want to mail. Your IP address is your return address on these letters—and your ISP (Internet Service Provider) is like your local post office. They handle and see all your internet traffic coming and going.


VPNs act like a special postal forwarding service. When you connect to a VPN, your letters get rerouted through their hub - the VPN server.


Now, instead of your home address, those letters bear the address of the VPN's postal hub. That's how websites see the VPN server's IP instead of yours.


  • IP Obfuscation/Masking: Think of "masking" as putting on a disguise. IP masking hides your real IP address, making it harder to link your online activity back to you directly.


  • Proxy: A proxy is like a temporary middleman. For this example, a proxy server will briefly make it look like your internet traffic is coming from its location instead of yours.


Simplified Python 'Simulation' Example

While Python can't truly change your machine's IP, we can mimic the idea with a proxy:

import requests

Simulating IP Masking by Using a Proxy

proxy = {   "http": "http://your-proxy-address:port",   "https": "http://your-proxy-address:port", }

url = "http://ipinfo.io/ip" response = requests.get(url, proxies=proxy) print("Masked IP Address:", response.text.strip())

2. Data Encryption

Mechanism Explanation

Imagine your internet data as letters containing sensitive information. Data encryption is like scrambling those letters into a secret code using complex math puzzles.


To make sense of the scrambled message, you need a special key. VPNs use tough encryption methods to turn readable data (like login details or bank info) into this messy code. If anyone (like a snoop on public Wi-Fi) tries to peek at your traffic, all they find is gibberish.


  • Shared Secrets: Only you and the VPN server have matching keys to 'lock' (encrypt) and 'unlock' (decrypt) the data.


Simplified Python 'Simulation' Example

Python won't mimic true VPN encryption, but let's see the principle:

import socket import ssl

Create a Secure Socket Using SSL

context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) secure_socket = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname="www.example.com")


secure_socket.connect(("www.example.com", 443)) secure_socket.sendall("GET / HTTP/1.1\
Host: www.example.com\


".encode())

Receive Data Securely

response = secure_socket.recv(4096) print(response.decode())

secure_socket.close()


Strong Encryption: Real VPNs use encryption (like AES) that's far harder to crack than our example.


Terminology: Encryption Protocols (AES, etc.)

  • AES (Advanced Encryption Standard): Commonly used in VPNs, renowned for its strong security.


Key Points

  • Encryption makes it extremely difficult for outsiders to understand intercepted data.


  • This ensures sensitive information stays safe in transit, especially on public networks.

3. Secure Connections (Tunneling)

Mechanism Explanation:

VPN tunneling involves encapsulating and encrypting each data packet sent over the internet between your device and the VPN server.


This secure "tunnel" prevents outsiders from intercepting, viewing, or modifying the transmitted data. Tunneling protocols, like OpenVPN, establish this secure connection by using encryption and other security measures.


Python Sample Code:

Simulating a VPN tunnel in Python is complex and beyond the scope of simple scripts due to the networking and system-level operations involved. However, you can use Python to create a basic secure connection using SSL with the socket library.


import socket import ssl

Create a Secure Socket Using SSL

context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) secure_socket = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname="www.example.com")


secure_socket.connect(("www.example.com", 443)) secure_socket.sendall("GET / HTTP/1.1\
Host: www.example.com\


".encode())

Receive Data Securely

response = secure_socket.recv(4096) print(response.decode())

secure_socket.close()


Key Points

  • Tunneling defends against snooping, data tampering, and other risks associated with untrusted networks.


Terminology: Tunneling Protocols (OpenVPN, Wireguard, etc.)

  • OpenVPN: Popular, flexible, and secure.


  • WireGuard: Newer, highly streamlined protocol gaining favor for speed and security.


  • IPsec: Core network-level protocol often used to secure VPN tunnels.

What VPNs Can (and Cannot) Do

VPNs Enhance Your Online Experience

  • Enhanced Online Privacy: IP masking and data encryption make it substantially harder for advertisers, your Internet Service Provider (ISP), and potential snoopers to connect your online actions back to you.


  • Secure Data Transmission: Vital on public Wi-Fi! A VPN safeguards your logins, financial details, and other sensitive information that could be easily intercepted on an unsecured network.


  • Bypassing Geo-restrictions: If a streaming service, website, or online content is region-locked, connecting to a VPN server in the appropriate location often helps you access as if you were there.

What VPNs Cannot Do

  • Guarantee Complete Anonymity: Although they make you much harder to pinpoint, factors like browser fingerprinting, cookies, or your online behavior patterns can still leave traces.


  • Protect Against All Forms of Malware and Phishing Attacks: A VPN secures your connection, but it's not a cure-all. Downloading infected files or falling for phishing links remains dangerous, even when using a VPN.


  • Eliminate the Need for Safe Browsing Practices: A VPN is one powerful layer of protection but doesn't substitute common-sense online safety. Stay vigilant about suspicious websites, links, and emails. Always be cautious, even when connected to a VPN.

Important to Remember

When selecting a VPN provider, carefully consider their reputation, features, logging policies, and commitment to user security. Not all VPN services are equal in the protection they provide. It's wise to thoroughly research options before investing your trust.