2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WireGuardでVPN接続

Last updated at Posted at 2022-05-31

事前準備

サーバとクライアント両方で以下のコマンドを実行する。

root# apt install -y wireguard

設定方法

以下にWireGuardのサーバとクライアント設定方法を示す。

Serverの設定

1. サーバ用秘密鍵の作成

root# wg genkey| tee /etc/wireguard/server.key
0I62zaLHBLbTNn1PFkarLyzkL11cuCPBuTvTU7/sVWM=

2. サーバ用公開鍵の作成

root# cat /etc/wireguard/server.key |wg pubkey | tee /etc/wireguard/server.pub
6IPfYoRdPAg1iKSYF3bAiqbuVofWayIPCMHhcJdw7WI=

3. クライアント用秘密鍵の作成

root# wg genkey | tee /etc/wireguard/client.key
qPaLzgFaCsj9o2nR9WZOxOv1NUA/WbuIN3doSDI69nc=

4. クライアント用公開鍵の作成

root# cat /etc/wireguard/client.key |wg pubkey |tee /etc/wireguard/client.pub
1W5we9rb1WnnaRYCKKOBOA/rWWo/71r5I4J9eDTUTzY=

5. コンフィグの作成

root# cat <<EOF > /etc/wireguard/wg0.conf
[Interface]
# 1.で生成したサーバー用秘密鍵を指定
PrivateKey = 0I62zaLHBLbTNn1PFkarLyzkL11cuCPBuTvTU7/sVWM=
# 使用するIPアドレス
Address = 10.0.0.1
# サーバで使用するポート
ListenPort = 51820

[Peer]
# 4.で生成したクライアント用公開鍵を指定
PublicKey = 1W5we9rb1WnnaRYCKKOBOA/rWWo/71r5I4J9eDTUTzY=
# 接続を許可するIPアドレス
AllowedIPs = 10.0.0.2
EOF

6. WireGuardの起動

root# systemctl enable wg-quick@wg0
root# systemctl start wg-quick@wg0

Clientの設定

root# cat << EOF >/etc/wireguard/wg0.conf
[Interface]
# 3.で生成したクライアント用秘密鍵の指定
PrivateKey = qPaLzgFaCsj9o2nR9WZOxOv1NUA/WbuIN3doSDI69nc=
# 使用するIPアドレス
Address = 10.0.0.2

[Peer]
# 2.で生成したサーバ用公開鍵の指定
PublicKey = 6IPfYoRdPAg1iKSYF3bAiqbuVofWayIPCMHhcJdw7WI=
# 接続するサーバのIPアドレスとポート指定
EndPoint = 192.168.1.1:51820
# VPNを通して接続するIPアドレスやネットワークの指定
AllowedIPs = 10.0.0.0/24
EOF

root# wg-quick up wg0

接続確認

クライアントからサーバにWireGuard越しで接続できるか確認

root# ping -c 4 10.0.0.1
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.247 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.415 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.400 ms
64 bytes from 10.0.0.1: icmp_seq=4 ttl=64 time=0.434 ms

--- 10.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3080ms
rtt min/avg/max/mdev = 0.247/0.374/0.434/0.074 ms

最後に

WireGuardサーバーのGUIではクライアントのconfigを自動生成したりQRコードからconfigのダウンロードが行えたできる。WireGuardはスマホやPCでも簡単にクライアントにすることができて、特定のネットワークのみVPN接続も簡単にできるのでSoftEtherより使い勝手がよさそう。

参考サイト

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?