Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 491. 윈도우에 OpenVPN 설치 - 서버 측 구성 [링크 복사], [링크+제목 복사]
조회: 19932
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)
(시리즈 글이 4개 있습니다.)
개발 환경 구성: 491. 윈도우에 OpenVPN 설치 - 서버 측 구성
; https://www.sysnet.pe.kr/2/0/12224

개발 환경 구성: 492. 윈도우에 OpenVPN 설치 - 클라이언트 측 구성
; https://www.sysnet.pe.kr/2/0/12225

개발 환경 구성: 493. OpenVPN의 네트워크 구성
; https://www.sysnet.pe.kr/2/0/12226

개발 환경 구성: 515. OpenVPN - 재부팅 후 ICS(Internet Connection Sharing) 기능이 동작 안하는 문제
; https://www.sysnet.pe.kr/2/0/12325




윈도우에 OpenVPN 설치 - 서버 측 구성

최근, 필요에 의해서 VPN을 설치해 봤는데 이에 대한 기록을 남깁니다. ^^ OpenVPN에 대해 검색해 보니 다음의 글이 잘 설명하고 있는데요,

OpenVPN Windows 서버 및 클라이언트 설치
; https://jacegem.github.io/blog/2017/openvpn-windows/

약간 살을 붙여서 ^^ 정리를 해보겠습니다.




우선 다음의 경로를 통해 설치 파일을 다운로드하고,

OpenVPN - Windows 10/Server 2016/Server 2019 installer (NSIS) GnuPG Signature openvpn-install-2.4.9-I601-Win10.exe 
; https://openvpn.net/community-downloads/

실행 후, 선택 옵션 중 "EasyRSA2 Certificate Management Scripts" 항목을 체크해 줍니다.

openvpn_install_1.png

설치가 완료되면, 기본적으로 "C:\Program Files\OpenVPN"에 파일이 위치합니다. 그다음, "관리자 권한"으로 cmd.exe 창을 하나 열어 easy-rsa 폴더로 이동한 후, init-config과 vars를 실행해 명령행 환경 구성을 합니다.

C:\Users\testusr> cd "C:\Program Files\OpenVPN\easy-rsa"

C:\Program Files\OpenVPN\easy-rsa> init-config

C:\Program Files\OpenVPN\easy-rsa>copy vars.bat.sample vars.bat
        1 file(s) copied.

C:\Program Files\OpenVPN\easy-rsa> vars

C:\Program Files\OpenVPN\easy-rsa>

("vars.bat"의 경우 향후에도 관련 작업을 할 때면 PATH 등의 환경 구성을 해주므로 미리 실행해 주면 됩니다.) 그다음 깨끗하게 기존 "keys" 폴더 환경을 초기화하고,

C:\Program Files\OpenVPN\easy-rsa> clean-all
The system cannot find the file specified.
        1 file(s) copied.
        1 file(s) copied.

Root CA 인증서부터 생성을 시작합니다. (Common Name은 임의의 값을 주면 됩니다.)

C:\Program Files\OpenVPN\easy-rsa> build-ca
Can't load C:\Program Files\OpenVPN\easy-rsa/.rnd into RNG
2452:error:2406F079:random number generator:RAND_load_file:Cannot open file:crypto/rand/randfile.c:98:Filename=C:\Program Files\OpenVPN\easy-rsa/.rnd
Generating a RSA private key
...................................................................................................................++++
.............++++
writing new private key to 'keys\ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:
State or Province Name (full name) [CA]:
Locality Name (eg, city) [SanFrancisco]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) [changeme]:
Common Name (eg, your name or your server's hostname) [changeme]:myca
Name [changeme]:
Email Address [mail@host.domain]:

C:\Program Files\OpenVPN\easy-rsa>

위의 과정을 마치면 "C:\Program Files\OpenVPN\easy-rsa\keys" 폴더에 "ca.crt", "ca.key" 파일이 생성됩니다.

그다음, VPN 서버 용 인증서를 만들고, 방금 생성했던 Root CA로부터 서명을 받습니다. (역시 이번에도 Common Name은 임의의 값을 줍니다.)

C:\Program Files\OpenVPN\easy-rsa> build-key-server server
Ignoring -days; not generating a certificate
Generating a RSA private key
............................................................................++++
........................................................++++
writing new private key to 'keys\server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:
State or Province Name (full name) [CA]:
Locality Name (eg, city) [SanFrancisco]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) [changeme]:
Common Name (eg, your name or your server's hostname) [changeme]:myvpn
Name [changeme]:
Email Address [mail@host.domain]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
stateOrProvinceName   :PRINTABLE:'CA'
localityName          :PRINTABLE:'SanFrancisco'
organizationName      :PRINTABLE:'OpenVPN'
organizationalUnitName:PRINTABLE:'changeme'
commonName            :PRINTABLE:'myvpn'
name                  :PRINTABLE:'changeme'
emailAddress          :IA5STRING:'mail@host.domain'
Certificate is to be certified until Jun  8 23:57:57 2030 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\Program Files\OpenVPN\easy-rsa>

위의 단계를 거치면 "C:\Program Files\OpenVPN\easy-rsa\keys" 폴더에 "server.crt", "server.csr", "server.key" 파일이 생성됩니다.

이어서 DH Parameter를 생성하는,

C:\Program Files\OpenVPN\easy-rsa> build-dh
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
......................................................................................................+.................
+.............................................................................................
+.......................................................................................................................
...생략]...
........+.............+....................+..+.............+...
+.............................................................................................................................
.........+.................................................................................
+...................................++*++*++*++*

C:\Program Files\OpenVPN\easy-rsa>

스크립트를 실행하면 "C:\Program Files\OpenVPN\easy-rsa\keys" 폴더에는 dh2048.pem 파일이 생성됩니다. 마지막으로 key 폴더로 이동해 ta 키 파일을 생성하면,

C:\Program Files\OpenVPN\easy-rsa> cd keys

C:\Program Files\OpenVPN\easy-rsa\keys> openvpn --genkey --secret ta.key

C:\Program Files\OpenVPN\easy-rsa\keys>

"C:\Program Files\OpenVPN\easy-rsa\keys" 폴더에는 OpenVPN을 위해 필요한 인증서 및 키 파일들이 모두 마련됩니다.

  • ca.crt
  • ca.key
  • dh2048.pem
  • ta.key
  • server.crt
  • server.key

위의 6개 파일을 "C:\Program Files\OpenVPN\config" 폴더에 복사하고, "C:\Program Files\OpenVPN\sample-config" 폴더에 있는 server.ovpn 파일도 "C:\Program Files\OpenVPN\config" 폴더에 복사해 줍니다.

  • ca.crt
  • ca.key
  • dh2048.pem
  • README.txt
  • server.crt
  • server.key
  • ta.key
  • server.ovpn

이것으로 파일은 모두 준비되었으니, 이제 최종적으로 OpenVPN 서비스를 위한 환경 설정을 server.ovpn 파일에 반영하는 일만 남았습니다.

(참고로, 이 글에서는 인증서 구성을 "Program Files" 영역에 했지만 2.4 버전부터 %USERPROFILE% 경로에 하는 기능이 추가되었다고 합니다.)




이제 파일 편집기가 필요한데, 아쉽게도 server.ovpn의 개행이 유닉스 양식을 따르기 때문에 Windows Server 2016 이하에 포함된 notepad.exe로는 정상적으로 편집할 수 없습니다. (반면 Windows 10, Windows Server 2019에 포함된 notepad.exe는 LF만 포함하고 있는 파일 편집을 할 수 있습니다.)

따라서 그런 환경이라면 간편하게 Visual Studio Code 등의 편집기를 설치해 server.ovpn 파일의 설정 값을 바꾸면 됩니다. 대충 다음의 값들만 추가하거나 주석을 제거해 줍니다.

push "dhcp-option DNS 168.126.63.1"
push "dhcp-option DNS 8.8.8.8"
client-to-client

(나머지 설정들은 여러분의 환경에 맞게 변경하고) 마지막으로 관리자 권한의 cmd.exe 명령행에서 다음의 명령어로 VPN 서비스를 시작하면 끝입니다.

C:\Program Files\OpenVPN\config> openvpn server.ovpn
Thu Jun 11 09:24:27 2020 OpenVPN 2.4.9 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [LZ4] [PKCS11] [AEAD] built on Apr 16 2020
Thu Jun 11 09:24:27 2020 Windows version 6.2 (Windows 8 or greater) 64bit
Thu Jun 11 09:24:27 2020 library versions: OpenSSL 1.1.1f  31 Mar 2020, LZO 2.10
Thu Jun 11 09:24:27 2020 NOTE: your local LAN uses the extremely common subnet address 192.168.0.x or 192.168.1.x.  Be aware that this might create routing conflicts if you connect to the VPN server from public locations such as internet cafes that use the same subnet.
Thu Jun 11 09:24:27 2020 Diffie-Hellman initialized with 2048 bit key
Thu Jun 11 09:24:27 2020 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Jun 11 09:24:27 2020 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Thu Jun 11 09:24:27 2020 interactive service msg_channel=0
Thu Jun 11 09:24:27 2020 ROUTE_GATEWAY 192.168.1.1/255.255.255.0 I=6 HWADDR=11:22:48:05:54:f0
Thu Jun 11 09:24:27 2020 open_tun
Thu Jun 11 09:24:27 2020 TAP-WIN32 device [Local Area Connection] opened: \\.\Global\{46031156-4155-4C7D-BC88-2750C4B95502}.tap
Thu Jun 11 09:24:27 2020 TAP-Windows Driver Version 9.24
Thu Jun 11 09:24:27 2020 Notified TAP-Windows driver to set a DHCP IP/netmask of 10.8.0.1/255.255.255.252 on interface {46031156-4155-4C7D-BC88-2750C4B95502} [DHCP-serv: 10.8.0.2, lease-time: 31536000]
Thu Jun 11 09:24:27 2020 Sleeping for 10 seconds...
Thu Jun 11 09:24:37 2020 Successful ARP Flush on interface [10] {46031156-4155-4C7D-BC88-2750C4B95502}
Thu Jun 11 09:24:37 2020 C:\Windows\system32\route.exe ADD 10.8.0.0 MASK 255.255.255.0 10.8.0.2
Thu Jun 11 09:24:37 2020 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=25 and dwForwardType=4
Thu Jun 11 09:24:37 2020 Route addition via IPAPI succeeded [adaptive]
Thu Jun 11 09:24:37 2020 Could not determine IPv4/IPv6 protocol. Using AF_INET6
Thu Jun 11 09:24:37 2020 Socket Buffers: R=[65536->65536] S=[65536->65536]
Thu Jun 11 09:24:37 2020 setsockopt(IPV6_V6ONLY=0)
Thu Jun 11 09:24:37 2020 UDPv6 link local (bound): [AF_INET6][undef]:1194
Thu Jun 11 09:24:37 2020 UDPv6 link remote: [AF_UNSPEC]
Thu Jun 11 09:24:37 2020 MULTI: multi_init called, r=256 v=256
Thu Jun 11 09:24:37 2020 IFCONFIG POOL: base=10.8.0.4 size=62, ipv6=0
Thu Jun 11 09:24:37 2020 IFCONFIG POOL LIST
Thu Jun 11 09:24:37 2020 Initialization Sequence Completed




화면 출력에도 나오지만, OpenVPN은 기본적으로 UDP 프로토콜에 1194 포트를 사용합니다. 따라서 외부에서 접근하려면 반드시 방화벽 등에서 제약을 풀어줘야 합니다. 가령, Azure 상의 VM에 OpenVPN을 설치했다면 1) 운영체제 자체의 방화벽뿐만 아니라, 2) Azure VM 설정의 Networking 옵션에서 "Inbound port rules"도 열어줘야 합니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/11/2020]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2023-02-24 08시49분
vpnhood/VpnHood - Undetectable Fast Portable VPN
; https://github.com/vpnhood/VpnHood
정성태

... 16  17  18  19  20  21  22  23  [24]  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13021정성태3/31/20226679Windows: 201. Windows - INF 파일을 이용한 장치 제거 방법
13020정성태3/30/20226423.NET Framework: 1187. RDP 접속 시 WPF UserControl의 Unloaded 이벤트 발생파일 다운로드1
13019정성태3/30/20226405.NET Framework: 1186. Win32 Message를 Code로부터 메시지 이름 자체를 구하고 싶다면?파일 다운로드1
13018정성태3/29/20226932.NET Framework: 1185. C# - Unsafe.AsPointer가 반환한 포인터는 pinning 상태일까요? [5]
13017정성태3/28/20226777.NET Framework: 1184. C# - GC Heap에 위치한 참조 개체의 주소를 알아내는 방법 - 두 번째 이야기 [3]
13016정성태3/27/20227626.NET Framework: 1183. C# 11에 추가된 ref 필드의 (우회) 구현 방법파일 다운로드1
13015정성태3/26/20228966.NET Framework: 1182. C# 11 - ref struct에 ref 필드를 허용 [1]
13014정성태3/23/20227576VC++: 155. CComPtr/CComQIPtr과 Conformance mode 옵션의 충돌 [1]
13013정성태3/22/20225896개발 환경 구성: 641. WSL 우분투 인스턴스에 파이썬 2.7 개발 환경 구성하는 방법
13012정성태3/21/20225261오류 유형: 803. C# - Local '...' or its members cannot have their address taken and be used inside an anonymous method or lambda expression
13011정성태3/21/20226724오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/20225683오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/20227229개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/20226516VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/20226151.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/20227180.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/20226063오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/20226090디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/20226235.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/20226984.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/20227388.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/20226950.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/20226444.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/20226061.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202210442오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202215603VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
... 16  17  18  19  20  21  22  23  [24]  25  26  27  28  29  30  ...