「OpenVPN ブリッジ」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(英語版より転載)
 
 
(同じ利用者による、間の12版が非表示)
1行目: 1行目:
 
[[Category:Virtual Private Network]]
 
[[Category:Virtual Private Network]]
[[ja:OpenVPN Bridge]]
+
[[en:OpenVPN Bridge]]
  +
このページでは Arch Linux でネットワークブリッジを作成し、IP layer-3 ベースの IP トンネル (TUN) ではなく、IP layer-2 ベースの Ethernet ブリッジ (TAP) を使って OpenVPN サーバをホストする方法を説明します。一般的な [[OpenVPN]] ページでは、PAM 認証や OpenSSL セキュリティ証明書の設定についてより詳しく説明しています。
This page describes how to create a network bridge on Arch Linux and host an OpenVPN server using a IP layer-2 based Ethernet bridge (TAP) rather than a IP layer-3 based IP tunnel (TUN). The general [[OpenVPN]] page describes setting up PAM authentication or OpenSSL security certificates in more detail.
 
   
  +
== イントロダクション ==
== Introduction ==
 
   
  +
[http://openvpn.net/index.php/open-source/documentation.html OpenVPN のドキュメント]ページでは、OpenVPN がサポートするサーバーサイドとクライアントサイドのオプションの完全な概要が提供されています。トンネリングモードで OpenVPN を設定し、トラフィックのルーティングを制御する方が簡単であり、目的に合っている場合は一般的にそのようにすることが推奨されます。ただし、Windows のファイル共有などのネットワークアプリケーションは、イーサネットレベルでのネットワークブロードキャストに依存し、同じサブネット上に物理的に配置されていると考えることで利益を得るため、ソフトウェアブリッジングがこの目的に役立ちます。
The [http://openvpn.net/index.php/open-source/documentation.html OpenVPN documentation] page gives a full overview of server-side and client-side options that OpenVPN supports. It is easier to set up OpenVPN in tunneling mode and control routing the traffic and it is generally advised to do so if it serves your purpose. However, some network applications, such as Windows file sharing, rely on network broadcasts at the Ethernet level and benefit from believing they are physically located on the same subnet, and software bridging serves this purpose.
 
   
  +
ブリッジングを設定する方法は複数あります。動的な方法では、OpenVPN がシステム上で独自のブリッジを管理し、それを開始、停止、および設定します。これはブリッジングを設定する最も迅速な方法ですが、OpenVPN の起動および停止時に他のネットワークサービスが中断されます。システムが独自のブリッジを管理する場合、OpenVPN の他にも他の仮想ネットワークアダプタがブリッジに接続するため、静的な方法を使用する方が好ましいです。
There are multiple ways to set bridging up. The dynamic method is where OpenVPN will be managing its own bridge on the system and will start, stop and configure it itself. This is the quickest way to set bridging up, although it interrupts other network services when OpenVPN starts and stops. If the system is going to manage its own bridge, maybe because other virtual network adapters connect to the bridge besides just that of OpenVPN, then it is preferable to use the static method.
 
   
  +
== 動的ブリッジのインストール ==
== Dynamic Bridge Installation ==
 
   
You will need to [[install]] OpenVPN and Linux bridging utilities which are available in the {{Pkg|openvpn}} and {{Pkg|bridge-utils}} packages.
+
OpenVPN Linux ブリッジングユーティリティをインストールする必要があります。これらは {{Pkg|openvpn}} および {{Pkg|bridge-utils}} パッケージで利用できます。
   
  +
== 動的ブリッジ設定 ==
== Dynamic Bridge Configuration ==
 
   
  +
OpenVPN は、設定ファイルで指定された名前の TAP デバイスを自動的に作成/削除します。以下の例の設定ファイルには、TUN または TAP に共通する OpenVPN の設定は示されておらず、TAP モードに影響する設定のみが示されています。スクリプトを作成した後、{{ic|up}} および {{ic|down}} スクリプトが実行可能であることを {{ic|chmod +x}} で確認してください。
OpenVPN will create/destroy the TAP device automatically for the name specified in the config file. OpenVPN settings common to TUN or TAP are not shown in the example config file below, only settings that affect TAP mode. Make sure the {{ic|up}} and {{ic|down}} scripts are executable with {{ic|chmod +x}} after you write them.
 
   
  +
(TUN と TAP に共通するセクションは省略)
(sections common to TUN and TAP omitted)
 
   
 
{{hc|/etc/openvpn/server.conf|
 
{{hc|/etc/openvpn/server.conf|
103行目: 103行目:
 
These examples are for using dhcp. If you are going to use static IP addresses, you will need to adjust accordingly.
 
These examples are for using dhcp. If you are going to use static IP addresses, you will need to adjust accordingly.
   
== Using Systemd ==
+
== Systemd の使用 ==
   
  +
OpenVPN の systemd スクリプトは、デフォルトで /etc/openvpn フォルダ内の <name>.conf ファイルを探します。したがって、server.conf という名前のファイルがあると仮定すると、{{ic|openvpn@server}} を有効化して起動することができます。
The OpenVPN systemd script looks for <name>.conf files in the /etc/openvpn folder by default. So assuming you have a file named server.conf, you can [[enable]] and start {{ic|openvpn@server}}.
 
   
  +
同時に dhcpcd が別々に有効化されていることに注意してください(つまり、dhcpcd@eth0.service)。OpenVPN の後に完了して OpenVPN 用の DHCP 設定を台無しにする可能性がありますが、それはあまりありそうもありません。どのみち openvpn@server.service が DHCP をリセットすることがわかっているので、dhcpcd@eth0.service を無効にすることができるでしょう。
Be careful about having dhcpcd enabled separately (ie. dhcpcd@eth0.service) at the same time. It is possible, though unlikely, for it to complete after OpenVPN and ruin your dhcp setup for OpenVPN. You could probably disable dhcpcd@eth0.service since you know openvpn@server.service will be resetting dhcp anyway.
 
   
  +
{{Warning| 静的ブリッジのセクションでは、systemd を使用した方法がまったく説明されていません。さらに、古い情報が含まれている可能性があります。いずれ見直す必要があります。}}
{{Warning| The Static Bridge section does not describe a method using systemd at all. In addition, it may contain outdated information. It should be revised at some point.}}
 
   
  +
== 静的ブリッジのインストール ==
== Static Bridge Installation ==
 
   
The first thing you want to do is [[install]] these packages: {{Pkg|openvpn}}, {{Pkg|bridge-utils}}, {{Pkg|netctl}}.
+
まず最初に、{{Pkg|openvpn}}{{Pkg|bridge-utils}}{{Pkg|netctl}} のパッケージを[[インストール]]してください。
   
  +
== 静的ブリッジの設定 ==
== Static Bridge Configuration ==
 
   
  +
OpenVPN チームやさまざまな Linux パッケージャが提供する OpenVPN の早期バージョンのガイドでは、OpenVPN を起動する際にブリッジを構築し、OpenVPN をシャットダウンする際にブリッジを破壊するためのスクリプトの例が示されていました。
Earlier versions of guides for OpenVPN provided by the OpenVPN team or various Linux packagers give example scripts for constructing a bridge when starting OpenVPN and destroying it when shutting OpenVPN down.
 
   
  +
ただし、これはやや時代遅れのアプローチであり、OpenVPN 2.1.1 以降では、セキュリティ上の理由から明示的に有効化されない限り、外部スクリプトやプログラムを呼び出すことができません。
However, this is a somewhat deprecated approach, since OpenVPN as of 2.1.1 defaults to not allowing itself to call external scripts or programs unless explicitly enabled to, for security reasons.
 
   
  +
また、ブリッジの構築は、ネットワークの初期化プロセスの他のすべての部分に比べて比較的遅いです(実際、ブリッジが準備できる前に dhcpcd がタイムアウトするほど遅いです。[[#Static Bridge Troubleshooting]] を参照してください)。さらに、設定変更後に OpenVPN を再起動する際に、動作しているブリッジを再構築する理由はありませんし、他のすべてのネットワークアプリケーションを中断します。したがって、以下のように静的ブリッジ設定を行うことが推奨されています。
Also, constructing the bridge is relatively slow compared to all other parts of the network initialization process. (In fact, so slow that dhcpcd will time out before the bridge is ready. See [[#Static Bridge Troubleshooting]].) Also, when restarting OpenVPN after configuration changes, there is no reason to rebuild a working bridge, interrupting all your other network applications. So, setting up a static bridge configuration as follows is the recommended method.
 
   
  +
サーバー用の OpenVPN ブリッジを作成するには、[[netctl]] を使用して 2 つのネットワークプロファイル(tap インターフェース用とブリッジ用)を作成する必要があります。
To create an OpenVPN bridge for your server, you are going to have to use [[netctl]] and create two network profiles - one for the tap interface and one for the bridge.
 
   
Go to {{ic|/etc/netctl}} and copy the tuntap example file to the directory:
+
{{ic|/etc/netctl}} に移動し、tuntap のサンプルファイルをディレクトリにコピーします:
   
 
# cd /etc/netctl/
 
# cd /etc/netctl/
 
# cp examples/tuntap openvpn_tap
 
# cp examples/tuntap openvpn_tap
   
  +
次に、{{ic|openvpn_tap}} を編集して tap インターフェイスを作成します。以下のようになるかもしれません:
Now edit {{ic|openvpn_tap}} to create a tap interface. It may look like this:
 
   
 
{{hc|/etc/netctl/openvpn_tap|2=
 
{{hc|/etc/netctl/openvpn_tap|2=
141行目: 141行目:
 
}}
 
}}
   
  +
ここでは IP アドレスを設定しないでください。これはブリッジインターフェイスで行われる予定です!
Do not configure the IP address here, this is going to be done for the bridge interface!
 
   
  +
{{ic|bridge}} プロファイルを作成するには、サンプルファイルをコピーします:
To create the {{ic|bridge}} profile, copy the example file:
 
   
 
# cp examples/bridge openvpn_bridge
 
# cp examples/bridge openvpn_bridge
   
  +
次に、{{ic|openvpn_bridge}} を編集します。以下のようになるかもしれません:
Now edit {{ic|openvpn_bridge}}. It may look like this:
 
   
 
{{hc|/etc/netctl/openvpn_bridge|2=
 
{{hc|/etc/netctl/openvpn_bridge|2=
160行目: 160行目:
 
}}
 
}}
   
  +
詳細情報や、例えば DHCP の使用方法については、[[netctl]] の記事を参照してください。
For more information, for example how to use DHCP instead, check the [[netctl]] article.
 
   
  +
次に、両方のプロファイルを有効化して開始します:
Now enable and start both profiles with:
 
   
 
# netctl enable openvpn_tap
 
# netctl enable openvpn_tap
169行目: 169行目:
 
# netctl start openvpn_bridge
 
# netctl start openvpn_bridge
   
  +
== スタティックブリッジのトラブルシューティング ==
== Static Bridge Troubleshooting ==
 
   
  +
=== ネットワークの開始に失敗しました ===
=== Failed to start the network ===
 
   
  +
これは、ブリッジで DHCP を使用しており、ブリッジの設定に dhcpcd が待機するよりも時間がかかるためです。ブリッジネットワークプロファイル(openvpn_bridge)で FWD_DELAY パラメータを設定することで、これを修正できます。まず 5 の値から始めて、動作するまで減らしていきます。
This is probably because you are using DHCP on the bridge and setting up the bridge takes longer than dhcpcd is willing to wait. You can fix this by setting the FWD_DELAY parameter in your bridge network profile (openvpn_bridge). Start with a value of 5 and decrease it until it works.
 
   
  +
=== DHCP を使用している場合にブリッジに IP アドレスがない ===
== More Resources ==
 
   
  +
イーサネットインターフェースに割り当てられている IP アドレスを解放してから、DHCP 経由で IP をリクエストする必要があるかもしれません。これを行うには:
* [[OpenVPN]] - General page on configuring OpenVPN, including setting up authentication methods.
 
  +
  +
{{bc|
  +
dhcpcd -k
  +
}}
  +
  +
次に、dhcpcd の設定ファイルを変更して、イーサネットインターフェースに IP アドレスが割り当てられないようにします(この場合、{{ic|enp3s0}}):
  +
  +
{{hc|/etc/dhcpcd.conf|
  +
denyinterfaces enp3s0
  +
}}
  +
  +
ファイルの最後の方で(ブリッジの名前が {{ic|br0}} であることを前提に):
  +
  +
{{hc|/etc/dhcpcd.conf|
  +
interface br0}}
  +
  +
上記で説明したように、ネットワークブリッジを作成し、{{ic|dhcpcd}} を実行してインターフェースに IP アドレスを割り当てます。{{ic|ip addr}} がブリッジ(つまり {{ic|br0}})に有効な IP アドレスを割り当てていることを確認します。
  +
  +
== その他のリソース ==
  +
  +
* [[OpenVPN]] - OpenVPN の設定に関する一般的なページで、認証方法の設定を含みます。

2023年3月20日 (月) 16:40時点における最新版

このページでは Arch Linux でネットワークブリッジを作成し、IP layer-3 ベースの IP トンネル (TUN) ではなく、IP layer-2 ベースの Ethernet ブリッジ (TAP) を使って OpenVPN サーバをホストする方法を説明します。一般的な OpenVPN ページでは、PAM 認証や OpenSSL セキュリティ証明書の設定についてより詳しく説明しています。

イントロダクション

OpenVPN のドキュメントページでは、OpenVPN がサポートするサーバーサイドとクライアントサイドのオプションの完全な概要が提供されています。トンネリングモードで OpenVPN を設定し、トラフィックのルーティングを制御する方が簡単であり、目的に合っている場合は一般的にそのようにすることが推奨されます。ただし、Windows のファイル共有などのネットワークアプリケーションは、イーサネットレベルでのネットワークブロードキャストに依存し、同じサブネット上に物理的に配置されていると考えることで利益を得るため、ソフトウェアブリッジングがこの目的に役立ちます。

ブリッジングを設定する方法は複数あります。動的な方法では、OpenVPN がシステム上で独自のブリッジを管理し、それを開始、停止、および設定します。これはブリッジングを設定する最も迅速な方法ですが、OpenVPN の起動および停止時に他のネットワークサービスが中断されます。システムが独自のブリッジを管理する場合、OpenVPN の他にも他の仮想ネットワークアダプタがブリッジに接続するため、静的な方法を使用する方が好ましいです。

動的ブリッジのインストール

OpenVPN と Linux ブリッジングユーティリティをインストールする必要があります。これらは openvpn および bridge-utils パッケージで利用できます。

動的ブリッジ設定

OpenVPN は、設定ファイルで指定された名前の TAP デバイスを自動的に作成/削除します。以下の例の設定ファイルには、TUN または TAP に共通する OpenVPN の設定は示されておらず、TAP モードに影響する設定のみが示されています。スクリプトを作成した後、up および down スクリプトが実行可能であることを chmod +x で確認してください。

(TUN と TAP に共通するセクションは省略)

/etc/openvpn/server.conf
# this uses a dhcp server, server-side
#  clients must support binding their dhcp client to their tap adapter
# do not append 'nogw' if using dhcp
server-bridge
# can specify interface, like tap0 or tap1
#  or use up/down routing scripts to handle
#  more than one, if needed
dev tap0
# needed to call scripts like up/down
#  which call external programs within the scripts
script-security 2
# user defined scripts for adding/removing tap to bridge
#  'dev mtu link_mtu ifconfig_local_ip ifconfig_remote_ip' are appended if set
# make sure 'user' has permission to run 'down' ('up' will be root)
up "up br0 eth0"
down "down br0 eth0"
# call 'down' before TUN/TAP close
down-pre
# drop root priveledges once connected
#  good idea, for servers running on linux
# 'up' script not affected, 'down' script is
;user nobody
;group nobody
/etc/openvpn/up
#!/bin/bash
br=$1
eth=$2
dev=$3
mtu=$4
cd /usr/bin/

# only if you start dhcpcd and leave it
#  running for eth
#dhcpcd -k $eth

# needed if script is run independently
# but when run through openvpn
# openvpn will do this automatically
#  could also use 'ip tuntap ..'
#openvpn --mktun --dev $dev

brctl addbr $br
# set forwarding delay to 0
#  otherwise dhcp called below would timeout
brctl setfd $br 0
brctl addif $br $eth
# order matters here.. right now there is only
#  one mac in the bridge's table
# if there were two.. there is no guarantee
#  which would be passed to the dhcp server
dhcpcd $br
brctl addif $br $dev

ip link set $eth up promisc on mtu $mtu
ip link set $dev up promisc on mtu $mtu
/etc/openvpn/down
#!/bin/bash
br=$1
eth=$2
cd /usr/bin/

dhcpcd -k $br

ip link set $br down
brctl delbr $br

# needed if script is run independently
# but when run through openvpn
# openvpn will do this automatically
#  could also use 'ip tuntap ..'
#openvpn --rmtun --dev $dev

# only if you start dhcpcd and leave it
#  running for eth
#dhcpcd $eth

These examples are for using dhcp. If you are going to use static IP addresses, you will need to adjust accordingly.

Systemd の使用

OpenVPN の systemd スクリプトは、デフォルトで /etc/openvpn フォルダ内の <name>.conf ファイルを探します。したがって、server.conf という名前のファイルがあると仮定すると、openvpn@server を有効化して起動することができます。

同時に dhcpcd が別々に有効化されていることに注意してください(つまり、dhcpcd@eth0.service)。OpenVPN の後に完了して OpenVPN 用の DHCP 設定を台無しにする可能性がありますが、それはあまりありそうもありません。どのみち openvpn@server.service が DHCP をリセットすることがわかっているので、dhcpcd@eth0.service を無効にすることができるでしょう。

警告: 静的ブリッジのセクションでは、systemd を使用した方法がまったく説明されていません。さらに、古い情報が含まれている可能性があります。いずれ見直す必要があります。

静的ブリッジのインストール

まず最初に、openvpnbridge-utilsnetctl のパッケージをインストールしてください。

静的ブリッジの設定

OpenVPN チームやさまざまな Linux パッケージャが提供する OpenVPN の早期バージョンのガイドでは、OpenVPN を起動する際にブリッジを構築し、OpenVPN をシャットダウンする際にブリッジを破壊するためのスクリプトの例が示されていました。

ただし、これはやや時代遅れのアプローチであり、OpenVPN 2.1.1 以降では、セキュリティ上の理由から明示的に有効化されない限り、外部スクリプトやプログラムを呼び出すことができません。

また、ブリッジの構築は、ネットワークの初期化プロセスの他のすべての部分に比べて比較的遅いです(実際、ブリッジが準備できる前に dhcpcd がタイムアウトするほど遅いです。#Static Bridge Troubleshooting を参照してください)。さらに、設定変更後に OpenVPN を再起動する際に、動作しているブリッジを再構築する理由はありませんし、他のすべてのネットワークアプリケーションを中断します。したがって、以下のように静的ブリッジ設定を行うことが推奨されています。

サーバー用の OpenVPN ブリッジを作成するには、netctl を使用して 2 つのネットワークプロファイル(tap インターフェース用とブリッジ用)を作成する必要があります。

/etc/netctl に移動し、tuntap のサンプルファイルをディレクトリにコピーします:

# cd /etc/netctl/
# cp examples/tuntap openvpn_tap

次に、openvpn_tap を編集して tap インターフェイスを作成します。以下のようになるかもしれません:

/etc/netctl/openvpn_tap
Description='tuntap connection'
Interface=tap0
Connection=tuntap
Mode='tap'
User='nobody'
Group='nobody'

ここでは IP アドレスを設定しないでください。これはブリッジインターフェイスで行われる予定です!

bridge プロファイルを作成するには、サンプルファイルをコピーします:

# cp examples/bridge openvpn_bridge

次に、openvpn_bridge を編集します。以下のようになるかもしれません:

/etc/netctl/openvpn_bridge
Description="Bridge connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(eth0 tap0)
IP=static
Address=('192.168.11.1/24')
Gateway='192.168.11.254'
DNS=('192.168.11.254')

詳細情報や、例えば DHCP の使用方法については、netctl の記事を参照してください。

次に、両方のプロファイルを有効化して開始します:

# netctl enable openvpn_tap
# netctl enable openvpn_bridge
# netctl start openvpn_tap
# netctl start openvpn_bridge

スタティックブリッジのトラブルシューティング

ネットワークの開始に失敗しました

これは、ブリッジで DHCP を使用しており、ブリッジの設定に dhcpcd が待機するよりも時間がかかるためです。ブリッジネットワークプロファイル(openvpn_bridge)で FWD_DELAY パラメータを設定することで、これを修正できます。まず 5 の値から始めて、動作するまで減らしていきます。

DHCP を使用している場合にブリッジに IP アドレスがない

イーサネットインターフェースに割り当てられている IP アドレスを解放してから、DHCP 経由で IP をリクエストする必要があるかもしれません。これを行うには:

dhcpcd -k

次に、dhcpcd の設定ファイルを変更して、イーサネットインターフェースに IP アドレスが割り当てられないようにします(この場合、enp3s0):

/etc/dhcpcd.conf
denyinterfaces enp3s0

ファイルの最後の方で(ブリッジの名前が br0 であることを前提に):

/etc/dhcpcd.conf
interface br0

上記で説明したように、ネットワークブリッジを作成し、dhcpcd を実行してインターフェースに IP アドレスを割り当てます。ip addr がブリッジ(つまり br0)に有効な IP アドレスを割り当てていることを確認します。

その他のリソース

  • OpenVPN - OpenVPN の設定に関する一般的なページで、認証方法の設定を含みます。