WPP
Windows の pipenv でも上下キーでヒストリーをたどりたい

タイトルのとおりですが、Windows の powershell 7 で pipenv shell するとコマンドの実行履歴がたどれなくなりなんとかしたいと思っていた。

ネット上を検索するといくつか回避策を見つけられたがどれも自分にはしっくりこなかったので、Claude に聞いてみて解決策を見つけたので記事にする。

そもそも pipenv shell すると powershell にいるにも関わらず command プロンプトが起動しているのが原因じゃないかと推測している。

いくつかのページでは、pipenv run pwsh で、直接powershell を起動すればいい的なことを書いているがそうするとプロンプト文字列の (VENV名) が消えてしまう。

(VENV名) は venv フォルダの Scripts の中にある activate.ps1 や activate.bat を起動すると表示できる。

解決策は Claude が言うままに $PROFILE に関数とエリアスを定義してやる。


function Invoke-PipenvPwsh {
  $venv_path = pipenv --venv 2>$null
  if ($venv_path -and (Test-path "$venv_path\Scripts\Activate.ps1")) {
    & "$venv_path\Scripts\Activate.ps1"
  } else {
    Write-error "Pipenv venv not found"
  }
}

Set-Alias pipenv-shell Invoke-PipenvPwsh

; これは不要だけど、名前を対照的にするためにエリアスを定義
Set-Alias pipenv-exit deactivate

反映するには以下を実行する。

; $PROFILE を反映する
PS > . $PROFILE

; pipenv shell の変わりに pipenv-shell で activate.ps1  を起動する
PS > pipenv-shell
(VENV 名)  PS > 

; 注意 exit しちゃうと shell そのものから抜けちゃうので  deactivate で抜ける
(VENV 名)  PS >  deactivate

function でやっていることは特別難しいことではなくて、 pipenv –venv で venv の場所を取得して、そのなかの activate.ps1 を起動している。

win / Linux に限らず shell 関係のスクリプトを空で書くのって結構面倒だからほんと Claude に頼りきりだ。こうやって人は AI の奴隷になっていくのかと思ってみたり。

ともあれ、これでちょっといい感じになった。

RUSTDESK で タスクマネージャーのカーソルが消えてしまい、閉じることができない

最近気に入って使っている RUSTDESK だが一つだけ困った挙動があった、それは、タスクマネージャーを開いてしまうとその Window だけリモート側からはクリックもなにもできなくなるという現象だ。

普段は隣り合った 2 台の PC を RUSTDESK でリモートアクセスしているので、上の事態になったら手を伸ばしてタスクマネージャーを閉じているのでいいのだが、遠隔地でこれやっちゃうと閉じることがのでちょっと安心して操作できないなと感じていた。

重い腰を上げて調べてみると公式のドキュメントがあった。普段あまり意識していないがタスクマネージャーは管理者権限に昇格することが必要らしい。
なので、昇格して動いているタスクマネージャーは一般ユーザーで動く RUSTDESK からは触れなくなってしまうようだ。

回避策は、操作される側の PC の RUSTDESK を管理者として起動してやればいい。
なので右クリックで 「管理者として実行」 するか、
毎回やるのが面倒ならウィンドウメニューに登録されているショートカットを右クリックして 「管理者として実行」 にチェックをつければ回避できる。

参考

Windows ポータブル昇格 – RustDeskのドキュメント

Apt でインストールした ROS の gpg がエラーになる

apt update すると下記の警告がでるようになった。参考リンクによると今月に入ってから、らしい。

おおよそ GPG キーの期限切れだろうと予測していたが (サードパーティの apt リポジトリを追加していると比較的出くわす) がその通りだった。

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.ros.org/ros2/ubuntu noble InRelease: The following signatures were invalid: EXPKEYSIG F42ED6FBAB17C654 Open Robotics <info@osrfoundation.org>
W: Failed to fetch http://packages.ros.org/ros2/ubuntu/dists/noble/InRelease  The following signatures were invalid: EXPKEYSIG F42ED6FBAB17C654 Open Robotics <info@osrfoundation.org>
W: Some index files failed to download. They have been ignored, or old ones used instead.

GPG キーを入れ替えればいいだけなのだが、URL がわからなかったのでメモする。

鍵は https://raw.githubusercontent.com/ros/rosdistro/master/ros.key にあるようなので

curl -sS https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o ros.key
とか
wget https://raw.githubusercontent.com/ros/rosdistro/master/ros.key

あとは /etc/apt/sources.list.d にある ROS リポジトリの設定に従って鍵ファイルを配置して(入れ替えて)やれば OK。

自分の場合は、

/etc/apt/sources.list.d/ros2.list にリポジトリを定義してあり、鍵ファイルは

/usr/share/keyrings/ros.gpg

となっていたので、 ros.key を ros.gpg として /usr/share/keyrings に配置してやればいい。

参考

2025年6月以降ROS環境でapt-get updateするときにGPG errorが発生する場合の対処方法

YAMAHA RTX1210 を Asahiネット IPIP + 固定IPアドレスで IKEv2 リモートアクセスを設定+ L2TP

前回は、 YAMAHA の RTX に IKEv2 を設定したが、iPhone で接続できなかったので仕方なく L2TP も追加した。

動機

さて前回までで、IKEv2 のリモートアクセスは構築できたわけですが、iPhone から接続はできませんでした。理由は iOS 18 以降は、RTX の提案する暗号化? 方式に対応していないからのようです。

Apple Configurator という Apple 製アプリで設定を変更することができるようですが、Mac は昨年手放したのであいにく手元にありません。他の情報では 「Mac 以外になにか企業向けのアカウントを持っていないとそもそも Apple Configurator を使えない」というような情報もあり Mac は欲しいがあやふやな情報すぎて却下。

いい感じの VPN クライアントを探そうかと思いましたが、数ある VPN サービスが出している VPN クライアントと見分けるのが困難なので早々に諦めた。(Apple のストアに掲載するにはたとえオープンソースであっても有料なのでどうしたってオープンソース系のアプリは少なくなる。

なので折角排除した L2TP を iPhone 用に復活した。

環境等

この辺も前回と同じ。

  • Asahiネット 光 の 1G のコース 10G だと「固定IPアドレスオプション」が使えない
  • 固定IPアドレスオプション
  • その結果、IPv4 over IPv6接続 (IPIP)
  • ひかり電話なし
  • ONU のみ
  • IKEv2 リモートアクセスは前回の記事で追加ずみ。

ネットワーク設計

RTX のインターフェイスはこんな感じ。

RTX: 192.168.1.254
LAN2: IPoE 接続
LAN1: 192.168.1.0/24 の宅内LAN
Tunnel1: IPIP でここで IPv4 に変換
Tunnel10: IKEv2
pp anonymous: L2TP の認証部分を担当するらしい。
Tunnel21: L2TP トンネル

固定IPv4: 157.107.YYY.ZZZ (適宜振り出されたIPに変えること)

RTX に設定した内容

はじめ、ipsec ike local name を適当な文字列にした上で、key-id としていたために、接続することができなかった。これに気づくまで数日かかってしまった。

設定全体は以下の通り、自分に固有のアドレス部分を変えればそのまま動くはず。

# RTX1210 Rev.14.01.42 (Fri Jul  5 11:17:45 2024)
# MAC Address : 00:a0:de:f0:48:21, 00:a0:de:f0:48:22, 00:a0:de:f0:48:23
# Memory 256Mbytes, 3LAN, 1BRI
# main:  RTX1210 ver=00 serial=S4H051400 MAC-Address=00:a0:de:f0:48:21 MAC-Address=00:a0:de:f0:48:22 MAC-Address=00:a0:de:f0:48:23 TAM=11
# Reporting Date: Jun 7 11:47:14 2025
login password *
administrator password *
login user admin *
user attribute connection=serial,telnet gui-page=dashboard,lan-map,config login-timer=1800
user attribute admin connection=serial,telnet,remote,ssh,sftp,http gui-page=dashboard,lan-map,config login-timer=1800
console character ja.utf8
console columns 120
console lines 40
system packet-buffer small max-buffer=3000
system packet-buffer middle max-buffer=7000
ip route default gateway tunnel 1
ipv6 prefix 1 ra-prefix@lan2::/64
ip lan1 address 192.168.1.254/24
ip lan1 proxyarp on
ipv6 lan1 address ra-prefix@lan2::9d6b:ZZZZ:0/64
ipv6 lan1 prefix change log on
ipv6 lan1 rtadv send 1 o_flag=on
ipv6 lan1 dhcp service server
switch control use lan1 on terminal=on
description lan2 Asahi-NET
lan linkup send-wait-time lan2 5
ipv6 lan2 secure filter in 101000 101002 101003 101004 102001 102002 102003
ipv6 lan2 secure filter out 101099 dynamic 101080 101081 101082 101083 101084 101085 101098 101099
ipv6 lan2 dhcp service client ir=on
ngn type lan2 ntt

# L2TP の認証に必要
pp select anonymous
 pp bind tunnel20-tunnel21
 pp auth request chap-pap
 pp auth username vpn1 pass1234
 pp auth username vpn2 pass1234
 ppp ipcp ipaddress on
 ppp ipcp msext on

# クライアントに対し10.10.10.x を払い出し、dhcp と重ならない同一のサブネットからでも OK
 ip pp remote address pool 10.10.10.1-10.10.10.10
 ip pp mtu 1258
 pp enable anonymous


tunnel select 1
 tunnel encapsulation ipip

# AsahiNet から指定のあった IPv6
 tunnel endpoint remote address 2001:c28:1:YYYY::ZZZZ
 ip tunnel mtu 1460
 ip tunnel secure filter in 1101 1505 1506 1507 1997
 ip tunnel secure filter out 1002 1003 1004 1005 1006 1007 1008 9999 dynamic 3001 3002 3003 3098 3099
 ip tunnel nat descriptor 20000
 tunnel enable 1

# IKEv2
tunnel select 10
 tunnel template 11
 description tunnel "IKEv2 tunnel"
 tunnel encapsulation ipsec
 ipsec tunnel 10
  ipsec sa policy 10 10 esp
  ipsec ike version 10 2
  ipsec ike keepalive log 10 off
  ipsec ike keepalive use 10 on rfc4306 10 3

  # AsahiNet から払出された固定IP
  ipsec ike local name 10 157.107.YYY.ZZZ ipv4-addr

  # 共有キーは適当に変更すること
  ipsec ike pre-shared-key 10 text ike-preshared-key-XXX-YYY-ZZZ
  ipsec ike remote name 10 vpn fqdn
  ipsec ike mode-cfg address 10 1
 tunnel enable 10

# L2TP -1
tunnel select 21
 tunnel encapsulation l2tp
 ipsec tunnel 21
  ipsec sa policy 21 21 esp aes256-cbc sha256-hmac
  ipsec ike keepalive use 21 off
  ipsec ike nat-traversal 21 on

  # 共有キーは適当に変更すること
  ipsec ike pre-shared-key 21 text l2tp-preshared-key-XXX-YYY-ZZZ
  ipsec ike remote address 21 any
 l2tp tunnel disconnect time off
 l2tp keepalive use on 10 3
 l2tp syslog off
 ip tunnel tcp mss limit auto
 tunnel enable 21

# L2TP -2
tunnel select 22
 tunnel encapsulation l2tp
 ipsec tunnel 22
  ipsec sa policy 22 22 esp aes256-cbc sha256-hmac
  ipsec ike keepalive use 22 off
  ipsec ike nat-traversal 22 on

  # 共有キーは適当に変更すること
  ipsec ike pre-shared-key 21 text l2tp-preshared-key-XXX-YYY-ZZZ
  ipsec ike remote address 22 any
 l2tp keepalive use on 10 3
 l2tp keepalive log off
 ip tunnel tcp mss limit auto
 tunnel enable 22

ip filter 1001 reject 192.168.1.0/24 * * *
ip filter 1002 reject * 192.168.1.0/24 * * *
ip filter 1003 reject * * udp,tcp 135 *
ip filter 1004 reject * * udp,tcp * 135
ip filter 1005 reject * * udp,tcp netbios_ns-netbios_ssn *
ip filter 1006 reject * * udp,tcp * netbios_ns-netbios_ssn
ip filter 1007 reject * * udp,tcp 445 *
ip filter 1008 reject * * udp,tcp * 445
ip filter 1101 pass * * icmp * *

# IKEv2 (L2TP) を通すフィルタ
ip filter 1505 pass-log * 192.168.1.254 * * 500
ip filter 1506 pass-log * 192.168.1.254 esp
ip filter 1507 pass * 192.168.1.254 udp * 4500
ip filter 1997 reject * *
ip filter 1998 pass * * tcp * *
ip filter 1999 pass * * udp * *
ip filter 9999 pass * * * * *
ip filter 500000 restrict * * * * *
ip filter dynamic 3001 * * ftp
ip filter dynamic 3002 * * www
ip filter dynamic 3003 * * https
ip filter dynamic 3098 * * tcp
ip filter dynamic 3099 * * udp
nat descriptor type 20000 masquerade
nat descriptor address outer 20000 157.107.76.213
nat descriptor masquerade incoming 20000 reject 
nat descriptor masquerade static 20000 2001 192.168.1.254 esp
nat descriptor masquerade static 20000 2002 192.168.1.254 udp 500
nat descriptor masquerade static 20000 2003 192.168.1.254 udp 4500
ipsec auto refresh on
ipsec ike remote name 11 vpn1 fqdn
ipsec ike mode-cfg address pool 1 10.20.30.1-10.20.30.10/24

# L2TP の転送設定
ipsec transport 1 21 udp 1701
ipsec transport 2 22 udp 1701

ipv6 filter 101000 pass * * icmp6 * *
ipv6 filter 101002 pass * * udp * 546
ipv6 filter 101003 pass * * 4
ipv6 filter 101004 pass * * tcp * www
ipv6 filter 101099 pass * * * * *
ipv6 filter 102001 pass-log * * * 500
ipv6 filter 102002 pass * * esp
ipv6 filter 102003 pass * * udp * 4500
ipv6 filter dynamic 101080 * * ftp
ipv6 filter dynamic 101081 * * domain
ipv6 filter dynamic 101082 * * www
ipv6 filter dynamic 101083 * * smtp
ipv6 filter dynamic 101084 * * pop3
ipv6 filter dynamic 101085 * * submission
ipv6 filter dynamic 101098 * * tcp
ipv6 filter dynamic 101099 * * udp

telnetd host lan1
dhcp service server
dhcp server rfc2131 compliant except remain-silent
dhcp scope 1 192.168.1.100-192.168.1.249/24
dhcp scope bind 1 192.168.1.100 01 34 cf f6 f5 93 62
dhcp scope bind 1 192.168.1.230 01 00 bb c1 c0 4f 20
dhcp scope bind 1 192.168.1.231 01 d0 c0 bf 87 9b 65
dhcp scope bind 1 192.168.1.232 00:17:88:b2:58:45
dhcp scope bind 1 192.168.1.233 ff 7d 7b c0 11 00 01 00 01 2d 41 c0 e2 9a d0 7d 7b c0 11
dhcp scope bind 1 192.168.1.240 01 c8 9e 43 a1 50 76
dhcp scope bind 1 192.168.1.241 01 50 91 e3 35 e5 fc
dhcp scope bind 1 192.168.1.242 01 50 91 e3 35 e6 20
dhcp scope bind 1 192.168.1.244 01 90 09 d0 4b 06 cd
dhcp scope option 1 dns=192.168.1.245,192.168.1.254,9.9.9.9
dns host lan1
dns service fallback on
dns cache max entry 1024
dns server dhcp lan2
dns server select 500000 dhcp lan2 any .
dns private address spoof on
schedule at 1 startup * lua emfs:/v6plus_map_e.lua
schedule at 2 */* 05:43:21 * ntpdate ntp.nict.jp syslog

l2tp service on
# VPN に別サブネットを払出したので許可追加 (GUIからできる)
httpd host lan1 10.20.30.1-10.20.30.10 10.10.10.1-10.10.10.10

alarm entire off

sshd service on
# VPN に別サブネットを払出したので許可追加 (GUIからできる)
sshd host lan1 10.20.30.1-10.20.30.10 10.10.10.1-10.10.10.10
sshd host key generate *
# VPN に別サブネットを払出したので許可追加 (GUIからできる)
sftpd host lan1 10.20.30.1-10.20.30.10 10.10.10.1-10.10.10.10

statistics traffic on
statistics nat on

# このへんは趣味で。。。
alias cc="clear log"
alias jj="show log|grep -i reje"
alias rr="show log reverse"
alias sa="show ipsec sa"


# スクリプトは、「かんたん設定」が生成したものに URL、キー、パスワードをコピペ
embedded file v6plus_map_e.lua <<EOF
UPD_SV = "https://v6update.asahi-net.or.jp/prefix"
USERNAME = "P74ZZZZZZ"
PASSWORD = "DKZZZZZZ"
WAN_IF = "LAN1"

LOG_PTN = "Add%s+IPv6%s+prefix.+%(Lifetime%:%s+%d+%)%s+via%s+" .. WAN_IF .. "%s+by"
LOG_LEVEL = "info"
LOG_PFX = "[v6plus]"
FAIL_MSG = "Failed to notify IPv6 address to the update server. (remaining retry: %d time(s))"

function logger(msg)
rt.syslog(LOG_LEVEL, string.format("%s %s", LOG_PFX, msg))
end

local rtn, count, log, result
local req_t = {}
local res_t
req_t.url = string.format("%s?user=%s&pass=%s", UPD_SV, USERNAME, PASSWORD)
req_t.method = "GET"
while true do
rtn = rt.syslogwatch(LOG_PTN)
if rtn then
count = 3
while true do
res_t = rt.httprequest(req_t)
if res_t.rtn1 then
logger("Notified IPv6 address to the update server.")
if res_t.code == 200 then
result = "Succeeded"
else
result = "Failed"
end
log = string.format("%s to update IPv6 address. (code=%d, body=%s)", result, res_t.code, res_t.body)
logger(log)
break
end
count = count - 1
if count > 0 then
logger(string.format(FAIL_MSG, count))
rt.sleep(10)
else
logger("Failed to notify IPv6 address to the update server.")
break
end
end
end
end
EOF

これでようやくアンドロイド > IKEv2、iOS > L2TP でVPNを構築できた。途切れ途切れで1週間かかった。
考えてみたら、L2TP なら全部 GUI でできたのかも。

参考

YAMAHA RTX1210でリモートアクセスVPN (IKEv2)環境を作る(Mac/iPhone対応) #yamaha – Qiita
iOS 18 で接続できないときの対策がのっている

iPhoneでIPv6のリモートアクセスVPNをIKEv2でつなげたお話。【RTX830】 – かなぽんの備忘録Vol.2
大いに参考になりましたが、実力不足でこれだけでは完成できず。

L2TP/IPsecを使用したリモートアクセス : ルーター コマンド設定

YAMAHA RTX1210 を Asahiネット IPIP + 固定IPアドレスで IKEv2 リモートアクセスを設定

先週 YAMAHA の RTX に変更したのは、別の記事にしたが、IKEv2 リモートアクセスを設定したのでそれも晒す。

動機

前回も書いたことだが Android からリモートアクセス VPN できるようにしたかった。

それまでは OpenVPN で接続していたが設定ファイルの管理がやっぱり面倒なのでなんとかしたかった。

環境等

この辺は前回と同じ。

  • Asahiネット 光 の 1G のコース 10G だと「固定IPアドレスオプション」が使えない
  • 固定IPアドレスオプション
  • その結果、IPv4 over IPv6接続 (IPIP)
  • ひかり電話なし
  • ONU のみ

ネットワーク設計

RTX のインターフェイスはこんな感じ。

RTX: 192.168.1.254
LAN2: IPoE 接続
LAN1: 192.168.1.0/24 の宅内LAN
Tunnel1: IPIP でここで IPv4 に変換
Tunnel2: IKEv2

固定IPv4: 157.107.YYY.ZZZ (適宜振り出されたIPに変えること)

RTX の設定した内容

わりと公式のサンプルのままでできるようだ。

IPIP トンネルを通った後、IKEv2 のトンネル処理をしなければいけなのでどうか書くのかよくわからなかったが、ipsec local name で振り出された固定IP にするといい感じにしてくれるらしい

はじめ、ipsec ike local name を適当な文字列にした上で、key-id としていたために、接続することができなかった。これに気づくまで数日かかってしまった。

設定全体は以下の通り、自分に固有のアドレス部分を変えればそのまま動くはず。

# RTX1210 Rev.14.01.42 (Fri Jul  5 11:17:45 2024)
# MAC Address : 00:a0:de:f0:48:21, 00:a0:de:f0:48:22, 00:a0:de:f0:48:23
# Memory 256Mbytes, 3LAN, 1BRI
# main:  RTX1210 ver=00 serial=S4H051400 MAC-Address=00:a0:de:f0:48:21 MAC-Address=00:a0:de:f0:48:22 MAC-Address=00:a0:de:f0:48:23 TAM=11
# Reporting Date: Jun 5 23:58:52 2025

# この辺は適当に好みで
login password *
administrator password *
login user admin *
user attribute connection=serial,telnet gui-page=dashboard,lan-map,config login-timer=1800
user attribute admin connection=serial,telnet,remote,ssh,sftp,http gui-page=dashboard,lan-map,config login-timer=1800
console character ja.utf8
console columns 120
console lines 40

# 大量パケットを送受信した際に LANに障害発生というAlertが出る対策
system packet-buffer small max-buffer=3000
system packet-buffer middle max-buffer=7000

ip route default gateway tunnel 1
ipv6 prefix 1 ra-prefix@lan2::/64
ip lan1 address 192.168.1.254/24
ip lan1 proxyarp on

#  AsahiNet から振り出されたプリフィックス
ipv6 lan1 address ra-prefix@lan2::ZZZZ:ZZZZ:0/64

ipv6 lan1 prefix change log on
ipv6 lan1 rtadv send 1 o_flag=on
ipv6 lan1 dhcp service server
switch control use lan1 on terminal=on
description lan2 Asahi-NET
lan linkup send-wait-time lan2 5
ipv6 lan2 secure filter in 101000 101002 101003 101004
ipv6 lan2 secure filter out 101099 dynamic 101080 101081 101082 101083 101084 101085 101098 101099
ipv6 filter 101000 pass * * icmp6 * *
ipv6 filter 101002 pass * * udp * 546
ipv6 filter 101003 pass * * 4
ipv6 filter 101004 pass * * tcp * www
ipv6 filter 101099 pass * * * * *
ipv6 filter dynamic 101080 * * ftp
ipv6 filter dynamic 101081 * * domain
ipv6 filter dynamic 101082 * * www
ipv6 filter dynamic 101083 * * smtp
ipv6 filter dynamic 101084 * * pop3
ipv6 filter dynamic 101085 * * submission
ipv6 filter dynamic 101098 * * tcp
ipv6 filter dynamic 101099 * * udp

ipv6 lan2 dhcp service client ir=on
ngn type lan2 ntt

tunnel select 1
 tunnel encapsulation ipip

# プロバイダが指定する終端アドレス
 tunnel endpoint remote address 2001:c28:1:XXXX::ZZZZZ
 ip tunnel mtu 1460
 ip tunnel secure filter in 1101 1500 1501 1502 1503 1504 1505 1506 1507 1997
 ip tunnel secure filter out 1002 1003 1004 1005 1006 1007 1008 9999 dynamic 3001 3002 3003 3098 3099
 ip tunnel nat descriptor 20000
 tunnel enable 1

tunnel select 10
 description tunnel "IKEv2 tunnel"
 tunnel encapsulation ipsec
 ipsec tunnel 1

  # ポリシーID とセキュリティゲート番号を理解のためわざと異なる値にしている。
 # よく見る例だと 1 1 とかで揃えている
  ipsec sa policy 1 20 esp
  ipsec ike version 20 2
  ipsec ike keepalive log 20 off
  ipsec ike keepalive use 20 on rfc4306 10 3

  # 固定IP を指定する、公式サンプルだと ddns のホスト名だと思う
  ipsec ike local name 20 157.107.YYY.ZZZ ipv4-addr

  # PSK: 事前共有キー 適当な長さの文字列
  ipsec ike pre-shared-key 20 text VPN-123456789

  # 適当な文字列で OK、ただしタイプを fqdn にすること
  ipsec ike remote name 20 vpn fqdn
  ipsec ike mode-cfg address 20 1
 tunnel enable 10

ip filter 1001 reject 192.168.1.0/24 * * *
ip filter 1002 reject * 192.168.1.0/24 * * *
ip filter 1003 reject * * udp,tcp 135 *
ip filter 1004 reject * * udp,tcp * 135
ip filter 1005 reject * * udp,tcp netbios_ns-netbios_ssn *
ip filter 1006 reject * * udp,tcp * netbios_ns-netbios_ssn
ip filter 1007 reject * * udp,tcp 445 *
ip filter 1008 reject * * udp,tcp * 445
ip filter 1101 pass * * icmp * *
ip filter 1500 pass * 192.168.1.244 tcp * 5000
ip filter 1501 pass * 192.168.1.244 tcp * 5001
ip filter 1502 pass * 192.168.1.244 tcp * 6699
ip filter 1503 pass * 192.168.1.244 tcp * https
ip filter 1504 pass * 192.168.1.244 tcp * 1194

# 500, esp, 4500 を通す、tunnel 1 の ip tunnel secure filter in で使う
ip filter 1505 pass-log * 192.168.1.254 * * 500
ip filter 1506 pass-log * 192.168.1.254 esp
ip filter 1507 pass-log * 192.168.1.254 udp * 4500

ip filter 1997 reject * *
ip filter 1998 pass * * tcp * *
ip filter 1999 pass * * udp * *
ip filter 9999 pass * * * * *
ip filter 500000 restrict * * * * *
ip filter dynamic 3001 * * ftp
ip filter dynamic 3002 * * www
ip filter dynamic 3003 * * https
ip filter dynamic 3098 * * tcp
ip filter dynamic 3099 * * udp
nat descriptor type 20000 masquerade
nat descriptor address outer 20000 157.107.76.213
nat descriptor masquerade incoming 20000 reject 

# ここは NAS 関連の公開サービスなので不要なら削除
nat descriptor masquerade static 20000 1000 192.168.1.244 tcp  5000
nat descriptor masquerade static 20000 1001 192.168.1.244 tcp 5001
nat descriptor masquerade static 20000 1002 192.168.1.244 tcp 6690
nat descriptor masquerade static 20000 1003 192.168.1.244 tcp https
nat descriptor masquerade static 20000 1004 192.168.1.244 tcp 1194

# IKEv2 用の NAT
nat descriptor masquerade static 20000 2001 192.168.1.254 esp
nat descriptor masquerade static 20000 2002 192.168.1.254 udp 500
nat descriptor masquerade static 20000 2003 192.168.1.254 udp 4500

# わかりやすくするためあえて全然別の IP を VPN クライアントに払い出し
# つながってしまえば後は RTX がいい具合にやってくれる
# dhcp  で使っていない 192.168.1.1-192.168.1.10 とかでもいい
ipsec ike mode-cfg address pool 1 10.20.30.1-10.20.30.10/24

telnetd host lan1

dhcp service server
dhcp server rfc2131 compliant except remain-silent
dhcp scope 1 192.168.1.100-192.168.1.249/24

# 宅内の固定でアサインしたい機器
dhcp scope bind 1 192.168.1.100 01 34 cf f6 f5 93 62
dhcp scope bind 1 192.168.1.230 01 00 bb c1 c0 4f 20
dhcp scope bind 1 192.168.1.231 01 d0 c0 bf 87 9b 65
dhcp scope bind 1 192.168.1.232 00:17:88:b2:58:45
dhcp scope bind 1 192.168.1.233 ff 7d 7b c0 11 00 01 00 01 2d 41 c0 e2 9a d0 7d 7b c0 11
dhcp scope bind 1 192.168.1.240 01 c8 9e 43 a1 50 76
dhcp scope bind 1 192.168.1.241 01 50 91 e3 35 e5 fc
dhcp scope bind 1 192.168.1.242 01 50 91 e3 35 e6 20
dhcp scope bind 1 192.168.1.244 01 90 09 d0 4b 06 cd

# DNS に宅内の PiHole, RTX自身と 何処かのオープンDNS
dhcp scope option 1 dns=192.168.1.245,192.168.1.254,9.9.9.9
dns host lan1
dns service fallback on
dns cache max entry 1024
dns server dhcp lan2

# この 500000 はどこから出てくるのか未だになぞ
dns server select 500000 dhcp lan2 any .
dns private address spoof on
schedule at 1 startup * lua emfs:/v6plus_map_e.lua
schedule at 2 */* 05:43:21 * ntpdate ntp.nict.jp syslog
httpd host lan1 10.20.30.1-10.20.30.10
alarm entire off
sshd service on
sshd host lan1 10.20.30.1-10.20.30.10
sshd host key generate *
sftpd host lan1 10.20.30.1-10.20.30.10
statistics traffic on
statistics nat on

# 喘い明日
alias cc="clear log"
alias jj="show log|grep -i reje"
alias rr="show log reverse"
alias sa="show ipsec sa"

embedded file v6plus_map_e.lua <<EOF
UPD_SV = "https://v6update.asahi-net.or.jp/prefix"
USERNAME = "P74587912"
PASSWORD = "DKIQWFFC"
WAN_IF = "LAN1"

LOG_PTN = "Add%s+IPv6%s+prefix.+%(Lifetime%:%s+%d+%)%s+via%s+" .. WAN_IF .. "%s+by"
LOG_LEVEL = "info"
LOG_PFX = "[v6plus]"
FAIL_MSG = "Failed to notify IPv6 address to the update server. (remaining retry: %d time(s))"

function logger(msg)
rt.syslog(LOG_LEVEL, string.format("%s %s", LOG_PFX, msg))
end

local rtn, count, log, result
local req_t = {}
local res_t
req_t.url = string.format("%s?user=%s&pass=%s", UPD_SV, USERNAME, PASSWORD)
req_t.method = "GET"
while true do
rtn = rt.syslogwatch(LOG_PTN)
if rtn then
count = 3
while true do
res_t = rt.httprequest(req_t)
if res_t.rtn1 then
logger("Notified IPv6 address to the update server.")
if res_t.code == 200 then
result = "Succeeded"
else
result = "Failed"
end
log = string.format("%s to update IPv6 address. (code=%d, body=%s)", result, res_t.code, res_t.body)
logger(log)
break
end
count = count - 1
if count > 0 then
logger(string.format(FAIL_MSG, count))
rt.sleep(10)
else
logger("Failed to notify IPv6 address to the update server.")
break
end
end
end
end
EOF

これでアンドロイドからは疎通するようになった。iPhone からは何故かつながらないが、疲れたのでいったんこれで OK とする。

参考

リモートアクセスVPN(IKEv2)の設定手順 – 由緒正しい公式のガイド