WireGuard 공식 CLI(wg) 치트시트: 키 생성과 인터페이스

💡 핵심 요약 (Executive Summary)

본 가이드는 network vpn wg 핵심 가이드 및 실전 아키텍처의 핵심 개념, 실전 구성 명령어 및 아키텍처 베스트 프랙티스를 다룹니다. 클라우드 네이티브 및 인프라 엔지니어링 실무에 즉시 활용 가능하도록 체계적으로 정리했습니다.

📑 Table of Contents
Installation
  • Mac OS
bash
brew install wireguard-tools
  • ( VPN Client Tool )
Exec
help
txt
Usage: wg <cmd> [<args>]

Available subcommands:
  show: Shows the current configuration and device information
  showconf: Shows the current configuration of a given WireGuard interface, for use with `setconf'
  set: Change the current configuration, add peers, remove peers, or change peers
  setconf: Applies a configuration file to a WireGuard interface
  addconf: Appends a configuration file to a WireGuard interface
  syncconf: Synchronizes a configuration file to a WireGuard interface
  genkey: Generates a new private key and writes it to stdout
  genpsk: Generates a new preshared key and writes it to stdout
  pubkey: Reads a private key from stdin and writes a public key to stdout
You may pass `--help' to any of these subcommands to view usage.
클라이언트 터널링 인터페이스 생성 (Linux Only)
Reference & Guidelines (NOTE)

현재 CLI버전에서는 .conf 에 Peer의 Address를 설정할 수 없고, 터널 구성에 추가해주어야 하는것으로 확인됨 wireguard-tools v1.0.20250521

  • git.zx2c4.com
  • 아래 바이너리를 앞으로 업데이트할것으로 확인됨
  • ( VPN Client Tool )
bash
# ip link 명령으로 직접 정의
ip link add dev wg0 type wireguard

# 피어링 대역 추가
ip address add dev utun9 10.0.X.X/32
## 단일 IP 2개 추가
ip address add dev utun9 192.168.2.1 peer 192.168.2.2

# config 생성
myConfig="""
"""
cat <<EOF > /etc/wireguard/utun9.conf
$myConfig
EOF

# config로 인터페이스구성 (Adderess x)
wg setconf utun9 utun9.conf
연결 종료
상태 확인
bash
sudo wg show
>>>
interface: utun6
  public key: <secret>
  private key: (hidden)
  listening port: 57450

peer: <secret>
  endpoint: <WAN_IP>:41821
  allowed ips: 10.0.X.X/24, 118.37.2.0/24, 192.168.118.0/24
  latest handshake: 2 minutes, 16 seconds ago
  transfer: 2.98 KiB received, 14.31 GiB sent
  persistent keepalive: every 25 seconds
<<<

# 리얼 인터페이스로 조회
sudo wg showconf utun6
>>>
[Interface]
ListenPort = 57450
PrivateKey = <secret>

[Peer]
PublicKey = <secret>
AllowedIPs = 10.0.X.X/24, 118.37.2.0/24, 192.168.118.0/24
Endpoint = <WAN_IP>:41821
PersistentKeepalive = 25
<<<
Features
Peer를 위한 개인키 및 공개키 생성
bash
mkdir wg-mgnt-peer1
cd wg-mgnt-peer1/
#wg genkey > privatekey
#cat privatekey
#cat privatekey | wg pubkey > publickey
#cat publickey
wg genkey | tee privatekey | wg pubkey > publickey

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *