diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-29 00:47:55 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-29 00:55:14 +0900 |
| commit | d30dfc89bf1b673b2fdc0638766b930adaec228c (patch) | |
| tree | 739d8826451947adfeb526ef1adeb1db397a9af4 /vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html | |
| parent | f65ec15aaf8fc46685c39d721cab82f64baead8c (diff) | |
| download | nsfisis.dev-d30dfc89bf1b673b2fdc0638766b930adaec228c.tar.gz nsfisis.dev-d30dfc89bf1b673b2fdc0638766b930adaec228c.tar.zst nsfisis.dev-d30dfc89bf1b673b2fdc0638766b930adaec228c.zip | |
feat(blog/nuldoc): migrate syntax highlighter from highlight.js to shiki.js
Diffstat (limited to 'vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html')
| -rw-r--r-- | vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html | 115 |
1 files changed, 67 insertions, 48 deletions
diff --git a/vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html b/vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html index 9b8c1815..f7a6f601 100644 --- a/vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html +++ b/vhosts/blog/public/posts/2024-02-03/install-wireguard-on-personal-server/index.html @@ -14,8 +14,7 @@ <meta property="og:locale" content="ja_JP"> <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【備忘録】 個人用サーバに WireGuard を導入する|REPL: Rest-Eat-Program Loop</title> - <link rel="stylesheet" href="/style.css?h=79020a898c7052f79b32e90376a4497d"> - <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> + <link rel="stylesheet" href="/style.css?h=60eb349e583f5bd51518a7eb98598043"> </head> <body class="single"> <header class="header"> @@ -99,14 +98,18 @@ まずは個人用サービスをホストしている Ubuntu のサーバに WireGuard をインストールする。 </p> - <pre class="highlight"><code>$ sudo apt install wireguard</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo apt install wireguard</span></span></code></pre> + </div> <p> 次に、WireGuard で使用する鍵を生成する。 </p> - <pre class="highlight"><code>$ wg genkey | sudo tee /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub -$ sudo chmod 600 /etc/wireguard/server.{key,pub}</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ wg genkey | sudo tee /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub</span></span> +<span class="line"><span>$ sudo chmod 600 /etc/wireguard/server.{key,pub}</span></span></code></pre> + </div> </section> <section id="section--install-wireguard-client"> @@ -115,25 +118,29 @@ $ sudo chmod 600 /etc/wireguard/server.{key,pub}</code></pre> 公式サイトから各 OS 向けのクライアントソフトウェアを入手し、インストールする。次に、設定をおこなう。 </p> - <pre class="highlight" language="ini"><code class="highlight"><span class="hljs-comment"># クライアント 1 の場合</span> -<span class="hljs-section">[Interface]</span> -<span class="hljs-attr">Address</span> = <span class="hljs-number">10.10</span>.<span class="hljs-number">1.2</span>/<span class="hljs-number">32</span> -<span class="hljs-attr">PrivateKey</span> = <クライアント <span class="hljs-number">1</span> の秘密鍵> - -<span class="hljs-section">[Peer]</span> -<span class="hljs-attr">PublicKey</span> = <サーバの公開鍵> -<span class="hljs-attr">AllowedIPs</span> = <サーバの外部 IP アドレス>/<span class="hljs-number">32</span> -<span class="hljs-attr">Endpoint</span> = <サーバの外部 IP アドレス>:<span class="hljs-number">51820</span></code></pre> - - <pre class="highlight" language="ini"><code class="highlight"><span class="hljs-comment"># クライアント 2 の場合</span> -<span class="hljs-section">[Interface]</span> -<span class="hljs-attr">Address</span> = <span class="hljs-number">10.10</span>.<span class="hljs-number">1.3</span>/<span class="hljs-number">32</span> -<span class="hljs-attr">PrivateKey</span> = <クライアント <span class="hljs-number">2</span> の秘密鍵> - -<span class="hljs-section">[Peer]</span> -<span class="hljs-attr">PublicKey</span> = <サーバの公開鍵> -<span class="hljs-attr">AllowedIPs</span> = <サーバの外部 IP アドレス>/<span class="hljs-number">32</span> -<span class="hljs-attr">Endpoint</span> = <サーバの外部 IP アドレス>:<span class="hljs-number">51820</span></code></pre> + <div class="codeblock" language="ini"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#6A737D"># クライアント 1 の場合</span></span> +<span class="line"><span style="color:#6F42C1">[Interface]</span></span> +<span class="line"><span style="color:#D73A49">Address</span><span style="color:#24292E"> = 10.10.1.2/32</span></span> +<span class="line"><span style="color:#D73A49">PrivateKey</span><span style="color:#24292E"> = <クライアント 1 の秘密鍵></span></span> +<span class="line"></span> +<span class="line"><span style="color:#6F42C1">[Peer]</span></span> +<span class="line"><span style="color:#D73A49">PublicKey</span><span style="color:#24292E"> = <サーバの公開鍵></span></span> +<span class="line"><span style="color:#D73A49">AllowedIPs</span><span style="color:#24292E"> = <サーバの外部 IP アドレス>/32</span></span> +<span class="line"><span style="color:#D73A49">Endpoint</span><span style="color:#24292E"> = <サーバの外部 IP アドレス>:51820</span></span></code></pre> + </div> + + <div class="codeblock" language="ini"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#6A737D"># クライアント 2 の場合</span></span> +<span class="line"><span style="color:#6F42C1">[Interface]</span></span> +<span class="line"><span style="color:#D73A49">Address</span><span style="color:#24292E"> = 10.10.1.3/32</span></span> +<span class="line"><span style="color:#D73A49">PrivateKey</span><span style="color:#24292E"> = <クライアント 2 の秘密鍵></span></span> +<span class="line"></span> +<span class="line"><span style="color:#6F42C1">[Peer]</span></span> +<span class="line"><span style="color:#D73A49">PublicKey</span><span style="color:#24292E"> = <サーバの公開鍵></span></span> +<span class="line"><span style="color:#D73A49">AllowedIPs</span><span style="color:#24292E"> = <サーバの外部 IP アドレス>/32</span></span> +<span class="line"><span style="color:#D73A49">Endpoint</span><span style="color:#24292E"> = <サーバの外部 IP アドレス>:51820</span></span></code></pre> + </div> <p> <code>PrivateKey</code> や <code>PublicKey</code> は鍵ファイルのパスではなく中身を書くことに注意。 @@ -146,28 +153,34 @@ $ sudo chmod 600 /etc/wireguard/server.{key,pub}</code></pre> 一度サーバへ戻り、WireGuard の設定ファイルを書く。 </p> - <pre class="highlight"><code>$ sudo vim /etc/wireguard/wg0.conf</code></pre> - - <pre class="highlight" language="ini"><code class="highlight"><span class="hljs-section">[Interface]</span> -<span class="hljs-attr">Address</span> = <span class="hljs-number">10.10</span>.<span class="hljs-number">1.1</span>/<span class="hljs-number">32</span> -<span class="hljs-attr">SaveConfig</span> = <span class="hljs-literal">true</span> -<span class="hljs-attr">PrivateKey</span> = <サーバの秘密鍵> -<span class="hljs-attr">ListenPort</span> = <span class="hljs-number">51820</span> - -<span class="hljs-section">[Peer]</span> -<span class="hljs-attr">PublicKey</span> = <クライアント <span class="hljs-number">1</span> の公開鍵> -<span class="hljs-attr">AllowedIPs</span> = <span class="hljs-number">10.10</span>.<span class="hljs-number">1.2</span>/<span class="hljs-number">32</span> - -<span class="hljs-section">[Peer]</span> -<span class="hljs-attr">PublicKey</span> = <クライアント <span class="hljs-number">2</span> の公開鍵> -<span class="hljs-attr">AllowedIPs</span> = <span class="hljs-number">10.10</span>.<span class="hljs-number">1.3</span>/<span class="hljs-number">32</span></code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo vim /etc/wireguard/wg0.conf</span></span></code></pre> + </div> + + <div class="codeblock" language="ini"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#6F42C1">[Interface]</span></span> +<span class="line"><span style="color:#D73A49">Address</span><span style="color:#24292E"> = 10.10.1.1/32</span></span> +<span class="line"><span style="color:#D73A49">SaveConfig</span><span style="color:#24292E"> = true</span></span> +<span class="line"><span style="color:#D73A49">PrivateKey</span><span style="color:#24292E"> = <サーバの秘密鍵></span></span> +<span class="line"><span style="color:#D73A49">ListenPort</span><span style="color:#24292E"> = 51820</span></span> +<span class="line"></span> +<span class="line"><span style="color:#6F42C1">[Peer]</span></span> +<span class="line"><span style="color:#D73A49">PublicKey</span><span style="color:#24292E"> = <クライアント 1 の公開鍵></span></span> +<span class="line"><span style="color:#D73A49">AllowedIPs</span><span style="color:#24292E"> = 10.10.1.2/32</span></span> +<span class="line"></span> +<span class="line"><span style="color:#6F42C1">[Peer]</span></span> +<span class="line"><span style="color:#D73A49">PublicKey</span><span style="color:#24292E"> = <クライアント 2 の公開鍵></span></span> +<span class="line"><span style="color:#D73A49">AllowedIPs</span><span style="color:#24292E"> = 10.10.1.3/32</span></span></code></pre> + </div> <p> 次に、WireGuard のサービスを起動する。 </p> - <pre class="highlight"><code>$ sudo systemctl enable wg-quick@wg0 -$ sudo systemctl start wg-quick@wg0</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo systemctl enable wg-quick@wg0</span></span> +<span class="line"><span>$ sudo systemctl start wg-quick@wg0</span></span></code></pre> + </div> </section> <section id="section--configure-firewall"> @@ -176,23 +189,29 @@ $ sudo systemctl start wg-quick@wg0</code></pre> 続けてファイアウォールを設定する。まずは WireGuard が使用する UDP のポートを開き、<code>wg0</code> を通る通信を許可する。 </p> - <pre class="highlight"><code>$ sudo ufw allow 51820/udp -$ sudo ufw allow in on wg0 -$ sudo ufw allow out on wg0</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo ufw allow 51820/udp</span></span> +<span class="line"><span>$ sudo ufw allow in on wg0</span></span> +<span class="line"><span>$ sudo ufw allow out on wg0</span></span></code></pre> + </div> <p> 次に、80 や 443 などの必要なポートについて、<code>wg0</code> を経由してのアクセスのみ許可する。 </p> - <pre class="highlight"><code>$ sudo ufw allow in on wg0 to any port 80 proto tcp -$ sudo ufw allow in on wg0 to any port 443 proto tcp</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo ufw allow in on wg0 to any port 80 proto tcp</span></span> +<span class="line"><span>$ sudo ufw allow in on wg0 to any port 443 proto tcp</span></span></code></pre> + </div> <p> 最後に、<code>ufw</code> を有効にする。 </p> - <pre class="highlight"><code>$ sudo ufw status -$ sudo ufw enable</code></pre> + <div class="codeblock"> + <pre class="shiki github-light" style="background-color:#f5f5f5;color:#24292e" tabindex="0"><code><span class="line"><span>$ sudo ufw status</span></span> +<span class="line"><span>$ sudo ufw enable</span></span></code></pre> + </div> </section> <section id="section--connect-each-other"> |
