(adsbygoogle = window.adsbygoogle || []).push({}); O_o :: 'VPN' 태그의 글 목록

'VPN'에 해당되는 글 3건

  1. 2008.11.05 Remote Access VPN Connections
  2. 2008.10.08 OpenVPN 설치및 사용하기 1
  3. 2008.10.08 OpenVPN 설정 방법

Remote Access VPN Connections

|

Remote AccessVPN Connections

For remote access VPN connections, a computer creates a remote access connection to a VPN server. During the connection process the VPN server assigns an IP address for the remote access VPN client and changes the default route on the remote client so that default route traffic is sent over the virtual interface.

IPAddresses and the Dial-Up VPN Client

For dial-up VPN clients who connect to the Internet before creating a VPN connection with a VPN server on the Internet, two IP addresses are allocated:

?

When creating the PPP connection, IPCP negotiation with the ISP NAS assigns a public IP address.

?

When creating the VPN connection, IPCP negotiation with the VPN server assigns an intranet IP address. The IP address allocated by the VPN server can be a public IP address or private IP address, depending on whether your organization is implementing public or private addressing on its intranet.

In either case, the IP address allocated to the VPN client must be reachable by hosts on the intranet and vice versa. The VPN server must have appropriate entries in its routing table to reach all the hosts on the intranet and the routers of the intranet must have the appropriate entries in their routing tables to reach the VPN clients.

The tunneled data sent through the VPN is addressed from the VPN client's VPN server-allocated address to an intranet address. The outer IP header is addressed between the ISP-allocated IP address of the VPN client and the public address of the VPN server. Because the routers on the Internet only process the outer IP header, the Internet routers forward the tunneled data to the VPN server's public IP address.

An example of dial-up client addressing is shown in Figure 9.14 where the organization uses private addresses on the intranet, and the tunneled data is an IP datagram.

Figure 9.14 Public and Private Addresses in PPTP Tunneled Data

DefaultRoutes and Dial-Up Clients

When a typical dial-up client dials the ISP, it receives a public IP address from the ISP NAS. A default gateway address is not allocated as part of the IPCP negotiation process. Therefore, in order to reach all Internet addresses, the dial-up client adds a default route to its routing table using the dial-up interface connected to the ISP. As a result, the client can forward the IP datagrams to the ISP NAS from where they are routed to its Internet location.

For dial-up clients with no other TCP/IP interfaces, this is the wanted behavior. However, this behavior can cause confusion for dial-up clients that have an existing LAN-based connection to an intranet. In this scenario, a default route already exists pointing to the local intranet router. When the dial-up client creates a connection with their ISP, the original default route remains in the routing table but is changed to have a higher metric. A new default route is added with a lower metric using the ISP connection.

As a result, the intranet locations that are not on the dial-up client's directly attached network are not reachable for the duration of the connection to the ISP. If the new default route is not created, all intranet locations are reachable, but Internet locations are not.

A Windows 2000?based dial-up client creates the default route by default.

To prevent the default route from being created

?

In the properties of the TCP/IP protocol of the dial-up connection object, in the Advanced TCP/IP Settings dialog box, click the General tab, and then clear the Use default gateway on remote network check box.

To achieve connectivity to both intranet and Internet locations while the ISP connection is active, leave the Use default gateway on remote network option selected and add the routes of the intranet to the routing table of the dial-up client. The intranet routes can be added through static persistent routes using the route utility, or, if Routing Information Protocol (RIP) version 1 is being used as the intranet routing protocol, you can use the Route Listening Service to listen to RIP version 1 routing protocol traffic and dynamically add intranet routes. When connected to the ISP, all intranet locations are reachable using the intranet routes and all Internet locations are reachable using the default route.

Default Routes and VPNs over the Internet

When the dial-up client calls the ISP, it adds a default route using the connection to the ISP as shown in Figure 9.15. At this point, it can reach all Internet addresses through the router at the ISP NAS.

Figure 9.15 Default Route Created When Dialing an ISP

When the VPN client creates the VPN connection, another default route and a host route to the IP address of the tunnel server are added, as illustrated in Figure 9.16. The previous default route is saved but now has a higher metric. Adding the new default route means that all Internet locations except the IP address of the tunnel server are not reachable for the duration of the VPN connection.

Figure 9.16 Default Route Created When Initiating the VPN

Just as in the case of a dial-up client connecting to the Internet, when a dial-up VPN client using voluntary tunneling creates a VPN connection to a private intranet across the Internet, one of the following occurs:

?

Internet locations are reachable and intranet locations are not reachable when the VPN connection is not active.

?

Intranet locations are reachable and Internet locations are not reachable when the VPN connection is active.

For most Internet-connected VPN clients, this behavior does not represent a problem because they are typically engaged in either intranet or Internet communication, not both.

For VPN clients who want concurrent access to intranet and Internet resources when the VPN is connected, the solution depends on the nature of the IP addressing in the intranet. In all cases, configure the VPN connection object so that it does not add a default gateway. When the VPN connection is created, the default route remains pointed to the ISP NAS, allowing access to all Internet addresses.

Based on the type of intranet addressing you use, enable concurrent access to intranet and Internet resources as follows:

Public Addresses    Add static persistent routes for the public network IDs of the intranet using the IP address of the VPN server's virtual interface as the gateway IP address.

Private Addresses    Add static persistent routes for the private network IDs of the intranet using the IP address of the VPN server's virtual interface as the gateway IP address.

Overlapping or Illegal Addresses    If the intranet is using overlapping or illegal addresses (IP network IDs that are not private and have not been registered by Internet Network Information Center [InterNIC] or obtained from an ISP), those IP addresses might be duplicated by public addresses on the Internet. If static persistent routes are added on the VPN client for the overlapping network IDs of the intranet, the locations on the Internet for the overlapping addresses are not reachable.

In each of these cases, static persistent routes for the network IDs of the intranet need to be added to the VPN client. When the persistent routes are added, they are saved in the registry. With Windows NT 4.0 Service Pack 3 and later and with Windows 2000, the persistent routes are not actually added to the IP routing table (and are not visible with the route print command at the Windows 2000 command prompt) until the IP address of the gateway is reachable. The IP address of the gateway becomes reachable when the VPN connection is made.

For each route, type the following route utility syntax at a Windows 2000 command prompt:

ROUTE ADD <Intranet Network ID> MASK <NetMask> <IP address of VPN server's virtual interface> -p

The gateway IP address in the route commands for each intranet route is the IP address assigned to the VPN server's virtual interface, not the IP address of the VPN server's Internet interface.

You can determine the IP address of the VPN server's virtual interface from the IP address of the Internal interface under IP Routing - General in the Routing and Remote Access snap-in. If you use DHCP to obtain IP addresses for dial-up networking and VPN clients, the IP address of the VPN server's virtual interface is the first IP address obtained when requesting DHCP addresses. If you have configured a static IP address pool, the IP address of the VPN server's virtual interface is the first IP address in the static IP address pool. You can also determine the IP address of the VPN server's virtual interface by double-clicking the virtual private networking connection object when the VPN connection is active. In the resulting Status dialog box, click the Details tab.

caution-icon

Caution

For all of these cases, you must add the routes very carefully to ensure that the private traffic to the intranet is forwarded using the VPN connection and not the PPP connection to the ISP. If the wrong routes are added, the traffic that you intend to forward across the VPN in an encrypted form is instead sent unencrypted across the Internet. For example, if your intranet is using the public network ID 207.46.130.0/24 (subnet mask 255.255.255.0), and you mistakenly add a persistent static route for 207.46.131.0/24, all traffic to the intranet network 207.46.130.0/24 is forwarded across the Internet in plaintext, rather than being encrypted and sent across the VPN connection.

Source : MS TechNet

And

OpenVPN 설치및 사용하기

|

OpenVPN 설치및 사용하기

1.1 시작하며


이글은 VPN (Virtual Priviate Network)을 리눅스나 윈도우즈 상에서 쉽게 구축할 수 있도록 해주는 OpenVPN ( http://www.openvpn.net ) 프로그램을 설치하고 설정하고 운영하는 방법을 설명한다.

처음에는 OpenVPN 사이트에 있는 HOWTO를 번역할 생각이었으나 영어에 대한 압박과 원본 HOWTO 자체가 그리 깔끔하지 못해 아예 새로 적어 보려고 한다. 원본 HOWTO 보다 더 깔끔하게 할 수 있을지는 모르지만...

1.2 VPN 이란

VPN 이야기는 많이 들어 보았을 것이다. 이것이 왜 필요한 것인가? 문제는 보안이다. 만약 내가 다시는 회사에 중요한 서버들이 있다고 하자.

이 서버를 회사내에서는 접속이 가능하고 비교적 보안도 유지시킬 수 있지만 우리가 출장을 가거나 해서 호텔등에서 우리 회사의 서버로 접속하는 경우가 있을 수 있다.

우선 이를 위해서는 회사 서버가 외부에서 연결되도록 열여 주어야 하는 문제가 생긴다(해커들의 공격 대상이 될수 있다).


더우기 호텔에서 회사 서버로 연결할 경우 호텔의 망관리자나 다른 호텔 넷트웍 사용자가 마음만 먹으면 내가 접속하는 서버와 내가 읽고 보내는 정보를 엿볼 수 있게 된다.

이것을 막기 위해 우리는 ssh같은 방식으로 shell을 접근하거나 ssl로 웹서버를 접속한다.


그러나 우리가 사용하고자 하는 서비스가 Samba나 회사의 DBMS등이면 단순이 하나의 프로토클을 암호화 하는 것으로 문제는 쉽게 해결되지 않는다. 그리고 설정또한 상당히 복잡해 진다.


우리는 Point-to-Point 암호화, 즉 내 컴퓨터에서 회사 서버로 주고 받는 모든 패킷의 암호화가 필요한 것이고 이를 위해서는 VPN이 필요한 것이다.

다시 강조하자면 VPN은 ssh 터널이나 ssl 터널같이 하나의 포트를 암호화 한다음 포워딩하는 것이 아닌 전체 패킷을 암호화 한다음 서버와 통신하는 것이다.

1.3 OpenVPN

이 중에서도 [http]윤석찬씨가 소개해준 OpenVPN이 가장 인기가 있었다. 더 자세한 정보는 SlashDot 에서 토론한 내용을 참고하기 바란다.

1.3.1 간단한 동작 원리


필자도 이쪽 전문가는 아니지만 며칠동안 읽어본바에 의해 간단한 동작 원리를 설명해 보려 한다. VPN은 서버와 클라이언트간의 모든 패킷을 Symmetric 열쇠를 이용하여 함호및 복호한다.

이때 Symmetric 열쇠를 안전하게 클라이언트와 서버간에 공유하는 것과 가능하다면 그 열쇠를 자주 자주 바꾸어 주는 것이 보안상 중요한데 이를 위해서는 서버와 클라이언트간의 안전한 통신 채널이 필요하다.

이를 위해 공개열쇠 방식을 사용해서 안전한 채널을 만든다음 서로 Symmetric 열쇠를 공유한다.

이 열쇠는 패킷의 암호화에 사용되고 기본적으로 OpenVPNBlueFish라는 아직까지 오류가 없는 것으로 알려진 암호화 방식을 사용한다.

그래서 각각 서버와 클라이언트들 마다 각각의 열쇠가 있어야 한다. 그런데 서로 이 열쇠를 어떻게 신뢰할 수 있을까?

바로 CA를 이용해서 한곳에서 열쇠를 만들어 서버와 클라이언트들에 열쇠를 복사하는 것이다. 더 자세한 사항은 열쇠를 만들때 더 설명한다.

(필자가 이부분 전문가가 아니라 혹 틀린 부분이 있다면 직접 수정하시거나 저에게 알려 주세요.)

1.4 서버

그럼 서버부터 설치하고 설정하는 방법을 설명한다.

1.4.1 설치 하기


설치를 위한 파일들은 http://openvpn.net/download.html 에서 다운로드 가능하다. 중요한 파일들이므로 파일들의 서명을 다음에서 확인하는 것도 도움이 된다. http://openvpn.net/sig.html

OpenVPN 프로그램은 서버와 클라이언트 공용이다. 여기서 서버는 리눅스에 클라이언트는 윈도우에 설치하는 것을 예로 설명한다.

서버용으로 우선은 리눅스용 Source Tarball을 다운 받는다. RPM과 YUM등으로도 다운과 설치가 가능할 것이지만 여기서는 소스를 컴파일 한다.

간단히:
    tar xfz openvpn-[version].tar.gz
    cd openvpn-[version]
    ./configure --prefix=/usr/local/openvpn
    make
    make install

그러면 /usr/local/openvpn/sbin 에 openvpn 이라는 실행파일이 생겨났을 것이다.

1.4.2 열쇠 만들기


우선 우리는 VPN서버와 클라이언트를 위해 열쇠를 만들어야 한다. 필요한 열쇠들은 CA(Certificate Authority), 서버, 그리고 클라이언트 열쇠이고 추가로 Diffie Hellman parameters 가 필요하다.

OpenVPN은 열쇠생성을 위한 스크립트를 제공하므로 열쇠를 아주 쉽게 만들 수 있다.

우선 소스를 푼 디렉토리로 가면 easy-rsa 디렉토리를 찾을 수 있을 것이다. 만약 rpm이나 yum으로 설치 했다면 /usr/share/doc/packages/openvpn 나 /usr/share/doc/openvpn-2.0 등의 디렉토리를 찾아 보면 좋을 것이다.

원 HOWTO는 update시 이전 파일들을 보존하기 위해 이 파일들을 /etc/openvpn 등으로 복사할것을 권장한다.

우선 vars 라는 파일을 열어 제일 아래쪽에 있는 변수를 수정한다. 필자의 경우 아래와 같이 하였다.

# These are the default values for fields
# which will be placed in the certificate.
# Don't leave any of these fields blank.
export KEY_COUNTRY=US
export KEY_PROVINCE=MA
export KEY_CITY=Cambridge
export KEY_ORG="OpenVPN-Server"
export KEY_EMAIL="hunkim@gmail.com"

. vars를 실행시켜 열쇠 생성을 위한 기본적인 변수들이 설정되게 한다.

그런다음 ./clean-all (기존 열쇠들을 지운다), ./build-ca 를 실행 시킨다. 그러면 ca.crt 와 ca.key를 생성 시킨다. 이제 부터 생겨날 모든 열쇠들은 현재 디렉토리 keys라는 디렉토리에 생성된다.

이제 CA 열쇠가 생성되었으면 서버에 사용할 열쇠를 만든다.

./build-key-server server

Common Name 을 물어 오면 'server'를 입력한다. 그리고 다음 두개의 질문에 Yes 라고 답한다.
  • Sign the certificate? y/n
  • 1 out of 1 certificate requests certified, commit? y/n

그럼 서버에 사용할 server.crt 와 server.key 가 생성되었을 것이다. 서버는 Diffie Hellman parameters 를 생성시켜야 한다. 간단하게 build-dh 를 실행시키면 된다.
    # ./build-dh
    Generating DH parameters, 1024 bit long safe prime, generator 2
    This is going to take a long time
    .................+...........................................
    ...................+.............+.................+.........
    ......................................

이것으로 서버에서 사용할 열쇠들은 모두 생성되었다.

클라이언트들에서 사용할 열쇠들을 생성시켜야 하는데 이는 서버에서 (또는 ca.key 가 있는 서버에서) 만든다. 각각의 클라이언트들마다 각기 다른 클라이언트 열쇠가 필요하다.


그래서 100개의 클라이언트가 있다면 열쇠만들기를 100번 해야 한다. 여기서는 hunkim 을 위한 클라이언트 열쇠 하나만 만든다. (리눅스 계정을 통한 추가인증 또는 단독인증 방법은 아래에서 설명한다.)

./build-key hunkim

서버때와 비슷하게 Common Name은 hunkim 을 입력한다. 각각 클라이언트마다 서로다른 Common Name을 주어야 한다.

그리고 다음 두개의 질문에 Yes 라고 답한다.
 * Sign the certificate? [y/n]
 * 1 out of 1 certificate requests certified, commit? [y/n]

각 클라이언트로 우리가 만든 클라이언트 열쇠 (hunkim.crt, hunkim.key) 그리고 ca.crt를 안전한 방법으로 복사해야 한다. 디스켓으로 복사하거나 sftp 등으로 복사하면 된다.

이메일이나 ftp로 복사하는 것은 좋은 방법이 아니다.

그럼 우리가 필요료 하는 모든 열쇠들이 만들어 졌다. 만들어진 열쇠들을 한번 살펴보자 (OpenVPN HOWTO에서 가져왔습니다.)

Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dh{n}.pem server only Diffie Hellman parameters NO
server.crt server only Server Certificate NO
server.key server only Server Key YES
hunkim.crt hunkim only hunkim Certificate NO
hunkim.key hunkim only hunkim Key YES

여기서 Secret가 YES된 열쇠들은 알아서 잘 보관하기 바란다. 아니면 VPN서버와 클라이언트 사이에 패킷을 엿듣는 middle-man 공격이 가능해진다.

1.4.3 환경설정

우선 서버 환경을 설정하기 전에 몇가지 결정해야 할 사항들이 있다. VPN으로 서버와 클라이언트간에 연결이 되면 VPN을 위한 새로운 주소가 서버와 클라이언트에 할당된다.

이 주소를 결정해야 하는데 혹 회사 내부의 망과 충돌이 없는지 확인하면 된다.

10.8.0.0/255.255.255.0 을 사용하기를 권한다.

두번째는 TCP와 UDP중 어느 프로토콜을 사용할지에 대한 것인데 UDP는 대부분의 환경에서 잘 동작한다.

<!> 여기서 주의할 점은, 서버가 UDP를 쓰면 클라이언트도 UDP를 쓰도록 설정해야 한다는 것이다.

마지막은 route 방식을 사용할 것인지 브릿지 방식을 사용할지에 대한 결정이다. 간단한 설정을 위해 route 방식을 사용하기를 권한다.

OpenVPN의 설정 파일은 하나이다. 소스 디렉토리나 /usr/share/doc/packages/openvpn 나 /usr/share/doc/openvpn-2.0 등을 보면 server.conf 라는 예제 서버 설정 파일이 있을 것이다.

10.8.0.0 을 사용하고 UDP를 사용하고 route 방식을 사용하기를 원한다면 예제 파일을 대부분 그대로 사용할 수 있다.

한가지 수정이 필요한것은 우리가 생성한 열쇠들을 지정하는 부분이 있는데 이를 여러분이 생성한 열쇠들을 바르게 가르키도록 설정해 주면 된다.

아래의 server.conf의 경우, keys/*파일이 server.conf파일이 있는 디렉토리에 같이 있어야 한다.
# server.conf
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca keys/ca.crt
cert keys/server.crt 
key keys/server.key  # This file should be kept secret

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh keys/dh1024.pem

마지막으로 중요한 것은 혹시 OpenVPN 서버가 방화벽 내부에 들어 있을 경우 UDP/1194 번을 열어 주어야 한다는 것이다. 그렇지 않으면 클라이언트가 OpenVPN 서버로 접속할 수 없게된다.

1.4.4 실행


서버 실행은 아주 간단하다. openvpn을 실행시키면서 server.conf 파일의 위치를 알려 주면 된다.그러면 로그에 해당하는 부분을 화면으로 출력해 줄 것이다 (이 로그는 원하는 파일로 보낼 수 있다).

# /sbin/openvpn server.conf 

Wed Dec 27 04:06:51 2006 OpenVPN 2.0.9 i686-intel-linux [SSL] [LZO] [EPOLL] built on Dec 26 2006
Wed Dec 27 04:06:51 2006 Diffie-Hellman initialized with 1024 bit key
Wed Dec 27 04:06:51 2006 TLS-Auth MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Wed Dec 27 04:06:51 2006 TUN/TAP device tun0 opened
Wed Dec 27 04:06:51 2006 /sbin/ifconfig tun0 10.8.0.1 pointopoint 10.8.0.2 mtu 1500
Wed Dec 27 04:06:51 2006 /sbin/route add -net 10.8.0.0 netmask 255.255.255.0 gw 10.8.0.2
Wed Dec 27 04:06:51 2006 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Wed Dec 27 04:06:51 2006 UDPv4 link local (bound): [undef]:1194
Wed Dec 27 04:06:51 2006 UDPv4 link remote: [undef]
Wed Dec 27 04:06:51 2006 MULTI: multi_init called, r=256 v=256
Wed Dec 27 04:06:51 2006 IFCONFIG POOL: base=10.8.0.4 size=62
Wed Dec 27 04:06:51 2006 IFCONFIG POOL LIST
Wed Dec 27 04:06:51 2006 hunkim,10.8.0.4
Wed Dec 27 04:06:51 2006 Initialization Sequence Completed


서버로서 계속 OpenVPN 프로그램이 실행되게 하려면 rc 스크립트등에 넣어 주어야 하는데 이는 원본 HOWTO나 자신이 사용하는 리눅스 배포판의 설명서에서 정보를 얻을 수 있을 것이다.

1.5 클라이언트

이제 서버가 완성되었으니 클라이언트를 설치해 보고 서버가 잘 동작되는지 시험해 보자. 클라이언트는 윈도우즈에서 실행된다고 가정하고 설명한다. (리눅스등은 유사한 방법으로 설치및 실행이 가능하다.)

1.5.1 설치하기


이를 위해 우선 클라이언트에 필요한 프로그램을 다운 받자. OpenVPN GUI for Windows (http://openvpn.se/) 를 추천한다.

이 프로그램을 설치하면 최신 OpenVPN및 GUI 프로그램을 다 한번에 설치하기 때문애 편리하게 설치 할 수 있다.

Installation Package (Both 32-bit and 64-bit TAP driver included)를 다운 받아 이 설치 프로그램을 실행 시킨다. 대부분은 기본으로 설정으로 설치를 한다.

설치중 아래와 같이 TAP-Win32 Adapter를 자동으로 설치해 주는데 이 프로그램은 M$ 의 서명은 받지 않았지만 "계속"을 눌러 설치를 한다.

openvpn1.png

설치가 완료된루 OpenVPN GUI가 자동으로 실행되어 윈도우 Tray에 보면 OpenVPN GUI 아이콘이 나타날 것이다.

openvpn2.png

1.5.2 키 복사하기


그럼 이제 서버 설치 과정에서 생성 시킨 클라이언트용 열쇠들을 (ca.crt, hunkim.key, hunkim.crt) 적당한 위치로 복사 한다.

다시 강조하지만 이 키들을 서버에서 받아올때 각별한 주의를 요한다. (sftp나 PGP 메일등의 방법 사용)

필자의 경우 열쇠들을 C:\Program Files\OpenVPN\config 로 복사 했다.

키 파일 없이 접속하는 방법은 아래쪽에 별도로 설명한다.

1.5.3 환경설정


클라이언트도 하나의 설정파일이 필요한데 (윈도우즈는 .ovpn 파일이다), 예제 파일들이 C:\Program Files\OpenVPN\sample-config 에 준비 되어 있다.

이중 client.ovpn 을 config 디렉토리 (C:\Program Files\OpenVPN\config) 로 복사한다. 이곳이 윈도우즈 OpenVPN GUI프로그램이 사용하는 기본 디렉토리이다.

그런다음 Tray에 있는 OpenVPN GUI 아이콘에서 오른쪽 마우스를 누르면 메뉴가 나타나는데 이중 Edit Config 를 선택하면 우리의 친구 노트패트가 열리면서 설정파일을 편집할 수 있도록 해준다.

openvpn3.png

우선 Open VPN 서버를 지정한다.

...
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote vpn.mit.edu 1194
...

만약 서버를 UDP, route 방식으로 설정하였으면 이제 열쇠 지정 부분만 수정하면 된다.

윈도우에서는 열쇠의 위치를 루트 디렉토리 부터 정확하게 지정해준다.

...
# 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 "C:\\Program Files\\OpenVPN\\config\\ca.crt"
cert "C:\\Program Files\\OpenVPN\\config\\hunkim.crt"
key "C:\\Program Files\\OpenVPN\\config\\hunkim.key"
...

그밖에, 서버에서 tun을 쓰면 client도 tun을 쓰도록하고, 서버가 TCP를 쓰면 클라이언트도 TCP를 쓰도록 해야 한다.
# 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
....
# Are we connecting to a TCP or UDP server?  Use the same setting as
# on the server.
;proto udp
proto tcp
...
이것으로 클라이언트의 모든 설정은 끝이 났다.

1.5.4 서버연결

이제 다시 Tray에 있는 OpenVPN 메뉴의 Connect를 이용해서 서버에 연결해 본다. 그러면 Status 창을 통해 연결상황을 보여준다.

Tray에 있는 아이콘이 연결중에는 노란색으로, 성공적으로 연결된후에는 초록색으로 바뀐다. 연결이 안되어 있을때에는 빨간색이다.

혹 연결이 안되거나 문제가 생기면 OpenVPN 아이콘 메뉴에 있는 View Log 를 통해 문제점을 살펴 볼 수 있다. 참고로 열쇠 설정이 잘못되면 아래와 같은 메시지가 나온다.

Tue Dec 26 15:32:45 2006 Cannot load CA certificate file C:\Program Files\OpenVPN\config\ca.crt (SSL_CTX_load_verify_locations): 
  error:02001002:system library:fopen:No such file or directory: error:2006D080:BIO routines:BIO_new_file:no such file: 
  error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
Tue Dec 26 15:32:45 2006 Exiting

성공적으로 연결되면 OpenVPN GUI 아이콘 색깔이 초록색으로 바뀌면서 10.8.0.x 의 번호가 할당되었다는 메시지가 나온다.

openvpn4.png

그럼 이제 다른 방법으로 서버와 연결이 확실한지 알아 보자. 우선 서버의 로그 메시지를 살펴보자.

그런다음 클라이언트에서 서버로 Ping을 해보자. 참고로 서버의 IP는 10.8.0.1 이다.

(윈도우즈에서 cygwin의 shell을 사용했다.)
$ ping 10.8.0.1
PING 10.8.0.1 (10.8.0.1): 56 data bytes
64 bytes from 10.8.0.1: icmp_seq=0 ttl=64 time=260 ms
64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=216 ms

----10.8.0.1 PING Statistics----
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max/med = 216/238/260/238

반대로 서버에서는 클라이언트로 ping을 보내면 클라이언트도 반응을 해야 한다.
server $ ping 10.8.0.6
PING 10.8.0.1 (10.8.0.6): 56 data bytes
...

Ping이 성공적으로 되었다면 이제 서버로 접속할때는 10.8.0.1 주소로 접속을 하면 안전하게 모든 패킷이 서버로 전달된다.

1.6 추가 설정


위의 기본 설정으로 간단하게 VPN이 연결되었다. 여기서는 추가적인 설정에 대해 설명한다.

1.6.1 추가적 사용자 인증

각 클라이언트들은 자신의 열쇠들을 가지고 VPN 서버에 접속한다. 즉 이 키를 가진 사람들은 VPN 서버로 접속이 가능하다. 이 키들이외에 추가로 서버족에서 클라이언트 접속을 인정하고 싶다면 어떻게 해야 할까? 예를 들어 리눅스 서버에 있는 사용자 아이디와 비밀번호를 가진 사람들만 OpenVPN 서버에 접속하게 하고 싶다면...

OpenVPN은 추가적인 인증 방식을 지원하며 이중 PAM방식을 이용한 인증 프로그램은 이미 배포판에 포함되어 있다. 추가 인증을 위해서는 우선 클라이언트 설정 파일에 auth-user-pass 를 추가 한다.

서버쪽 설정 파일에는 PAM인증을 위해 다음을 추가 한다.

plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so login


이때 openvpn-auth-pam.so 의 정확한 위치를 설정해야 한다. 그런다음 다시 서버를 구동하고 클라이언트로 접속을 하면 아래와 같이 아이디와 비밀번호를 물어 온다.

openvpn5.png

이 비밀번호가 정확할때만 접속이 가능하다. 이 비밀번호는 물론 안전한 방법으로 서버로 보낸다.

1.6.1.1 사용자/비밀번호 만으로 인증하기


여기까지 설명 방법으로에서는 각 클라이언트의 열쇠들의 인증 방식의 추가로 리눅스 상의 사용자 아이디/비밀번호로 인증하는 방법을 살펴 보았다.

이전 열쇠를 만드는 방법에서 설명한것 처럼 각 클라이언트마다 각각의 열쇠를 만들어야 하고 이를 안전하게 클라이언트로 복사해야 하는데 이는 매우 성가신 일이 아닐 수 없다.


그러한 이유로 보안상 권장하지는 않지만 VPN 서버 접속시 리눅스 상의 사용자 아이디/비밀번호만으로 인증하는 방법도 제공한다.

다음의 두 줄을 서버의 설정 파일에 추가 한다. (서버의 설정파일이 server.conf라면 그 파일에)

...
client-cert-not-required
username-as-common-name
...

그리고 클라이언트에서는 cert와 key 부분의 열쇠를 지정하지 않으면 된다. 그러나 ca는 VPN 서버의 열쇠를 인정하기 위해 클라이언트로 복사 되어야 하며 정확하게 지정되어야 한다.
...
ca "C:\\Program Files\\OpenVPN\\config\\my-server.ca.crt"
...

1.6.2 서버쪽의 다른 서버들 연결하기 (도움 필요)


이전까지의 연결은 서버와 1:1 (point-to-point)방식으로 서버와 클라이언트간에만 서로 패킷이 암호화 된다. 만약 서버가 있는 쪽 다른 서버들 (서버와 같은 넷트웍에 있는)에 접속하고 싶다면 어떻게 해야 하나?

여기서는 여러분이 routed VPN(dev tun)을 사용하고 있다고 가정합니다.

우선 서버가 있는 넷트웍이 128.30.0.0/8 이라고 가정하자. 우선 서버에서 이들의 주소를 클라이언트로 알려 주어야 한다. 다음의 한줄을 서버의 설정에 추가 한다.

push "route 128.30.0.0 255.255.255.0"

Next, you must set up a route on the server-side LAN gateway to route the VPN client subnet (10.8.0.0/24) to the OpenVPN server (this is only necessary if the OpenVPN server and the LAN gateway are different machines).

'이부분은 제가 LAN gateway의 설정 권한이 없어서 실험을 못했습니다. 혹시 시험하실 수 있으신 분들은 저에게 알려 주시면 감사하겠습니다.'

그런후 반드시 IP forwarding 을 가능하게 설정해 주시고:
On Linux, use the command:

    echo 1 > /proc/sys/net/ipv4/ip_forward

TUN도 forwarding이 가능하도록 설정 한다:
# Allow TUN interface connections to OpenVPN server
iptables -A INPUT -i tun+ -j ACCEPT

# Allow TUN interface connections to be forwarded through other interfaces
iptables -A FORWARD -i tun+ -j ACCEPT

그런다음 다시 OpenVPN으로 접속하신 다음 해당 서버들을 접속하면 된다.

1.6.3 전체 트래픽을 서버로 라우팅 하기


이전의 설정을 통해 VPN 서버에 접속하면 서버와 클라이언트 (point-to-point) 또는 크라이언트 와 서버넷들의 연결만 암호화가 되었다. 그러나 어떨때는 외부에 있는 사용자가 자신이 사용하는 전체 트래픽을 서버로 암호화 한다음 라우트 할 필요가 있다. 예를 들어 외부에서 내가 구글 메일이나 구글톡등을 사용할때 누군가가 이 메일이나 톡의 정보를 엿볼 수 있기 때문이다.

VPN으로 서버와 또는 서버넷으로는 암호화로 연결된다고 해도 그 외의 넷트웤(보통 인터넷) 트래픽은 직접 해당하는 서버와 암호화 되지 않고 연결된다.

즉 아래 그림과 같이 VPN을 사용하는 중에도 어떤 사용자가 A라는 기관에서 구글톡을 하게 되면 A기관의 망 관리자는 쉽게 그 내용을 엿 들을 수 있게 된다.

openvpn6.png

그래서 아래 그림과 같이 전체 트래픽을 VPN 서버로 보내고 VPN 서버에서 구글 톡이나 다른 서버로 연결할 수 있다면 A기관의 망 관리자는 그 내용을 전혀 알 수 없게 된다.

openvpn7.png

물론 VPN 서버에서 외부로 나가는 정보는 암호화가 되지 않고 또 감시당할 수도 있지만 VPN서버를 둔 곳은 자신의 집이나 회사기 때문에 비교적 믿을만하다고 가정한다.

이 방법은 서버쪽 넷트웍에 있는 다른 서버들과의 안전한 연결을 위해서도 사용할 수 있다. 즉 서버쪽의 넷트웍에 있는 서버가 자체 넷트웍에서만 연결되고 외부에서는 차단되도록 해놓는 다면 OpenVPN 서버 접속을 통해서 내부망에 있는 서버들과의 접속이 가능하기 때문이다. 마치 자신이 그 내부망에서 컴퓨터를 연결한것과 같아 진다.

이 유용한 방법은 여러모로 쓸모가 많지만 설정은 아주 간단하다. 다음의 한줄을 서버쪽 설정에 추가 한다.

# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# the TUN/TAP interface to the internet in
# order for this to work properly). 
# CAVEAT: May break client's network config if
# client's local DHCP server packets get routed
# through the tunnel.  Solution: make sure
# client's local DHCP server is reachable via
# a more specific route than the default route
# of 0.0.0.0/0.0.0.0.
push "redirect-gateway def1"

그런후 몇가지 간단한 추가 설정이 필요한데 우선 IP forwarding 을 가능하게 설정해 주시고:
On Linux, use the command:

    echo 1 > /proc/sys/net/ipv4/ip_forward

VPN이 10.8.0.0/24 주소를 사용하고 서버의 기본 넷트웍 장치가 eth0이라 가정 하면 아래의 명령으로 NAT를 통해 VPN 클라이언트의 트래픽을 인터넷으로 보낼 수 있도록 해준다.

    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

그러면 클라이언트의 모든 트래픽 (DNS 쿼리를 포함)이 서버를 거치므로 DNS는 서버는 VPN 서버에서 가까운 쪽이나 또는 VPN 서버 자체가 DNS 서버를 겸하면 좋다. 이를 위해서는 아래 한줄의 추가로 자동으로 클라이언트 DNS를 설정해 줄 수 있다.

    push "dhcp-option DNS 10.8.0.1"

그런후 이제 다시 클라이언트의 OpenVPN GUI프로그램을 통해 접속을 해보자. 그런다음 클라이언트 쪽의 TCP/IP 설정을 보자.

Ethernet adapter Local Area Connection 7:

        Connection-specific DNS Suffix  . : 
        Description . . . . . . . . . . . : TAP-Win32 Adapter V8
        Physical Address. . . . . . . . . : 00-FF-51-C4-40-4B
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 10.8.0.6
        Subnet Mask . . . . . . . . . . . : 255.255.255.252
        Default Gateway . . . . . . . . . : 10.8.0.5
        DHCP Server . . . . . . . . . . . : 10.8.0.5
        DNS Servers . . . . . . . . . . . : 10.8.0.1
        Lease Obtained. . . . . . . . . . : Tuesday, December 26, 2006 4:43:57 PM
        Lease Expires . . . . . . . . . . : Wednesday, December 26, 2007 4:43:57 PM

Default Gateway 와 DNS Servers 가 10.8.0.1 로 설정된것을 알 수 있다. 우선 연결이 잘되었는지 보기 위해서는 웹사이트를 접속해보자. 이때 인터넷 연결 속도가 매우 떨어지는 것을 느낀다면 VPN 서버로 접속이 된 것이다. 더 확실히 하기 해서는 클라이언트에서 http://www.checkmyip.com/ 등을 접속해보자. IP번호가 클라이언트가 아닌 서버의 것이라면 확실하게 연결이 된것이다. 이제부터 사용자가 사용하는 모든 넷트웍 (모든 인터넷, 모든 프로토클)은 OpenVPN 서버까지 안전하게 전달된후 서버를 통해 연결이 된다.


이 방법은 서버에서 설정을 해 주었을 경우에만 가능하다. 서버에서 이 기능을 제공해 주지 않을 경우 client 에서 옵션이 있는지 찾아 보았지만 찾을 수 없어.. 강제 라우팅을 변경하는 방법을 적어 본다. 이 방법은 client 에서 행하며 windows 에서의 명령행이다. (기타 OS 에서는 DIY 하기 ^^)

// 기존의 default gateway 를 제거
route DELETE 0.0.0.0

// VPN_SERVER_IP 를 gateway 로 잡는다. 이때 중요한 것은 P-2-P 의 VPN 측 IP
// 로 잡아야 한다. 아무생각 없이 VPN server 의 real IP 를 잡으면 대략 낭패다.
//
// OpenVPN 은 route 방식과 bridge 방식이 있는데, 두가지 모드 중에서 VPN_SERVER_IP
// 는 다음과 같다.
// 
// * route 방식
// 서버측에 "server 192.168.100.0 255.255.255.0" 라는 설정이 있다면 192.168.100.1
// 로 설정을 하면 될 것이다. route 방식은 필자가 직접 한 것이 아니라 추측이다.
//
// * bridge 방식
// 서버측에 "server-bridge 192.168.100.1 255.255.255.0 192.168.100.2 192.168.100.254"
// 와 같이 설정이 되어 있다면 192.168.100.1 로 사용하면 된다.
route ADD 0.0.0.0 MASK 0.0.0.0 VPN_SERVER_IP

위와 같이 default gateway 를 VPN 으로 변경하면 모든 트래픽은 VPN 서버를 통해서 가게 될 것이다. VPN 을 끊으면 역시 수동으로 gateway 를 복구해 줘야 한다. (VPN 서버에서 설정을 해 주면 자동으로 복구가 되나, 수동으로 GW 를 변경하면, 복원시에도 수동으로 해 주어야 한다. 복구 방법은 위의 VPN_SERVER_IP 를 기존의 gateway 로 바꿔서 실행해 주면 된다.

변경을 하려고 할때 만약 서버측의 설정을 모른다면.. 대충 할당 받은 대역의 첫번째 IP 를 잡아 주면 될거다.. 아마도 -- oops

1.7 마치면서


OpenVPN은 기존의 VPN 프로토클인 IPSec 등보다 쉽게 (필자의 경우 하루 정도) 설치, 설정 및 운영이 가능하다. 보안이 필요한 회사나 단체 등은 반드시 OpenVPN등을 이용해 안전한 통신을 할 것을 권한다.

필자도 공부하면서 정리한 내용이라 오류나 잘못된 부분이 많을 것으로 생각한다. 발견되면 직접 수정하시거나 필자에게 알려 주시기 바랍니다. 참고로 OpenVPN 이 상세하게 설명된 책(http://www.packtpub.com/openvpn/book/mid/2405065clw5q) 을 주문해 두었는데 책이 도착하면 잘 읽어 보고 부족한 내용을 보충할 계획이다.
원본 : http://wiki.kldp.org/wiki.php/OpenVPN#s-1
And

OpenVPN 설정 방법

|

1 프로그램 다운로드

 윈도우즈 용은 OpenVPN GUI로, 다운로드는 다음과 같다.

http://openvpn.se/download.html

프로그램 다운로드 : http://openvpn.se/files/install_packages/openvpn-2.0.9-gui-1.0.3-install.exe

 

2. 설치

기본 설치로 하면 Program File\OpenVPN에 깔린다.


3. 키 설정 (http://openvpn.net/howto.html#pki)

1) 준비

  - 커맨드 쉘로  \Program Files\OpenVPN\easy-rsa 폴더로 이동


init-config

vars
clean-all

2) 기본 ca 작성

(입력을 편하게 하려면 vars.bat파일의 set KEY_COUNTRY=US등의 내용을 변경하세요... 안해도 무방)

build-ca

다음과 같이 물어봅니다.

Country Name (2 letter code) [KG]:
State or Province Name (full name) [NA]:
Locality Name (eg, city) [BISHKEK]:
Organization Name (eg, company) [OpenVPN-TEST]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:OpenVPN-CA
Email Address [me@myhost.mydomain]:


여기는 적당히 채우세요~

다만 Common Name은 앞으로 만들 키에서 전체적으로 중복되면 안됩니다.


3) 서버 키 작성

build-key-server server

앞에 입력한 것과 비슷하게 나옵니다. Common Name만 다르게 하시고

나머지는 똑같이 입력하세요.

y/n 묻는 건 당연히 y겠죠.


4)클라이언트 키 작성

build-key client1

동시에 여러 클라이언트가 접속한다면 동접 갯수만큼 client1를 숫자나 적당한 것으로 바꿔서 키를 만들면 됩니다. client1를 원하는 이름으로 바꾸세요.

예를 들어 세명이 동시에 사용한다면

build-key client1

build-key client2build-key client3

이런식으로 만들어 주면 되겠죠.

그리고 처음 키를 만들때와 같은 걸 물어보는데 Common name에 client1같은 각각의 이름을 넣어주면 됩니다.


4. DH parameter 생성

build-dh


5. ta 키 생성

keys 디렉토리로 이동해서..

openvpn --genkey --secret ta.key 라고 하면 ta.key가 만들어집니다.


6. key 파일 복사.

config 폴더에 다음과 같은 파일을 복사합니다.

ca.crt

ca.key

dh1024.pem

server.crt

server.key

ta.key


7. Server config 설정

1) sample-config 폴더에서 server.ovpn 파일을 config 폴더로 복사합니다.

2) 복사한 server.ovpn 파일을 메모장으로 열어서 다음 항목을 찾아 필요한 값을 설정합니다.

 port

 proto

 tls-auth ta.key 0

 cipher BF-CBC


port는 원하는 포트번호를 proto는 udp나 tcp를 설정합니다.

tls-auth, cipher 는 앞에 있는 커맨트 ; 를 지워줍니다.

설정이 되었으면 저장하세요.


8. 서버 실행

config 폴더에서 openvpn server.ovpn 이라고 입력합니다.

나오는 내용을 확인해 보시고..에러가 없으면 F3인가 F4인가를 눌러 종료합니다.

그리고 제어판->관리도구->서비스 에서 OpenVPN 서비스를 자동으로 하시고 시작 하시면 컴퓨터가 부팅될 경우 자동으로 실행이 됩니다.


9. 클라이언트 설정

1) 서버와 똑같이 프로그램을 설치합니다. (같은 프로그램으로 서버와 클라이언트를 사용함)


2) 위의 서버에서 만든 다음과 같은 키 파일을 config 폴더에 복사합니다.

ca.crt

ca.key

client1.key

client1.crt

ta.key


3) sample-config 폴더에서 client.ovpn을 config 폴더로 복사합니다.

 이때 client.ovpn을 client1.ovpn으로 이름을 맞춰 주는 게 좋습니다.

(여러곳의 연결설정을 할때 편함)


4) client.ovpn을 메모장으로 열어서 다음 항목을 수정합니다.

proto

remote

cert

key

tls-auth

cipher


; proto는 서버에서 설정한 것으로 udp/tcp로 맞춰주시고, remote는 remote 서버ip 포트번호 로 하시면 됩니다.

cert는 client1.crt

key는 client1.key 로 파일 이름을 맞춰 주세요.

tls-auth는 앞의 ;를 지워주시고

cipher도 서버와 같이 cipher BF-CBC로 맞춰 주시면 됩니다.


5) 연결 확인

openvpn client1.ovpn으로 해보시면 되고

평상시에는 오른쪽 아래의 트레이에 있는 OpenVPN GUI의 오른쪽 클릭을 하면

Connect가 나옵니다. 문제없이 연결되면 아이콘이 초록색으로 변경됩니다.


6) 서버 접속

서버의 ip를 변경할수 있지만 여기서는 기본 설정이므로 10.8.0.1이 서버의 ip입니다.

ping을 해보시던가..리모트 접속을 해보시면 틀린거 없이 하셨다면 연결이 될껍니다.

And
prev | 1 | next