πŸ•ΉοΈ
Ghoulsec Vault
Website Toolbase
  • Welcome !
  • πŸ—ƒοΈExam Prep Notes
    • πŸ“”CEH V13 (Master Edition)
      • Module 02: Footprinting and Reconnaissance
      • Module 03: Scanning Networks
      • Module 04: Enumeration
      • Module 05: Vulnerability Analysis
      • Module 06: System Hacking
      • Module 07: Malware Threats
      • Module 08: Sniffing
      • Module 09 : Social Engineering
      • Module 10: Denial of Service
      • Module 11: Session Hijacking
      • Module 12: Evading IDS, Firewalls , Honeypots
      • Module 13: Hacking web servers
      • Module 14: Hacking Web Applications
      • Module 15:SQL Injection
      • Module 16: Wireless Attacks
      • Module 17: Hacking Mobile Platforms
      • Module 18: IoT & OT Hacking
      • Module 19 : Cloud Computing
      • Module 20 : Cryptography
    • πŸ“˜ISC2 -Certified in Cyber Security
      • Chapter -1 Security Principals
      • Chapter -2 Disaster Recovery,Business Continuity & Incident Response
      • Chapter -3 Access Control Concepts
      • Chapter -4 Network Security
      • Chapter -5 Security Operations
    • πŸ“—AZ - 900
      • Basics of Cloud Computing
        • Economic of Scale
        • CapEx & OpEx
        • Consumption based model
        • Cloud Deployment Models
        • Shared Responsibility Model
        • Data centers, Regions & Availability Zones & Geographyies in Azure
        • Resources & Resource Group
        • Azure Access Tools
        • Azure Service Lifecycle
        • Azure SLAs
        • Azure Cloud Adoption Framework
      • Azure Services
        • Azure Computing Services
        • Azure Networking Services
        • Azure Storage Services
        • Azure Database Service
        • Azure Marketplace
        • Big Data & Azure
        • Azure Serverless Computing
        • IoT & Azure
        • Other Azure Services
        • Azure Resource Locks & Resource Tags
        • Azure Security Services
          • Security Groups
          • Routing Tables
          • Azure Firewall
          • Azure DDOS Protection
          • Azure Identity & Access Management (Azure AD)
          • Azure RBAC
          • Azure Security Center
          • Azure Key Vault
      • Azure policies & Blueprints
      • Azure Cost Management
      • Azure Core Tenents
    • πŸ“—SC - 900
      • Zero Trust Model
      • Shared Responsibility Model
      • Defense in Depth
      • Security Controls
      • CIA Triad
      • Encryption / Hashing / Signing
      • Microsoft Security & Compliance Principals
      • Common Identity Attacks
      • Microsoft Identity as Primary Security Perimeter
      • Modern Authentication with Azure AD
      • Azure AD Identity Types
      • Azure External Identities
      • Hybrid Identities
      • Authentication Methods & Password Protection
      • Conditional Access
      • Azure AD Roles & RBAC
      • Governance in Azure AD
      • Azure Identity Protection
      • Azure NSG, DDOS, Firewall
      • Azure Bastion & Keyvault
      • Azure Encryption
      • Azure CSPM
      • Azure Security Center
      • Azure Defender
        • Microsoft O365 Defender
        • Azure Sentinel
      • Microsoft Cloud App Security
      • Microsoft Intune
      • Microsoft Complaince Manager
      • Information Protection
      • Microsoft insider risk capabilities
    • πŸ“”AWS Cloud Practitioner
      • Cloud Deployment
        • AWS Global Infrastructure
      • AWS Cloud Essentials
        • AWS SNS
          • AWS SQS
      • AWS Compute & Container Services
        • AWS EC2
          • Elasticity & Agility
        • AWS Serverless Computing
        • AWS Container Services
        • AWS Beanstalk
        • AWS Load Balancing
      • AWS Storage & Databases
      • AWS Networking
      • AWS Security
        • AWS Organisation
        • AWS Compliance
        • AWS DDOS
        • Additional Security Services
      • AWS Monitoring & Analytics
        • Other Analytics Services
      • AWS Pricing & Support
      • AWS Migration & Innovation
        • Migration Statergies
        • AWS Snow Family
        • AWS Transfer Family
        • Innovation on AWS
      • AWS Well Architecture Framework
      • Other AWS Services
  • πŸ§‘β€πŸ’»Cyber Security Base
    • Ghoul's Den
    • Cheatsheets
    • SSL Handbook
      • Installing OpenSSL
      • Encrypting Web Servers using SSL
      • Compiling .pfx file using openssl
      • De-compiling .pfx file
      • Zimbra Mail Server SSL renew
      • SSL Certificates
    • ☁️Cloud Security
      • Amazon Web Services (AWS)
        • AWS - IAM & Policy Management
        • AWS Organization
        • AWS - Roles (Assume Role)
        • AWS - EC2 (Elastic Computing)
        • AWS - VPC
        • AWS - Bastion Host
        • AWS Application Load Balancer
        • AWS Auto Scaling Group
        • AWS WAF
        • AWS - VPC Peering
        • AWS Transit Gateway
        • AWS NAT Gateway
        • AWS - Route 53
        • AWS Certificates Manager
        • AWS Network Load Balancer (NLB)
    • πŸ•ΈοΈNetwork Security
      • Firewalls
        • Sophos - Security Suite
          • Sophos Firewalls
      • VPN
        • VPNs
          • Wireguard Tunneling
          • StrongSwan Gateway VPN Server on Ubuntu
      • IP Address and IP Subnetting
      • Basic to Advance Networking Materials
    • πŸ§‘β€πŸ’»VAPT
      • Sample Report Templete
      • OWASP
        • OWASP Web Application Security & WebGoat
      • Web Application testing checklist
        • Client Side Penetration Testing
          • Clickjacking
          • Websockets
          • CSRF
          • XSS Filters
        • Server Side Penetration Testing
        • Advanced Web Application Pentesting
          • OAuth
          • JWT Injection
          • Server Side Templete Injection
    • β˜„οΈGRC
      • ISMS AUDIT PLAN
      • CIS Compliance Windows
    • πŸ”Forensic
      • Forensic Tools
      • EMAIL Forensics
      • File header forensics
    • Trend Micro
      • Deep Security
        • Installation & Prerequisite
          • Microsoft SQL server 2022
          • Postgres 16 Core
          • Installation
    • Practical Malware Analysis & API Threats
  • πŸ•ΉοΈServer are fun !
    • Securing Linux
      • Securing SSH
      • Sudoers
      • UFW (Uncomplicated FW)
      • Unattended Upgrades
      • Password Complexiety
      • Auditing Linux
      • Samba - SMB
      • NFS - Network File System
      • FTP
      • AIDE
    • Servers
      • Linux Sever
        • OpenLDAP Server Setup
          • ldap-account-manager
          • Securing OpenLDAP
          • OpenLDAP client setup
          • Checking LDAP setup
        • Users & Groups
        • Password Policy
        • File & File Permissions
        • Automatic Updates
        • Adding GUI to Ubuntu Server
        • DNS Server
        • NTP Server
      • Windows Sever
        • Deep dive into Windows Server
        • Windows server Installation
        • Disable IPv6
        • Disable Server Manager on startup
        • Promoting OS to AD server
        • AD DNS
        • AD DHCP
        • AD Activation
        • AD Users & Groups
        • AD FileServer
        • Adding Users into AD
        • Bulk Importing users into Domain
        • Windows AD Resources
        • Group Policy Editor
          • Creating First Policy
          • Restricting CMD & Powershell
          • Password Policies
          • Audit Policies
          • Log Retention Policy
          • Windows Defender Firewall
          • Patch Management & Window Updates
        • Setting Up local accounts for windows hosts
    • Hacking Systems
      • Linux Systems
        • Battery Charge Threshold (Linux)
        • Metasploitable OS Complete Solved
      • Tricking Windows
        • Bitlocker & Time based policy bypass
    • Monitoring HeartBeats
    • RAID Technology
    • Managing Partitions
      • Parted
      • Fdisk
      • LVM
        • Re-claiming unused disk space
        • Adding physical volume into VG
        • Removing physical volume from VG
      • SWAP Memory
    • Virtualization
      • Proxmox
        • Proxmox VE Installation
        • Default Storage Expansion
        • Proxmox Network Link Aggegration
        • NAT Interface Configuration
        • Importing disk into proxmox
        • Creating an LVM Thin Pool
        • Proxmox IAM
  • πŸ™β€β™‚οΈDan the AI Expert
    • Ollama Ollama ...
      • Ollama
        • Ollama models
        • Open Web UI & Ollama Integration
    • Microsoft Presentation using AI
  • πŸ›‘οΈSecurity Operations
    • Wazuh - Open Source XDR. Open Source SIEM.
      • Components
      • Deployment Methods
      • Installation
        • Single Node Installation
          • Wazuh Indexer Installation
          • Wazuh Server Installation
          • Wazuh Dashboard Installation
          • Single node deployment with Script
        • Managing multiple Wazuh clusters with Cross-Cluster Search
          • Cluster Configuration
          • Set up Cross-Cluster Search
        • Upgrading Wazuh Central Components
        • Uninstalling Wazuh
      • Custom Decoder & Rules
        • Pfsense Decoders
        • Pfsense Rules
      • Security Operations Center Tools (Wazuh)
    • IRIS-DFIR / Case Management
    • Graylog & ElasticSearch
    • Zabbix NMS
      • Zabbix Installation
      • Zabbix Database Management
        • Zabbix Database backup
        • Zabbix Database restore
        • MySQL Replication (M-M)
        • MySQL Replication (M-W)
      • Zabbix Geomap Setup
      • Adding Hosts into Zabbix
      • Zabbix Hostgroups
      • Auto Registration Hosts Zabbix
      • Zabbix Globalscrips
      • Zabbix HA Cluster
      • Zabbix Proxy
      • Zabbix Notifications
      • Zabbix Maintainance
      • Zabbix User Management & Authentication
      • Zabbix Housekeeping
      • Scheduled Reporting
      • Service Monitoring using Zabbix
  • Git the master!!
    • Configuring git
    • Git Branches
    • Undoing changes
    • Git - Cheat sheet
    • My first git...
Powered by GitBook
On this page
  1. Cyber Security Base
  2. Network Security
  3. VPN
  4. VPNs

Wireguard Tunneling

1. Overview

CommentThis document outlines the process of setting up a WireGuard VPN between a local machine and an AWS EC2 instance, where only specific traffic is routed through the VPN tunnel. Internet traffic will not be routed through the VPN, but only traffic destined for the VPN network or EC2 instance will be.


2. Prerequisites

2.1. AWS EC2 Instance

  • A running AWS EC2 instance with:

    • Public IP (13.233.64.77 in this example)

    • Private IP (172.31.13.140 in this example)

    • WireGuard installed (sudo apt install wireguard)

2.2. Local Machine

  • A local machine with a public IP (183.87.214.118 in this example).

  • WireGuard installed on the local machine (sudo apt install wireguard).


3. WireGuard VPN Configuration

3.1. Server (EC2) Configuration

  1. Install WireGuard on the EC2 instance:sudo apt updatesudo apt install wireguard

  2. Generate Server Keys:wg genkey | tee server_private_key | wg pubkey > server_public_key

  3. Configure WireGuard on the EC2 instance:Create the WireGuard configuration file (/etc/wireguard/wg0.conf):[Interface]Address = 10.0.0.1/24 # Server VPN IPListenPort = 51820 # WireGuard portPrivateKey = <server_private_key> # Use the generated server private key​[Peer]PublicKey = <client_public_key> # Client's public keyAllowedIPs = 10.0.0.2/32 # Client's VPN IP

  4. Enable IP Forwarding on the EC2 instance:sudo sysctl -w net.ipv4.ip_forward=1sudo sysctl -p

  5. Set up NAT for internet access:sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEsudo iptables -A FORWARD -i wg0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPTsudo iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT

  6. Persist iptables rules:sudo apt install iptables-persistentsudo netfilter-persistent save

  7. Start WireGuard on the EC2 instance:sudo wg-quick up wg0


3.2. Client (Local Machine) Configuration

  1. Generate Client Keys:wg genkey | tee client_private_key | wg pubkey > client_public_key

  2. Configure WireGuard on the Local Machine:Create the WireGuard configuration file (/etc/wireguard/wg0.conf):[Interface]Address = 10.0.0.2/24 # Client VPN IPPrivateKey = <client_private_key> # Use the generated client private keyDNS = 8.8.8.8 # DNS server (optional)​[Peer]PublicKey = <server_public_key> # Server's public keyEndpoint = 13.233.64.77:51820 # EC2 server's public IP and WireGuard portAllowedIPs = 10.0.0.0/24 # Only route traffic to the VPN subnet (no full tunnel)PersistentKeepalive = 25

    • AllowedIPs = 10.0.0.0/24: Routes only traffic to the VPN network (i.e., EC2's private network) through the VPN. Internet traffic will bypass the VPN.

  3. Start WireGuard on the Local Machine:sudo wg-quick up wg0


4. Verifying the Configuration

4.1. On the EC2 Server (AWS)

  1. Check the status of WireGuard:sudo wg show

  2. Ensure IP forwarding is working by running:sudo sysctl net.ipv4.ip_forwardCommentThis should return net.ipv4.ip_forward = 1.

  3. Check the NAT and routing rules:sudo iptables -t nat -LCommentEnsure that the MASQUERADE rule is present for the VPN interface (wg0).


4.2. On the Local Machine

  1. Verify VPN connection:

    • Test connectivity to the VPN server's private IP (from the local machine):ping 10.0.0.1

  2. Verify that internet traffic is bypassing the VPN:

    • Test general internet access:ping google.com # Should use the local machine's regular internet connection

    CommentComment

  3. Check the routing table to verify that only the VPN network traffic goes through the VPN tunnel:ip routeCommentExpected output:10.0.0.0/24 dev wg0 # VPN traffic routes via wg0default via <gateway_ip> # Default traffic goes via the normal interface


5. Troubleshooting

5.1. No Internet on Client

  • Ensure that the EC2 instance has IP forwarding enabled and iptables NAT rules are configured correctly.

  • Check the security group of the EC2 instance to ensure it allows UDP traffic on port 51820 and outbound traffic on port 80 (for internet access).

5.2. VPN Connection Not Established

  • Ensure that the public keys on the server and client match.

  • Verify the WireGuard service is running on both the server and client.

  • Check for firewall rules or network issues that may be blocking the connection.


6. Optional: Additional Configuration

6.1. Use a Custom DNS Server

If you'd like to ensure that the client always uses a specific DNS server when connected to the VPN, add the following to the [Interface] section of the client configuration:DNS = 8.8.8.8 # Google's DNS (or your preferred DNS)


6.2. Use Policy-Based Routing

If you need even more control over which traffic goes through the VPN, you can use policy-based routing (using ip rule) on the local machine. This method allows routing specific applications or destinations through the VPN while other traffic remains on the default route.


7. Conclusion

This setup provides a WireGuard VPN that routes only specific traffic (i.e., traffic destined for the VPN network) through the VPN tunnel, while all other traffic (including internet access) bypasses the VPN. This ensures selective routing for improved performance and security.

PreviousVPNsNextStrongSwan Gateway VPN Server on Ubuntu

Last updated 3 months ago

πŸ§‘β€πŸ’»
πŸ•ΈοΈ