ホーム ネットワーク上のグローバルにルーティング可能な Web サーバーに対して、ポート 80/443 で受信 IPv6 トラフィックを許可したいと考えています。OpenWrt ではデフォルトで受信 IPv6 トラフィックがブロックされます (優れたファイアウォールとして当然のことですが)。これを実現する最適な方法は何でしょうか。
私の ISP (Comcast) は、DHCPv6 経由で委任用に /60 プレフィックスを割り当てます。これは時々変更されます。Web サーバー (Ubuntu) は、OpenWrt ルーターから SLAAC 経由でグローバル IPv6 アドレスを取得します。
に従ってhttps://wiki.openwrt.org/doc/uci/firewall#port_accept_for_ipv6次のようなトラフィックを許可するトラフィック ルールを設定できます。
ポート 80 を開いて、インターネットから 2001:db8:42::1337 のローカル Web サーバーにアクセスできるようにするには、次のようにします。
設定ルール オプション src wan オプション プロトコル TCP オプション 宛先 LAN オプション dest_ip 2001:db8:42::1337 オプション dest_port 80 オプション ファミリ ipv6 オプションターゲットACCEPT
簡単ですが、宛先 IP がハードコードされている点が異なります。
宛先 IP が変化する可能性がある場合、このタイプのルールをどのように設定すればよいでしょうか?(ISP からの委任プレフィックスの変更による)。おそらく、定期的に更新する必要があります...。これを試した人はいますか? もし試したなら、何がうまく機能し、何がうまく機能しないのでしょうか?
答え1
私もあなたと同じ問題に遭遇し、行き詰まってしまいました。ファイアウォールの変更を自動化するための簡単なスクリプトを作成しました。
#!/bin/sh
# CONFIGURABLE PARAMETER: PREFIX
# the prefix is the prefix of all the firewall rules that should be changed
PREFIX=DynamicIPv6
PREFIX_LEN=${#PREFIX}
# get current IPv6 prefix from WAN
. /lib/functions/network.sh
network_get_prefix6 prefix6 wan6
prefix6=$(echo $prefix6 | cut -d/ -f1)
prefix_len=$(expr ${#prefix6} - 1)
prefix6=${prefix6:0:$prefix_len}
changed=0
index=0
name=$(uci get firewall.@rule[$index].name 2> /dev/null)
while [ "$name" != "" ]; do
subname=${name:0:$PREFIX_LEN}
# if the prefix matches, determine whether to change the firewall rules
if [ "$subname" == "$PREFIX" ]; then
dest_ip=$(uci get firewall.@rule[$index].dest_ip 2> /dev/null)
dest_network=${dest_ip:0:$prefix_len}
host_addr=$(echo $dest_ip | awk -F: 'BEGIN { OFS=":"; } { print $5,$6,$7,$8 }')
# if the firewall rule and prefix mismatch, update the firewall
if [ "$dest_network" != "$prefix6" ]; then
changed=1
new_ip="${prefix6}${host_addr}"
uci set firewall.@rule[$index].dest_ip=$new_ip
uci commit firewall
fi
fi
# advance to the next firewall rule
index=$(expr $index + 1)
name=$(uci get firewall.@rule[$index].name 2> /dev/null)
done
# if changes were detected, then reload the firewall
if [ $changed -eq 1 ]; then
/etc/init.d/firewall reload 2> /dev/null
fi
スクリプトを使用するには:
PREFIX
スクリプトを使用してファイアウォール ルールを作成します。- cron を使用してスクリプトの実行をスケジュールします。
既知の問題:スクリプトは完全な IPv6 アドレスに制限されており、:: 短縮形は使用できません。(例: 2600:dead:beef:cafe::1 ではなく 2600:dead:beef:cafe:0:0:0:1)。
このスクリプトは完璧とは程遠いので、お手柔らかにお願いします。このスクリプトは、皆さんの役に立つことを願って提供しています。:)
答え2
チェックアウト動的プレフィックス転送接頭辞に負の数を使用できるトリックがあるからです。
設定する静的 DHCPv6 リース転送ルールを追加します。
uci add firewall rule uci set firewall.@rule[-1].name="Forward-IPv6" uci set firewall.@rule[-1].src="wan" uci set firewall.@rule[-1].dest="lan" uci set firewall.@rule[-1].dest_ip="::123/-64" uci set firewall.@rule[-1].family="ipv6" uci set firewall.@rule[-1].proto="tcpudp" uci set firewall.@rule[-1].target="ACCEPT" uci commit firewall /etc/init.d/firewall restart