Coolx World - Computer ???
OpenVPN 서버 및 클라이언트 설치 (Linux)
2023-02-13 13:50 - swindler
1. 패키지 설치

yum install openvpn
yum install easy-rsa


# mkdir /etc/openvpn/easy-rsa
# cp -r /usr/share/easy-rsa/3/* /etc/openvpn/easy-rsa


2. Key 생성

# cd /etc/openvpn/easy-rsa
# ./easyrsa init-pki

> 해당 명령어는 CA 생성 및 요청할 수 있는 상태로 만들며,

생성한 키파일은 /etc/openvpn/easy-rsa/pki 경로에 저장됨.



# ./easyrsa build-ca

> ca 암호 입력

> ca 암호 재입력

> ca 명 입력[서버명]

# ./easyrsa gen-req [서버명] nopass

> Enter

# ./easyrsa sign-req server [서버명]

> yes

> ca 암호 입력

./easyrsa gen-dh

> Diffle-Hellman 방식의 보안키 생성



3.server.conf 설정

# cp -a /etc/openvpn/easy-rsa/pki/ca.crt /etc/openvpn

# cp -a /etc/openvpn/easy-rsa/pki/issued/[서버명].crt /etc/openvpn

# cp -a /etc/openvpn/easy-rsa/pki/private/[서버명].key /etc/openvpn

# cp -a /etc/openvpn/easy-rsa/pki/dh.pem /etc/openvpn


설정파일은 아래과 같이 작성함

port 1194
proto tcp
dev tun

ca ca.crt
cert 2hlab.crt
key 2hlab.key
dh dh.pem

server 10.8.0.0 255.255.255.0

push "redirect-gateway def1"
push "dhcp-option DNS 168.126.63.1"
push "dhcp-option DNS 168.126.63.2"


keepalive 10 120

comp-lzo


user nobody
group nobody

persist-key
persist-tun

status openvpn-status.log
log-append openvpn.log

verb 3

client-to-client

duplicate-cn

plugin /usr/lib64/openvpn/plugins/openvpn-plugin-auth-pam.so login

client-cert-not-required

username-as-common-name


4.
# vi /etc/sysctl.conf

net.ipv4.ip_forward = 1 // 맨 밑 줄에 해당 내용 추가



5.
# systemctl restart network.service // 네트워크 재시작

# systemctl enable openvpn@server.service // OpenVPN 서비스 활성화

# systemctl start openvpn@server.service // OpenVPN 서비스 시작



6. 클라이언트는 openvpn 을 설치함
(서버에 계정 설정을 해야함)


클라이언트에서 연결은 정상적으로 되었으나,
vpn을 통한 접속이 되지 않음. 라우팅 문제로 보임

아래와 같이 해결

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o em1 -j MASQUERADE [root@ss sysconfig]# iptables -t nat -A


Copyright © 1999-2020, swindler.

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog