🔒 Security

VPN

Virtual Private Network

A VPN (Virtual Private Network) creates an encrypted tunnel over a public network to enable secure communication. Protocols include WireGuard, OpenVPN, and IPSec, and it is essential for remote work and enterprise network security.

📖 Detailed Explanation

A VPN (Virtual Private Network) is a technology that creates an encrypted "tunnel" over the public internet, enabling secure communication as if connected to a dedicated network. A VPN provides functions such as data encryption, IP address masking, and bypassing geographic restrictions. Enterprises use it to let remote workers connect securely to the internal network or to link networks between branch offices.

VPN protocols have evolved over several generations. IPSec operates at the network layer and is widely used for site-to-site VPNs. OpenVPN is an SSL/TLS-based open-source solution with high flexibility. WireGuard is a modern protocol integrated into the Linux kernel in 2020, characterized by concise code of fewer than 4,000 lines, modern cryptography (ChaCha20, Curve25519), and fast connection speed. As of 2025, WireGuard is becoming the standard for building new VPNs.

The role of VPNs is changing with the rise of Zero Trust architecture. Traditional VPNs followed a "castle wall" model, in which connecting grants access to the entire network. In contrast, Zero Trust Network Access (ZTNA) "never trusts, always verifies," allowing granular access only to specific resources. Solutions such as Tailscale and Cloudflare Access implement ZTNA on top of WireGuard, combining the encryption strengths of VPNs with the granular access control of Zero Trust.

As serious vulnerabilities continue to be discovered in SSL VPNs (Fortinet, SonicWall, etc.), many organizations are migrating to WireGuard-based solutions. WireGuard is easy to audit thanks to its small codebase, and its stealth mode means it does not respond to UDP port scans, resulting in a smaller attack surface. Solutions such as Defguard and Netmaker add MFA, ACL, and centralized management features to WireGuard to meet enterprise requirements.

💻 Code Example

# WireGuard VPN 서버 설정 (Ubuntu/Debian)
# WireGuard는 Linux 커널 5.6+에 내장

# 1. 설치
sudo apt update && sudo apt install wireguard

# 2. 키 쌍 생성 (서버)
cd /etc/wireguard
umask 077  # 파일 권한 제한
wg genkey | tee server_private.key | wg pubkey > server_public.key

# 3. 서버 설정 파일 (/etc/wireguard/wg0.conf)
cat > /etc/wireguard/wg0.conf << 'EOF'
[Interface]
# 서버 개인키 (절대 공유 금지!)
PrivateKey = SERVER_PRIVATE_KEY_HERE
# VPN 내부 IP 주소
Address = 10.0.0.1/24
# 수신 포트 (UDP)
ListenPort = 51820
# 패킷 포워딩 활성화
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

# 클라이언트 피어 (각 사용자마다 추가)
[Peer]
# 클라이언트 공개키
PublicKey = CLIENT_PUBLIC_KEY_HERE
# 클라이언트에 할당할 IP
AllowedIPs = 10.0.0.2/32
# 선택: 동적 IP 클라이언트용 keepalive
PersistentKeepalive = 25
EOF

# 4. 커널 IP 포워딩 활성화
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

# 5. WireGuard 시작
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0

# 6. 상태 확인
sudo wg show

# === 클라이언트 설정 (/etc/wireguard/wg0.conf) ===
cat > client_wg0.conf << 'EOF'
[Interface]
PrivateKey = CLIENT_PRIVATE_KEY_HERE
Address = 10.0.0.2/24
DNS = 1.1.1.1, 8.8.8.8

[Peer]
PublicKey = SERVER_PUBLIC_KEY_HERE
# 서버 주소:포트
Endpoint = vpn.example.com:51820
# 모든 트래픽을 VPN으로 (전체 터널)
AllowedIPs = 0.0.0.0/0
# 또는 특정 네트워크만 (스플릿 터널)
# AllowedIPs = 10.0.0.0/24, 192.168.1.0/24
PersistentKeepalive = 25
EOF

# QR 코드 생성 (모바일 클라이언트용)
# sudo apt install qrencode
qrencode -t ansiutf8 < client_wg0.conf

# 보안 참고:
# - WireGuard는 4,000줄 미만의 간결한 코드 (OpenVPN: 100,000+줄)
# - ChaCha20-Poly1305 암호화, Curve25519 키 교환
# - 스텔스: 인증되지 않은 패킷에 응답 안 함 (포트 스캔 불가)
# Tailscale - WireGuard 기반 Zero Trust VPN
# 중앙 관리, SSO 통합, ACL로 세분화된 접근 제어

# 1. 설치 (Linux)
curl -fsSL https://tailscale.com/install.sh | sh

# 2. 연결 (브라우저에서 SSO 인증)
sudo tailscale up

# 기업 SSO 연동 (SAML, OIDC)
sudo tailscale up --login-server=https://login.tailscale.com

# 3. 상태 확인
tailscale status
# 결과 예:
# 100.64.0.1    my-laptop    user@example.com  linux   -
# 100.64.0.2    office-pc    user@example.com  windows -
# 100.64.0.3    server-prod  admin@example.com linux   -

# 4. 다른 기기에 SSH 접속 (Tailscale IP 사용)
ssh 100.64.0.3  # 또는
ssh server-prod  # MagicDNS로 호스트명 사용

# === ACL (Access Control List) 정책 예제 ===
# tailscale.com 관리 콘솔에서 설정
{
  "acls": [
    // 개발자는 개발 서버만 접근 가능
    {
      "action": "accept",
      "src": ["group:developers"],
      "dst": ["tag:dev:*"]
    },
    // 관리자는 모든 서버 접근 가능
    {
      "action": "accept",
      "src": ["group:admins"],
      "dst": ["*:*"]
    },
    // 모든 사용자는 사내 웹앱만 접근
    {
      "action": "accept",
      "src": ["*"],
      "dst": ["tag:webapp:80,443"]
    }
  ],
  "tagOwners": {
    "tag:dev": ["group:devops"],
    "tag:prod": ["group:admins"],
    "tag:webapp": ["group:admins"]
  },
  "groups": {
    "group:developers": ["user1@example.com", "user2@example.com"],
    "group:admins": ["admin@example.com"],
    "group:devops": ["devops@example.com"]
  }
}

# === Subnet Router (사내 네트워크 접근) ===
# 사내에 Tailscale 노드를 설치하고 서브넷 라우터로 설정
sudo tailscale up --advertise-routes=192.168.1.0/24

# 관리 콘솔에서 라우트 승인 후, 모든 Tailscale 기기에서
# 192.168.1.0/24 네트워크 접근 가능

# === Exit Node (전체 인터넷 트래픽 VPN 경유) ===
# 서버에서 Exit Node 활성화
sudo tailscale up --advertise-exit-node

# 클라이언트에서 Exit Node 사용
tailscale up --exit-node=server-prod

# 장점:
# - WireGuard 기반으로 빠르고 안전
# - NAT 통과 자동 처리 (DERP 릴레이)
# - SSO/MFA 통합
# - 세분화된 ACL로 Zero Trust 구현
# - 설치 수분 내 완료 (전통적 VPN: 수 시간~수일)
# OpenVPN 서버 설정 (Ubuntu/Debian)
# 레거시 시스템이나 특수 요구사항에 사용

# 1. 설치
sudo apt update
sudo apt install openvpn easy-rsa

# 2. PKI 초기화 및 인증서 생성
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
./easyrsa init-pki
./easyrsa build-ca nopass           # CA 생성
./easyrsa gen-req server nopass     # 서버 인증서 요청
./easyrsa sign-req server server    # 서버 인증서 서명
./easyrsa gen-dh                    # DH 파라미터
openvpn --genkey secret ta.key      # TLS-Auth 키

# 3. 서버 설정 (/etc/openvpn/server.conf)
cat > /etc/openvpn/server.conf << 'EOF'
port 1194
proto udp
dev tun

# 인증서 경로
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
dh /etc/openvpn/dh.pem
tls-auth /etc/openvpn/ta.key 0

# VPN 네트워크
server 10.8.0.0 255.255.255.0

# 클라이언트가 서로 통신 가능
client-to-client

# 모든 트래픽을 VPN으로
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 1.1.1.1"

# 보안 설정 (2025 권장)
cipher AES-256-GCM
auth SHA256
tls-version-min 1.2
tls-cipher TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384

# 로깅
log-append /var/log/openvpn.log
verb 3
EOF

# 4. 클라이언트 인증서 생성
./easyrsa gen-req client1 nopass
./easyrsa sign-req client client1

# 5. 클라이언트 설정 파일 (.ovpn)
cat > client1.ovpn << 'EOF'
client
dev tun
proto udp
remote vpn.example.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun


# CA 인증서 내용



# 클라이언트 인증서 내용



# 클라이언트 개인키 내용



# ta.key 내용

key-direction 1

cipher AES-256-GCM
auth SHA256
verb 3
EOF

# OpenVPN vs WireGuard:
# OpenVPN: 100,000+ 줄 코드, 복잡한 설정, 인증서 관리 필요
# WireGuard: 4,000줄 코드, 간단한 설정, 키 쌍만 사용
# 새 프로젝트는 WireGuard 권장

🗣️ Say It Like This in Practice

💬 In an Infrastructure Modernization Meeting
"I propose migrating from legacy SSL VPN to a WireGuard-based solution. Fortinet VPN vulnerabilities keep being discovered, and WireGuard has a small codebase, making it easy to audit and maintain. We could consider Tailscale or our own WireGuard server."
💬 In a Zero Trust Adoption Discussion
"A VPN alone cannot achieve Zero Trust. It is a problem if users can access all internal resources even after connecting to the VPN. We should apply ZTNA and configure ACLs so that each role can access only the services it needs. Please look into Tailscale ACLs or Cloudflare Access."
💬 In a Remote Work Security Policy
"Remote workers must connect to internal systems through the VPN. If only internal traffic goes through the VPN using split tunneling, performance is good and personal internet use is not affected. It would be good to make MFA mandatory and also add device posture verification."

⚠️ Cautions & Best Practices

❌
The Misconception That a VPN Alone Provides Complete Security

A VPN encrypts data in transit, but it leaves you defenseless against internal threats after connection. Apply Zero Trust principles (granular access control, continuous verification) together with the VPN.

❌
Leaving Vulnerable SSL VPNs Unpatched

Serious vulnerabilities in SSL VPNs such as Fortinet, SonicWall, and Ivanti continue to be discovered. Do not delay applying patches. If possible, consider migrating to a WireGuard-based solution.

❌
Operating a VPN Without MFA

Authenticating with VPN credentials alone is vulnerable to phishing and credential leaks. Make TOTP, hardware keys (YubiKey), or SSO-integrated MFA mandatory.

✅
VPN Best Practices

Use WireGuard or a WireGuard-based solution (Tailscale, Netmaker), make MFA mandatory, use ACLs for granular access control, optimize performance with split tunneling, perform logging and monitoring, and rotate keys regularly. Operate it together with Zero Trust principles.

🔗 Related Terms

📚 Learn More