LoginSignup
0
0

More than 1 year has passed since last update.

【Linuxサーバ不要】自宅のWindows PCとWireguardで直接VPN張る方法

Posted at

Wireguradを使って、自宅PCへリモートディスクトップで接続する環境を構築しました。

こだわった点

自宅にLinuxサーバ(Raspiなど)を置きたくない。
自宅PCにWireguardをインストールして直接接続したい。

ネット上のWireguard のサーバ側の説明はLinuxの場合が多いのですが、Windows Clientでも同じなんじゃない?
とおもって設定してみたところ、うまくいきました。

接続図

自宅PC(Windows) --- Router --- Internet --- スマホ --- NotePC(Windows)

設定方法

  • WireguardはWindows版を、自宅PC,NotePCそれぞれにインストール。Windows版のWireguardの使い方は省略。
  • 自宅PCはIPアドレスが変動しないようにする(固定IPにするなど)
  • Routerにはポートマッピング設定をして外部からのUDP 51820ポートを自宅PCのIPに転送する
  • DDNSを設定して、自宅のグロバルIPのFQDNを確保する
  • Note PC側には、PersistentKeepalive = 30の設定を入れる。

NotePCで、10.0.0.1にリモートディスクトップ接続できました。

鍵の生成は、次のコマンドで実行しました。Linux版と同様にできます。保存先のフォルダーは適当に変えてください。

PS C:\Program Files\WireGuard> .\wg.exe genkey > c:\tmp\wgclient.key
PS C:\Program Files\WireGuard> cat C:\tmp\wgclient.key| .\wg.exe pubkey > C:\tmp\wgclient.pub
PS C:\Program Files\WireGuard> .\wg.exe genkey > c:\tmp\wgserver.key
PS C:\Program Files\WireGuard> cat C:\tmp\wgserver.key| .\wg.exe pubkey > C:\tmp\wgserver.pub
wgserver.conf
[Interface]

PrivateKey = [wgserver.keyの内容]
ListenPort = 51820
Address = 10.0.0.1/32

[Peer]
PublicKey = [wgclient.pubの内容]
AllowedIPs = 10.0.0.2/32
wgclient.conf
[Interface]
PrivateKey = [wgclient.keyの内容]
Address = 10.0.0.2/32
[Peer]
PublicKey = [wgserver.pubの内容]
AllowedIPs = 10.0.0.1/32
Endpoint = xxxxxxx.ddns.net:51820
PersistentKeepalive = 30

注意点

ping 10.0.0.1の応答はありませんでした。多分、WindowsのFirewallによるブロックではないかと思いますが、追及していません。
ping応答がなくてしばらく悩みました。

0
0
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
0
0