iptables は pptp と openvpn 転送を使用します。

iptables は pptp と openvpn 転送を使用します。

VPSにOpenVPNとPPTPをインストールしました。明確な答えが得られないいくつかの質問があります。

1.1.1.1(eth0、パブリックIPアドレス)にOpenVPNをインストールし、1.1.1.2(eth0:1、パブリックIPアドレス)にPPTPをインストールしたいと思います。私はSNATを介してこれを達成しました。しかし、私が読んだすべてのチュートリアルでは、ppp +をeth0に渡すか、その逆に渡すことをお勧めします。

iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
iptables -A FORWARD -i ppp+ -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o ppp+ -j ACCEPT

私の設定はCentOS、専用サーバーです。

何らかの理由で、iptablesがすべてのトラフィックをeth0からtun0にルーティングし、そこで停止することを前提としています。

  1. これらの順方向ルールは互いに競合していますか?
  2. 衝突を避けるために、ppp+をeth0:1に渡す必要がありますか?可能ですか?私はまだそれを理解していません。
  3. iptablesは、これらのルールを介してtunおよびppp固有のトラフィックをルーティングするのに十分スマートですか?

ベストアンサー1

私が正しく理解したら、OpenVPNトンネルとPPTPトンネルが必要です。それぞれトンネルトラフィックをeth0にルーティングしますが、それぞれ独自のIPを持っています。

私が間違っている場合は明確に説明してください。最善を尽くしてお手伝いします。しかし、私はこのスクリプトがあなたの要件を満たすと信じています。

#!/bin/bash

# This enables forwarding in the kernel.
echo 1 > /proc/sys/net/ipv4/ip_forward

# This will allow all return traffic to pass back to the originating socket
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

# This permits forwarding traffic that came in either tunnel and bound out eth0.
# Note: This does not explicitly permit forwarding between tunnels.
iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -A FORWARD -i ppp+ -o eth0 -j ACCEPT

# This blocks all forwarding that is not explicitly permitted.
# Removing this line would be unsafe.
iptables -A FORWARD -j DROP

# These lines will SNAT the traffic coming from each tunnel to the
# appropriate IP address.
iptables -t nat -A POSTROUTING -i tun0 -o eth0 -j SNAT --to-source 1.1.1.1
iptables -t nat -A POSTROUTING -i ppp+ -o eth0 -j SNAT --to-source 1.1.1.2

このスクリプトを複数回実行すると、ルールが設定されます。次のスクリプトはファイアウォールルールを更新し、転送を無効にします。私は通常ファイアウォールスクリプトの先頭にこれを含めますが、それが安全であるかどうかわからないので、別々に含めます。

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t filter -F
iptables -t nat -F

おすすめ記事