WiguardでKDEConnectを使用する方法

WiguardでKDEConnectを使用する方法

ブロードキャストを実装していないwireguardを介してKDEConnectをどのように使用できますか?

ベストアンサー1

3台のコンピュータがあるとしましょう。

  • Wireguardサーバーを実行するサーバー、Wireguard IPは10.100.0.1です。
  • Android用KDEConnectを実行している携帯電話の場合、ワイヤガードIPは10.100.0.2です。
  • kdeconnect、wireguard ip 10.100.0.3を実行するKDEプラズマを搭載したノートパソコン

まず、サーバーでWireguardを設定します。私は個人的にこれを行うためにnixosを使用することを選択しましたが、手動で設定することも、ファイルを使用して設定することもできます.conf。これは私のnix設定ファイルです。

# Source: https://nixos.wiki/wiki/Wireguard
#### Create keys, as root:
# mkdir ~/wireguard-keys
# umask 077 ~/wireguard-keys
# wg genkey > ~/wireguard-keys/private
# wg pubkey < ~/wireguard-keys/private > ~/wireguard-keys/public
{ config, pkgs, lib, ... }:
let
  port = 51820;
in
{
  environment.systemPackages = with pkgs; [ wireguard ];

  networking.wireguard.interfaces = {
    # "wg0" is the network interface name. You can name the interface arbitrarily.
    wg0 = {
      # Determines the IP address and subnet of the server's end of the tunnel interface.
      ips = [ "10.100.0.1/24" ];

      # The port that Wireguard listens to. Must be accessible by the client.
      listenPort = port;

      # Path to the private key file.
      #
      # Note: The private key can also be included inline via the privateKey option,
      # but this makes the private key world-readable; thus, using privateKeyFile is
      # recommended.
      privateKeyFile = "/root/wireguard-keys/private";

      peers = [
        # List of allowed peers.
        {
          # Android
          publicKey = "myandroidpublickey=";
          # List of IPs assigned to this peer within the tunnel subnet.
          # Used to configure routing.
          allowedIPs = [ "10.100.0.2/32" ];
        }
        {
          # Laptop
          publicKey = "mylaptoppublickey=";
          # List of IPs assigned to this peer within the tunnel subnet.
          # Used to configure routing.
          allowedIPs = [ "10.100.0.3/32" ];
        }
      ];
    };
  };

  # Ensure IP forwarding is enabled.
  boot.kernel.sysctl."net.ipv4.ip_forward" = 1;

  # Add a masquerade rule to iptables so the clients can
  # talk to the internet
  networking.firewall.extraCommands = ''
   iptables -t nat -A POSTROUTING -s 10.100.0.0/24 ! -d 10.100.0.0/24 -j MASQUERADE
  '';
  # Make sure port is open
  networking.firewall = {
    allowedTCPPorts = [ port ];
    allowedUDPPorts = [ port ];
  };


}

重要な部分はい、IP転送が有効になっていることを確認してコマンドを実行しますiptables -t nat -A POSTROUTING -s 10.100.0.0/24 ! -d 10.100.0.0/24 -j MASQUERADE。実際に偽装しないと携帯電話からインターネットにアクセスできなくなり、偽装する前に目的地がネットワーク外にあることを確認することを忘れてしまうと、KDEConnectに接続できません。あなたの電話で(私は多くの時間を費やしました。それから私はこれを実現しました)。

次に、ラップトップでWireguardを設定します。たとえば、次のように入力します/etc/wireguard/wg0.conf

# https://wiki.archlinux.fr/Wireguard
# To run, use:
# wg-quick up wg0
# ou systemctl enable --now [email protected]
# Sur le noeud 2, le "client"
[Interface]
# le /24 est important : on définit un réseau (/24) auquel l'interface appartient
Address = 10.100.0.3/24
PrivateKey = computerprivatekey

# On définit qui est le "serveur"
[Peer]
PublicKey = serverpublickey
# le /24 indique ici que tous les noeuds du VPN vont d'abord communiquer avec le serveur,
# qui va nous renvoyer ce qui nous concerne :
# on peut s'attendre à recevoir du trafic de la part d'hypothétiques nouveaux noeuds qui seraient dans 10.X.Y/24
AllowedIPs = 10.100.0.0/24
Endpoint = serverip.com:51820
# En général les clients sont derrière du NAT, et si on veut que le serveur puisse joindre le client à tout moment, il faut :
PersistentKeepalive = 15

Android携帯にWireguardアプリ(次の場所で利用可能)をインストールしてください。アプリストアそしてFDロイド)、新しいインターフェースを作成し、新しい秘密鍵を作成してから、インターフェースアドレスから選択します10.100.0.2/32。ピアでサーバーの公開鍵を追加し、許可されたIPを入力します0.0.0.0/0(実際にはより制限的なIPセットを選択できます)。ターミナルを設定し、設定をmyserver.com:51820保存/アクティブ化/ネットワークテストします。

最後に、携帯電話でKDEConnectを開き、「新しいデバイスの接続」に移動し、右上隅にある3つのドット「IPとしてデバイスを追加」をクリックしてノートブックのIPを追加します10.100.0.3。楽しむ!

注:携帯電話のIPを設定したくない場合は、KDEConnectを再コンパイルしてブロードキャストアドレスを携帯電話のIPに変更することもできますが、これは実用的ではありません。

おすすめ記事