사전준비
- 설치에 앞서 vpn firewall 정책설정이 선행되어야 합니다.
- ddns 설정을 하지 않았다면 ddns설정을 참고하세요. (아래 예시는 myhost.duckdns.org를 사용합니다.)
설치구성
- vpn 네트워크는 10.8.0.0/24 , udp 포트는 21194 사용
- 클라이언트의 dns는 서버(OpenWrt 라우터)의 dns 사용 (DoT로 구성한 192.168.1.1)
openvpn 설치
openvpn-easy-rsa및 openvpn-openssl. OpenWrt GUI(luci)를 사용하는 경우 luci-app-openvpn도 설치하세요.
opkg update
opkg install openvpn-easy-rsa openvpn-openssl luci-app-openvpn
키생성
디폴트 키 크기는 2048비트입니다. 2048비트면 충분하지만 4096비트로 비트를 늘리려면 export EASYRSA_KEY_SIZE=4096 로 수정하세요.
# 변수 설정
export EASYRSA_KEY_SIZE=2048
export EASYRSA_PKI="/etc/easy-rsa/pki"
export EASYRSA_REQ_CN="[whatever]"
export EASYRSA_REQ_COUNTRY="[2-letter country code]"
export EASYRSA_REQ_PROVINCE="[whatever]"
export EASYRSA_REQ_ORG="[whatever]"
export EASYRSA_REQ_ORG="[whatever]"
export EASYRSA_REQ_EMAIL="[whatever]"
export EASYRSA_REQ_OU="[whatever]"
export EASYRSA_BATCH="1"
# pki 디렉토리를 제거하고 초기화
easyrsa init-pki
# DH parameters 생성
easyrsa gen-dh
# CA 생성 (인증기관 키 생성)
easyrsa build-ca nopass
# 서버키 생성 및 자체서명 (server 라는 서버키가 생성됩니다)
easyrsa build-server-full server nopass
# 클라이언트키 생성 (client1 라는 클라이언트키가 생성됩니다)
easyrsa build-client-full client1 nopass
생성된 키 복사
생성된 다음 키를 /etc/openvpn으로 복사합니다.
cp /etc/easy-rsa/pki/ca.crt /etc/openvpn/
cp /etc/easy-rsa/pki/dh.pem /etc/openvpn/
cp /etc/easy-rsa/pki/issued/server.crt /etc/openvpn/
cp /etc/easy-rsa/pki/private/server.key /etc/openvpn/
luci 설정
/etc/config/openvpn 을 다음과 같이 편집합니다.
config openvpn 'custom_config' option config '/etc/openvpn/my-vpn.conf' option enabled '1' ...
서버 구성
/etc/openvpn/my-vpn.conf 을 수정해 openvpn 서버 설정을 합니다.
verb 4 user nobody group nogroup dev tun0 server 10.8.0.0 255.255.255.0 proto udp port 21194 txqueuelen 1000 keepalive 10 120 ncp-ciphers AES-256-GCM:AES-128-GCM:AES-256-CBC:AES-128-CBC cipher AES-256-GCM comp-lzo no client-to-client #client-config-dir /etc/openvpn/ccd push "route 192.168.1.0 255.255.255.0" push "dhcp-option DNS 192.168.1.1" #push "redirect-gateway def1" push "redirect-gateway autolocal def1" push "persist-tun" push "persist-key" persist-tun persist-key topology subnet ca /etc/easy-rsa/pki/ca.crt dh /etc/easy-rsa/pki/dh.pem cert /etc/easy-rsa/pki/issued/server.crt key /etc/easy-rsa/pki/private/server.key status-version 2 status /var/run/openvpn.status 10 log-append /var/log/openvpn.log
인터페이스 생성
openvpn 네트워크 인터페이스 생성을 위해 /etc/config/network 다음과 같이 추가합니다.
... config interface 'tun0' option ifname 'tun0' option proto 'none'
방화벽 설정
udp 포트 21194를 통해 들어오는 연결 허용합니다.
... config rule option name 'Allow-openvpn' option src 'wan' option proto 'udp' option dest_port '21194' option target 'ACCEPT'
서비스 재시작
/etc/init.d/firewall restart
/etc/init.d/network restart
/etc/init.d/openvpn restart
클라이언트 설정
client1.ovpn 화일을 아래와 같이 생성하고 위에서 생성한 키를 클라이언트에 복사합니다.
- ca.crt
- client1.crt
- client1.key
remote myhost.duckdns.org port 21194 proto udp comp-lzo no dev tun cipher AES-256-GCM client remote-cert-tls server ca ca.crt cert client1.crt key client1.key verb 3 status status auth-nocache ; log /var/log/openvpn.log