YJWANG

[WireGuard] WireGuard 이용하여 사내 VPN 서버 구축하기 (GUI 관리 콘솔 포함) 본문

00.OS

[WireGuard] WireGuard 이용하여 사내 VPN 서버 구축하기 (GUI 관리 콘솔 포함)

왕영주 2021. 5. 28. 13:12

References


 

ENV


Ubuntu 20.04.1 LTS

 

Intro


WireGuard는 VPN서버 및 클라이언트로 'OpenVPN', 'IPsec' 보다 더 빠르고 간단한 구성을 지원한다고합니다.
또한 UDP 통신을 하며 생성한 key를 통해 데이터를 암호화 하고 복호화하며 통신하도록 구성됐습니다.

WireGuard는 아래 프로토콜들을 사용한다고 합니다. (TCP가 아닌 UDP를 사용하는게 특이하네요)

Curve25519 for key exchange
ChaCha20 for symmetric encryption
Poly1305 for message authentication codes
SipHash for hashtable keys
BLAKE2s for cryptographic hash function
UDP-based only

TCP가 아닌 UDP를 썼지만 `Noise` 프로토콜을 이용해서 handshake를 하여 데이터 신뢰성을 높였다고 합니다. 데이터 Loss에 대한 노파심이 조금 줄어드네요 https://www.wireguard.com/protocol/

 

Configure Server


wg command를 이용하여 peer할 수 있지만 wg-easy 프로젝트가 간단하게 구성할 수 있게 해주었으므로 해당 프로젝트를 이용해서 구축하려합니다.

 

우선 Server에 Docker를 설치합니다.
https://yjwang.tistory.com/132

docker-compose도 설치합니다.
https://yjwang.tistory.com/153

 

필요한 파일 및 dir를 생성합니다.

# mkdir ~/.wg-easy
# cd ~/.wg-easy
# wget https://raw.githubusercontent.com/WeeJeWel/wg-easy/master/docker-compose.yml

 

환경에 맞게 설정 파일을 수정합니다.

# vim docker-compose.yml

 

서비스 실행

# docker-compose up -d
Creating wg-easy ... done

 

확인

# docker-compose ps
 Name                Command               State                                              Ports                                           
----------------------------------------------------------------------------------------------------------------------------------------------
wg-easy   docker-entrypoint.sh node  ...   Up      0.0.0.0:51820->51820/udp,:::51820->51820/udp, 0.0.0.0:51821->51821/tcp,:::51821->51821/tcp,
                                                   80/tcp

 

UI 접속

WireGarud 서버의 IP와 위에서 설정한 Port를 이용하여 관리 콘솔에 접속합니다.
http://<Host-IP>:51821/

 

Create Connection

 

Configure Client


Linux

Download Wireguard

https://www.wireguard.com/install/

$ sudo apt install wireguard resolvconf

Download .conf file and Move to /etc/wireguard/ dir

$ sudo mv yjwang-t14s.conf /etc/wireguard/

 

(Using Command) Up WireGuard Interface

$ sudo wg-quick up yjwang-t14s
[#] ip link add yjwang-t14s type wireguard
[#] wg setconf yjwang-t14s /dev/fd/63
[#] ip -4 address add 10.199.62.2/24 dev yjwang-t14s
[#] ip link set mtu 1420 up dev yjwang-t14s
[#] resolvconf -a tun.yjwang-t14s -m 0 -x
[#] wg set yjwang-t14s fwmark 51820
[#] ip -6 route add ::/0 dev yjwang-t14s table 51820
[#] ip -6 rule add not fwmark 51820 table 51820
[#] ip -6 rule add table main suppress_prefixlength 0
[#] ip6tables-restore -n
[#] ip -4 route add 0.0.0.0/0 dev yjwang-t14s table 51820
[#] ip -4 rule add not fwmark 51820 table 51820
[#] ip -4 rule add table main suppress_prefixlength 0
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
[#] iptables-restore -n

 

(Using NetworkManager) Up WireGuard Interface

https://github.com/max-moser/network-manager-wireguard
https://mox.sh/sysadmin/wireguard-networkmanager-gnome/

$ sudo apt install wireguard git build-essential libgtk-3-dev libnma-dev libsecret-1-devmanager-dev resolvconf

$ git clone https://github.com/max-moser/network-manager-wireguard.git
$ cd network-manager-wireguard/

$ ./autogen.sh --without-libnm-glib
$./configure --prefix=/usr \
              --without-libnm-glib \
              --sysconfdir=/etc \
              --libdir=/usr/lib/x86_64-linux-gnu \
              --libexecdir=/usr/lib/NetworkManager \
              --localstatedir=/var

$ make
$ sudo make install

Config 시작

$ sudo nmcli connection import type wireguard file "/etc/wireguard/yjwang-t14s.conf"

Confirm

$ sudo wg
interface: yjwang-t14s
  public key: dQ0JxaOevQuWbByNTqfErK8rlXhBZkwNBTHRpDGBSAk=
  private key: (hidden)
  listening port: 57561
  fwmark: 0xcc14

peer: ujRW9o9z0B+mj6eRniaMuMJdUdVB/WMzHafFNxEpDzc=
  preshared key: (hidden)
  endpoint: 192.168.0.123:51820
  allowed ips: 0.0.0.0/0, ::/0
  latest handshake: 21 seconds ago
  transfer: 78.07 KiB received, 157.02 KiB sent

 

이후 UI에 접속하면 아래와 같이 연결됨을 볼 수 있다.

 

mount한 폴더만 그대로 가져가서 docker-compose up 하면 백업 복원도 가능하다.

반응형