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)の設定手順 – 由緒正しい公式のガイド