웹사이트 검색

OpenVPN - 다중 플랫폼 VPN 연결로 서버 관리 보안


이 페이지에서

  1. 서버 준비
  2. OpenVPN 설치
  3. 방화벽 구성\n
  4. 인증서 생성
  5. 보안 강화\n
  6. 클라이언트 구성

OpenVPN은 업계 표준 SSL/TLS 프로토콜을 사용하여 OSI 레이어 2 또는 3 보안 네트워크 확장을 구현하는 완전한 기능을 갖춘 SSL VPN입니다. 인증서, 스마트 카드 및/또는 사용자 이름/암호 자격 증명을 기반으로 유연한 클라이언트 인증 방법을 지원하고 VPN 가상 인터페이스에 적용된 방화벽 규칙을 사용하여 사용자 또는 그룹별 액세스 제어 정책을 허용합니다. OpenVPN은 웹 애플리케이션 프록시가 아니며 웹 브라우저를 통해 작동하지 않습니다.

서버 준비

이 가이드에서는 Debian 또는 Ubuntu 서버를 사용합니다. 프로덕션 환경에 이미 있는 모든 서버를 사용할 수 있습니다.

OpenVPN 설치

Linux 및 UNIX 서버의 알려진 모든 배포판에는 저장소에 OpenVPN이 있습니다. 설치는 다음을 실행하는 것처럼 간단합니다.

apt-get install openvpn

방화벽 구성

OpenVPN의 기본 수신 포트는 1194입니다. 기본 포트를 사용하는 것이 안전합니다. OpenVPN은 기본적으로 UDP 프로토콜을 사용합니다. 이에 대한 간단한 이유가 있습니다.

OpenVPN은 레이어 2 및 3을 사용합니다.

  • 계층 2는 물리 계층을 통해 오류 없는 데이터 프레임 전송을 제공하는 데이터 링크 계층입니다. 즉, 자체 TUN/TAP 네트워크 장치를 사용합니다.\n
  • 계층 3은 라우팅을 제공하는 네트워크 계층입니다.\n

이는 계층 4(패킷 전달을 보장하는 전송 계층)가 OS 및 애플리케이션 자체에서 관리됨을 의미합니다. 간단히 말해 트래픽 및 패킷 전달 제어는 OS에서 제어하므로 OpenVPN 자체에서 두 번 수행할 필요가 없습니다. 물론 OpenVPN에 TCP를 사용하는 옵션이 있으므로 더 많은 리소스가 낭비되지만 일부 특수한 환경에서는 편리할 수 있습니다.

요약하자면 UDP용 포트 1194를 여는 것만으로도 VPN 연결을 허용할 수 있습니다. OpenVPN에는 자체 검증 및 제어가 구현되어 있으므로 필터링이 필요하지 않습니다(이후 섹션 참조). 방화벽 구성에 다음 명령문을 추가하십시오.

-A INPUT -p udp -m udp --dport 1194 -j ACCEPT

서버 구성

OpenVPN을 성공적으로 설치한 후 /etc/openvpn 폴더에서 모든 OpenVPN 구성 파일을 찾을 수 있습니다. 편집기에서 server.conf 파일을 열고 편집해 보겠습니다.

nano /etc/openvpn/server.conf

다음 섹션을 확인하고 수정합니다.

# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).

ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key # This file should be kept secret

# Diffie hellman parameters.
dh /etc/openvpn/easy-rsa/keys/dh2048.pem

# Configure server mode and supply a VPN subnet
server 10.9.8.0 255.255.255.0

# Push routes to the client
push "route 10.9.8.0 255.255.255.0"

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
tls-auth /etc/openvpn/easy-rsa/keys/ta.key 0 # This file is secret

# Select a cryptographic cipher.
cipher AES-128-CBC # AES

# Enable compression on the VPN link.
comp-lzo

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
user vpn
group vpn

10.9.8.0/24 서브넷을 내부 서브넷으로 선택했으므로 클라이언트는 연결 후 이 서브넷에서 IP 주소를 받습니다. 기본적으로 10.9.8.1은 서버 자체용으로 예약되어 있습니다.

인증서 생성

먼저 vars 파일을 수정해야 합니다. KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG 및 KEY_EMAIL 매개변수를 입력합니다. 이 값은 새 인증서를 생성할 때마다 사용됩니다.

vars 파일을 로드하려면 다음을 실행하십시오.

./vars

로드한 후 인증 기관을 생성할 수 있습니다.

./clean-all
./build-ca

CA가 생성되면 서버 인증서 생성을 진행합니다.

./build-key-server server

클라이언트용 인증서가 하나 더 있습니다.

./build-key client

결국 DH 매개변수를 생성해야 합니다.

./build-dh

보안 강화

OpenVPN 서버를 보호하기 위해 tls-auth를 사용할 것입니다. 이렇게 하면 손상된 서버에 인증서를 보내지 않습니다.

openvpn –genkey –secret ta.key

이 ta.key 파일은 이제 모든 클라이언트 인증서 번들에 포함되어야 합니다.

클라이언트 구성

 ##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun

# Windows needs the TAP-Windows adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote <your-server-ip> 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-128-CBC

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
mute 20 

client.ovpn 파일로 저장하고 ta.key, ca.crt, client.crt, client.key를 하나의 폴더에 포함합니다.

컴퓨터에 openvpn 클라이언트를 설치하고 client.ovpn 구성 파일을 실행한 후 VPN 서버에 연결할 수 있어야 합니다. 그런 다음 설정한 10.9.8.0/24 범위의 IP 주소를 얻고 비공개로 서버와 협력합니다.