To content | To menu | To search

OpenWrt 21.02 と @nifty v6サービス(OCNバーチャルコネクト)と J:COM と。MAP-E 無し。

元々 J:COM の回線を使っていて、いろいろあって、下り 320Mbps 上り 10Mbps に切り替え。
ついでに元々アカウントだけ契約していた @nifty のフレッツも契約。
回線が速くなったので、なんちゃって 1000Base だった Raspberry Pi 3B+ も 4B に変更。
4B は OpenWrt 21.02 以降のサポートなので、リリースを待った。
MAP-E は使うのを一旦断念。

使ったハードウェアは Raspberry Pi 4 Model B Rev 1.2 (2GB モデル)に TP-Link の UE300 2個。オンボードの RJ45 は LAN に。UE300 2個は J:COM とフレッツに。フレッツはホームゲートウェイ無しで ONU 直結。

UE300 は2個ともあらかじめ Raspberry PI 4 につないでおく。ただ LAN ケーブルはオンボードのとフレッツのだけつないで、J:COM のは外しておく。

LAN 上の主な端末はメインの Windows 10、Windows 10ノート、Nintendo Switch、WiFi アクセスポイント経由して iPhone と Android 。作業はメインの Windows 10 から。

SDカードイメージと、後述する UE300 用ドライバのパッケージをダウンロードしておく。

Windows 上のソフトはイメージを書き込む balenaEtcher と端末は TeraTerm とあとは適当なブラウザ。SD イメージをマイクロSDに書き込んで起動。

Windows 側の IP アドレスを OpenWrt のデフォルトに合わせて一旦手動で 192.168.1.XXX に。

TeraTerm の SSH で 192.168.1.1 に対して root / password でログイン。

パスワードを変更。

root@OpenWrt:~# passwd
Changing password for root
New password:
Retype password:
passwd: password for root changed by root

ローカルのアドレスを変えたいので編集&反映。

root@OpenWrt:~# vi /etc/config/network

「config interface 'lan'」の「option ipaddr」に任意の値を設定。

root@OpenWrt:~# uci commit /etc/config/network

UE300 はそのままではドライバが入っていないので、別途ダウンロードしてインストール。ファイルはこの3つ。

  • kmod-mii_5.4.143-1_aarch64_cortex-a72.ipk
  • kmod-usb-net-rtl8152_5.4.143-1_aarch64_cortex-a72.ipk
  • kmod-usb-net_5.4.143-1_aarch64_cortex-a72.ipk
root@OpenWrt:~# opkg install kmod-mii_5.4.143-1_aarch64_cortex-a72.ipk
Installing kmod-mii (5.4.143-1) to root...
Configuring kmod-mii.
root@OpenWrt:~# opkg install kmod-usb-net_5.4.143-1_aarch64_cortex-a72.ipk
Installing kmod-usb-net (5.4.143-1) to root...
Configuring kmod-usb-net.
root@OpenWrt:~# opkg install kmod-usb-net-rtl8152_5.4.143-1_aarch64_cortex-a72.ipk
Installing kmod-usb-net-rtl8152 (5.4.143-1) to root...
Configuring kmod-usb-net-rtl8152.
root@OpenWrt:~# halt

一旦電源入れ直す。

J:COM は IPv4 に限れば簡単につながるけれど、フレッツは苦労したので、判断しやすいようにここでは J:COM のは外してある。

Windows 側は IP アドレスは DHCP で取得するように戻して IP アドレス取得

ipconfig /renew

OpenWrt の web にアクセスしログイン。
Network → Interfaces を開く。

Add new interface で、Name は wan6、Protocol は DHCPv6 client、Device は eth1 で Create interface 。 Firewall Settings で wan を選択し Save 。

もう一度 Add new interface で、Name は wanb、Protocol は DHCP client、Device は eth2 で Create interface 。 Firewall Settings で wan を選択し Save 。

Interfaces の画面で Save & Apply 。

wan6 で IPv6 アドレスがとれたら、Network → Diagnostics で IPv6 Ping をためす


みんなここまでで説明が終わるので、これだけで普通は IPv6 が通るのかもしれない。ただうちの環境では IPv6 さえ全く通らなかったのでもう少し四苦八苦してなんとか通るようになった。


ここから次の区切り線までは、もしかしたら MAP-E 諦めたら要らないかもしれない。

map-e 計算機を開く。 http://ipv4.web.fc2.com/map-e.html wan6 が取得したアドレスを入力して計算。

SSH でログイン。

root@OpenWrt:~# vi /etc/config/network

「config interface 'wan6'」の設定の中に「list ip6prefix 'XXXX:YYYY:ZZZZ::/56'」を追加。

値の由来は忘れたけれど、多分 MAP-E 計算機の出力の ip6prefix から。多分データのまとまりが3個だけだったから /56 にした。4個なら /64 。書き換えたら反映。

root@OpenWrt:~# uci commit /etc/config/network

web の Network → Interfaces で wan6 を Restart すると IPv6-PD という行が増えている。


いくつかパッケージを追加する。

curl と diffutils は普通使わないと思うけれど念のため。map は入れてるけれどあとで諦めた。iptables-mod-ipopt は何に使うんだったか忘れた。kmod-ipt-nat6 は必須。

/
root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install curl diffutils map iptables-mod-ipopt kmod-ipt-nat6
/

https://openwrt.org/docs/guide-user/network/ipv6/ipv6.nat6

ここの 3. Firewall に従う。

root@OpenWrt:~# uci set $(uci show firewall | sed -n -e "/\.name='wan'$/s//.masq
6='1'/p" | sed -n -e "1p")
root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# uci set $(uci show firewall | sed -n -e "/\.name='Allow-ICMPv6-F
orward'$/s//.enabled='0'/p" | sed -n -e "1p")
root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# cat << "EOF" > /etc/firewall.nat6
> # NAT6 + masquerading firewall script
> # https://github.com/akatrevorjay/openwrt-masq6
> # trevorj <github@trevor.joynson.io>
> #
> # You can configure in /etc/config/firewall per zone:
> # * IPv4 masquerading
> #     option masq 1
> # * IPv6 masquerading
> #     option masq6 1
> # * IPv6 privacy extensions
> #     option masq6_privacy 1
>
> set -e -o pipefail
>
> . /lib/functions.sh
> . /lib/functions/network.sh
> . /usr/share/libubox/jshn.sh
>
> log() {
>     logger -t nat6 -s "${@}"
> }
>
> get_ula_prefix() {
>     uci get network.globals.ula_prefix
> }
>
> validate_ula_prefix() {
>     local ula_prefix="${1}"
>     if [ $(echo "${ula_prefix}" | grep -c -E -e "^([0-9a-fA-F]{4}):([0-9a-fA-F
]{0,4}):") -ne 1 ] ; then
>         log "Fatal error: IPv6 ULA ula_prefix="${ula_prefix}" seems invalid.
 Please verify that a ula_prefix is set and valid."
>         return 1
>     fi
> }
>
> ip6t() {
>     ip6tables "${@}"
> }
>
> ip6t_add() {
>     if ! ip6t -C "${@}" &> /dev/null; then
>         ip6t -I "${@}"
>     fi
> }
>
> nat6_init() {
>     iptables-save -t nat \
>     | sed -e "/\s[DS]NAT\s/d;/\sMASQUERADE$/d;/\s--match-set\s\S*/s//\06/" \
>     | ip6tables-restore -T nat
> }
>
> masq6_network() {
>     # ${config} contains the ID of the current section
>     local network_name="${1}"
>
>     local device
>     network_get_device device "${network_name}" || return 0
>
>     local done_net_dev
>     for done_net_dev in ${DONE_NETWORK_DEVICES}; do
>         if [ "${done_net_dev}" = "${device}" ]; then
>             log "Already configured device="${device}", so leaving as is."
>             return 0
>         fi
>     done
>
>     log "Found device="${device}" for network_name="${network_name}"."
>
>     if [ "${zone_masq6_privacy}" -eq 1 ]; then
>         log "Enabling IPv6 temporary addresses for device="${device}"."
>
>         log "Accepting router advertisements on ${device} even if forwarding i
s enabled (required for temporary addresses)"
>         echo 2 > "/proc/sys/net/ipv6/conf/${device}/accept_ra" \
>         || log "Error: Failed to change router advertisements accept policy on
 ${device} (required for temporary addresses)"
>
>         log "Using temporary addresses for outgoing connections on interface $
{device}"
>         echo 2 > "/proc/sys/net/ipv6/conf/${device}/use_tempaddr" \
>         || log "Error: Failed to enable temporary addresses for outgoing conne
ctions on interface ${device}"
>     fi
>
>     append DONE_NETWORK_DEVICES "${device}"
> }
>
> handle_zone() {
>     # ${config} contains the ID of the current section
>     local config="${1}"
>
>     local zone_name
>     config_get zone_name "${config}" name
>
>     # Enable masquerading via NAT6
>     local zone_masq6
>     config_get_bool zone_masq6 "${config}" masq6 0
>
>     log "Firewall config="${config}" zone="${zone_name}" zone_masq6="${zo
ne_masq6}"."
>
>     if [ "${zone_masq6}" -eq 0 ]; then
>         return 0
>     fi
>
>     # IPv6 privacy extensions: Use temporary addrs for outgoing connections?
>     local zone_masq6_privacy
>     config_get_bool zone_masq6_privacy "${config}" masq6_privacy 1
>
>     log "Found firewall zone_name="${zone_name}" with zone_masq6="${zone_ma
sq6}" zone_masq6_privacy="${zone_masq6_privacy}"."
>
>     log "Setting up masquerading nat6 for zone_name="${zone_name}" with zone
_masq6_privacy="${zone_masq6_privacy}""
>
>     local ula_prefix="$(get_ula_prefix)"
>     validate_ula_prefix "${ula_prefix}" || return 1
>
>     local postrouting_chain="zone_${zone_name}_postrouting"
>     log "Ensuring ip6tables chain="${postrouting_chain}" contains our MASQUE
RADE."
>     ip6t_add "${postrouting_chain}" -t nat \
>         -m comment --comment "!fw3" -j MASQUERADE
>
>     local input_chain="zone_${zone_name}_input"
>     log "Ensuring ip6tables chain="${input_chain}" contains our permissive D
NAT rule."
>     ip6t_add "${input_chain}" -t filter -m conntrack --ctstate DNAT \
>         -m comment --comment "!fw3: Accept port forwards" -j ACCEPT
>
>     local forward_chain="zone_${zone_name}_forward"
>     log "Ensuring ip6tables chain="${forward_chain}" contains our permissive
 DNAT rule."
>     ip6t_add "${forward_chain}" -t filter -m conntrack --ctstate DNAT \
>         -m comment --comment "!fw3: Accept port forwards" -j ACCEPT
>
>     local DONE_NETWORK_DEVICES=""
>     config_list_foreach "${config}" network masq6_network
>
>     log "Done setting up nat6 for zone="${zone_name}" on devices: ${DONE_NET
WORK_DEVICES}"
> }
>
> main() {
>     nat6_init
>     config_load firewall
>     config_foreach handle_zone zone
> }
>
> main "${@}"
> EOF
root@OpenWrt:~# cat << "EOF" >> /etc/sysupgrade.conf
> /etc/firewall.nat6
> EOF
root@OpenWrt:~# uci -q delete firewall.nat6
root@OpenWrt:~# uci set firewall.nat6="include"
root@OpenWrt:~# uci set firewall.nat6.path="/etc/firewall.nat6"
root@OpenWrt:~# uci set firewall.nat6.reload="1"
root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# /etc/init.d/firewall restart
Warning: Unable to locate ipset utility, disabling ipset support
Warning: Option @zone[1].masq6 is unknown
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan'
 * Flushing IPv4 filter table
 * Flushing IPv4 nat table
 * Flushing IPv4 mangle table
 * Flushing IPv4 raw table
 * Flushing IPv6 filter table
 * Flushing IPv6 nat table
 * Flushing IPv6 mangle table
 * Flushing conntrack table ...
 * Populating IPv4 filter table
   * Rule 'Allow-DHCP-Renew'
   * Rule 'Allow-Ping'
   * Rule 'Allow-IGMP'
   * Rule 'Allow-IPSec-ESP'
   * Rule 'Allow-ISAKMP'
   * Forward 'lan' -> 'wan'
   * Zone 'lan'
   * Zone 'wan'
 * Populating IPv4 nat table
   * Zone 'lan'
   * Zone 'wan'
 * Populating IPv4 mangle table
   * Zone 'lan'
   * Zone 'wan'
 * Populating IPv4 raw table
   * Zone 'lan'
     - Using automatic conntrack helper attachment
   * Zone 'wan'
 * Populating IPv6 filter table
   * Rule 'Allow-DHCPv6'
   * Rule 'Allow-MLD'
   * Rule 'Allow-ICMPv6-Input'
   * Rule 'Allow-IPSec-ESP'
   * Rule 'Allow-ISAKMP'
   * Forward 'lan' -> 'wan'
   * Zone 'lan'
   * Zone 'wan'
 * Populating IPv6 nat table
Warning: fw3_ipt_rule_append(): Can't find target 'prerouting_lan_rule'
Warning: fw3_ipt_rule_append(): Can't find target 'postrouting_lan_rule'
Warning: fw3_ipt_rule_append(): Can't find target 'prerouting_wan_rule'
Warning: fw3_ipt_rule_append(): Can't find target 'postrouting_wan_rule'
Warning: fw3_ipt_rule_append(): Can't find target 'prerouting_rule'
Warning: fw3_ipt_rule_append(): Can't find target 'postrouting_rule'
   * Zone 'lan'
   * Zone 'wan'
 * Populating IPv6 mangle table
   * Zone 'lan'
   * Zone 'wan'
 * Set tcp_ecn to off
 * Set tcp_syncookies to on
 * Set tcp_window_scaling to on
 * Running script '/etc/firewall.user'
 * Running script '/etc/firewall.nat6'
nat6: Firewall config="cfg02dc81" zone="lan" zone_masq6="0".
nat6: Firewall config="cfg03dc81" zone="wan" zone_masq6="0".

ただそのままコピペして実行したら、/etc/config/firewall への設定がおかしいようだったので編集。

root@OpenWrt:~# vi /etc/config/firewall

「config zone」の「option masq6」の値が「''1'\'」になっているので「'1'」に直す。
「config rule」の「option enabled」も同様に「'0'」にする。
保存したら反映。

root@OpenWrt:~# uci commit firewall
root@OpenWrt:~# /etc/init.d/firewall restart

念のため Windows 側で ipconfig /renew 。
これでしばらくすると IPv6 で通信ができているはず。


IPv6 の接続性チェック。ただ、結構失敗する。

  • https://ipv6-test.com/
  • https://v6test.ocn.ne.jp/
  • https://test-ipv6.com/
  • http://kiriwake.jpne.co.jp/
  • https://ipv6test.google.com/

System → Software で Update lists を実行。
luci-app-mwan3 をインストール。
再度ログイン。

Network → Load balancing を開く。
wan の Edit で Enabled のチェックを外して Save & Apply。Back to overview で戻る。
wan6 と wanb で Edit で Enabled をチェックして、それぞれ Save & Apply。
Rules を開いて https を Delete して Save & Apply 。

これで JCOM のケーブルを接続し、Status → Load balancing を開くと、wanb と wan6 が online 。

Network → Interfaces で、wan6 と wanb の Edit で、Advanced Settings の Use gateway metric の値をそれぞれ設定。異なる値で、大きい方が優先、のはず。例えば 100 と 50 とか。

これで IPv6 はフレッツに、IPv4 は J:COM を通るはず。


本当は MAP-E を通して、IPv4 も Load balancing 通したかった。MAP-E が動いて仮想インタフェースまでできたのだけれど、その状態がとても不安定で J:COM 側のインタフェースや IPv6 まで通らなくなる現象がでたので一旦保留。


この関係でよく見かける LEGACY=1 のコメントアウトを解除、のやつ、以下のサイトの中にでてくる option legacymap ‘1’ の方がスマートにできそう。


参考にした web サイト、利用した web サイト

  • https://blog.hinaloe.net/2020/03/14/openwrt-mape-ocn/
  • https://zenn.dev/yakumo/articles/19cbc6309d8143cc9349b2fb0d29771e
  • https://zenn.dev/yakumo/articles/74c16c2e737841b6945e2309243236a2
  • https://blog.mamemaki.com/entry/2019/12/15/171104
  • https://gist.github.com/anonymous/0fdec75fa20a7f1ce4806391d6b0429b
  • https://p.teknik.io/YuLFn
  • https://blog.osakana.net/archives/category/router/openwrt
  • https://pastebin.pl/view/raw/06212cd8
  • https://gist.github.com/osakanataro/a9ba5ded340070b8e6abc28969d7ae4f
  • https://blog.misosi.ru/2019/12/02/openwrt-mape/
  • https://blog.misosi.ru/2019/12/14/openwrt-v6plus-stuck/
  • http://ipv4.web.fc2.com/map-e.html
  • http://kiriwake.jpne.co.jp/
  • https://test-ipv6.com/
  • https://v6test.ocn.ne.jp/
  • https://ipv6-test.com/
  • https://developers.google.com/speed/public-dns/docs/using
  • https://qiita.com/daredeshow/items/7af368e6b95b62a04e5e
  • https://openwrt.org/docs/guide-user/network/wan/multiwan/mwan3
  • https://openwrt.org/docs/guide-user/network/ipv6/start
  • https://openwrt.org/docs/guide-user/network/ipv6/ipv6.nat6

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

They posted on the same topic

Trackback URL : https://www.pseudomoon.jp/dotclear/index.php?trackback/139

This post's comments feed