ubuntu 20.0.4 서버에 l2tp vpn 서버 구축

ubuntu 20.0.4에 L2TP를 구축하는 방법 중, 가장 간단한 방법으로 여러가지 기능을 지원하지 않는 단순한 방법을 정리한다.

 

구성 상태

(외부 인터넷) <-----> (공유기 - VPN 연결에 대해서 Portforwarding) <------------> VPN 서버
                          IP:192.168.100.1                            IP:192.168.100.100

 

ubuntu 20.0.4에 설치할 Package 정리

- xl2tpd
- strongswan

 

l2tp 관련 패키지 설치

# apt install xl2tpd strongswan iptables-persistent

 

커널 파리미터 설정 - /etc/sysctl.conf 파일에 아래 내용 추가

# vi /etc/sysctl.conf

# L2TP VPN
kernel.msgmnb = 65536
kernel.msgmax = 65536

net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.eno1.send_redirects = 0
net.ipv4.conf.eno1.rp_filter = 0

net.core.wmem_max = 12582912
net.core.rmem_max = 12582912
net.ipv4.tcp_rmem = 10240 87380 12582912
net.ipv4.tcp_wmem = 10240 87380 12582912

 

iptables 설정 - /etc/iptables/rules.v4 파일에 아래 내용 추가

# L2TP
-A INPUT -p udp -m udp --dport 1701 -m policy --dir in --pol none -j DROP
-A INPUT -m conntrack --ctstate INVALID -j DROP
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p udp -m multiport --dports 500,4500 -j ACCEPT
-A INPUT -p udp -m udp --dport 1701 -m policy --dir in --pol ipsec -j ACCEPT
-A INPUT -p udp -m udp --dport 1701 -j DROP

 

ppp 설정 (접속 ID/PASS 설정) - /etc/ppp/chap-secrets

# vi /etc/ppp/chap-secrets

"test" l2tpd "qwer1234" *

 

ppp 설정 (xl2tpd에서 사용할 설정) - /etc/ppp/options.xl2tpd

# vi /etc/ppp/options.xl2tpd
+mschap-v2
ipcp-accept-local
ipcp-accept-remote
noccp
auth
mtu 1280
mru 1280
proxyarp
lcp-echo-failure 4
lcp-echo-interval 30
connect-delay 5000
ms-dns 8.8.8.8
ms-dns 8.8.4.4

 

 xl2tpd 설정 - /etc/xl2tpd/xl2tpd.conf

# vi /etc/xl2tpd/xl2tpd.conf
[global]
port = 1701

[lns default]
ip range = 192.168.100.200-192.168.100.230
local ip = 192.168.100.100
require chap = yes
refuse pap = yes
require authentication = yes
name = l2tpd
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

 

strongswan 설정 (L2TP 연결에 사용할 비밀키 설정) - /etc/ipsec.secrets

# vi /etc/ipsec.secrets
%any  %any  : PSK "testvpn"

 

strongswan 설정 - /etc/ipsec.conf

# vi /etc/ipsec.conf
config setup
#    nat_traversal=yes

conn %default
    auto=add

conn L2TP-NAT
    type=transport
    left=%any
    leftauth=psk
    right=%any
    rightauth=psk

conn IPSEC-NAT
    authby=xauthpsk
    xauth=server
    keyexchange=ikev1
    leftsubnet=0.0.0.0/0
    leftfirewall=yes
    dpdaction=clear
    right=%any
    rightsourceip=%dhcp

 

서비스 시작하기

# systemctl start strongswan-starter.service