dd-wrtでOpenVPN (9)

MTU
sshログインができず調べていくと297byteまでしか通らないことがわかり、試行錯誤して変更。1374 bytesまでは通るようになった。ssh loginもできる。

サーバ(dd-wrt)側変更点
項目
Advanced OptionEnable
CompressionYes
Redirect default GatewayDisable
Allow Client to ClientDisable
Allow duplicate ClientsDisable
Tunnel MTU setting1500
Tunnel UDP Fragment(blank)
Tunnel UDP MSS-FixDisable
Use ECDH instead of DH.PEMDisable

クライアント側変更点
項目
Use LZO data compressiony
Use custom tunnel maximum Transmission Unit(MTU)1500

これで1374byte (1402byte)までのパケットは通過するが、1375byte (1403byte)以上はロストする。ファイル転送で失敗しそうな。
$ ping -s 1375 10.10.1.1
PING 10.10.1.1 (10.10.1.1) 1375(1403) bytes of data.
^C
--- 10.10.1.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

$ ping -s 1374 10.10.1.1
PING 10.10.1.1 (10.10.1.1) 1374(1402) bytes of data.
1382 bytes from 10.10.1.1: icmp_seq=1 ttl=64 time=2.78 ms
1382 bytes from 10.10.1.1: icmp_seq=2 ttl=64 time=2.27 ms
^C
--- 10.10.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 2.275/2.530/2.785/0.255 ms
(つづく)

dd-wrtでOpenVPN (8)

ルーティング情報
用途としてLAN内にリモートアクセスすることだけを考えていて、デフォルトルートを入れたくない。

dd-wrtのLAN側ネットワークへの経路をプッシュする
OpenVPN - Advanced Options [x] Enable
Additional Config:
push "route 192.168.131.0 255.255.255.0 vpn_gateway"
項目
Redirect default GatewayDisable
Ubuntu側クライアントを切断して、再接続する。
dd-wrt上のログ:
... 20210227 23:22:10 client1/192.168.129.58:54979 PUSH: Received control message: 'PUSH_REQUEST'
20210227 23:22:10 client1/192.168.129.58:54979 SENT CONTROL [client1]: 'PUSH_REPLY route 192.168.131.0 255.255.255.0 vpn_gateway route-gateway 10.10.1.1 topology subnet ping 10 ping-restart 120 ifconfig 10.10.1.2 255.255.255.0 peer-id 0' (status=1)
クライアント側のルーティングテーブル
kenhrd@ubuntu:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.10.1.1 0.0.0.0 UG 50 0 0 tun0
default 192.168.129.254 0.0.0.0 UG 100 0 0 ens33
10.10.1.0 * 255.255.255.0 U 50 0 0 tun0
link-local * 255.255.0.0 U 1000 0 0 ens33
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
192.168.129.0 * 255.255.255.0 U 100 0 0 ens33
192.168.131.0 10.10.1.1 255.255.255.0 UG 50 0 0 tun0
pushした経路が乗るのはいいがdefaultが出るのはおかしい ... クライアント側の設定だった(cf https://askubuntu.com/questions/254031/change-openvpn-clients-default-route)
You can fix that behaviour by editing the VPN connection and on the IPv4 settings tab select the 'Routes...' button. You'll see an option called 'Use this connection only for resources on this network'. Make sure that's enabled and then restart your VPN. That should sort you out.
設定したところでUbuntuのルーティング
kenhrd@ubuntu:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.129.254 0.0.0.0 UG 100 0 0 ens33
10.10.1.0 0.0.0.0 255.255.255.0 U 50 0 0 tun0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.129.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.131.0 10.10.1.1 255.255.255.0 UG 50 0 0 tun0

(つづく)

dd-wrtでOpenVPN (7)

テスト

UbuntuGUIOpenVPNをONにするとつながった。

クライアント側

$ route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 0.0.0.0 0.0.0.0 U 50 0 0 tun0

0.0.0.0 192.168.129.254 0.0.0.0 UG 100 0 0 ens33

10.10.1.0 0.0.0.0 255.255.255.0 U 50 0 0 tun0

10.147.19.0 0.0.0.0 255.255.255.0 U 0 0 0 zt7nnolz6z

169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33

192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

192.168.129.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

$ ifconfig tun0

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

inet addr:10.10.1.2 P-t-P:10.10.1.2 Mask:255.255.255.0

inet6 addr: fe80::61da:e5df:63a4:eb17/64 Scope:Link

UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1

RX packets:781 errors:0 dropped:0 overruns:0 frame:0

TX packets:815 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:682887 (682.8 KB) TX bytes:56848 (56.8 KB)

$ ping 10.10.1.1

PING 10.10.1.1 (10.10.1.1) 56(84) bytes of data.

64 bytes from 10.10.1.1: icmp_seq=1 ttl=64 time=5.56 ms

64 bytes from 10.10.1.1: icmp_seq=2 ttl=64 time=4.60 ms

64 bytes from 10.10.1.1: icmp_seq=3 ttl=64 time=2.87 ms

^C

--- 10.10.1.1 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2004ms

rtt min/avg/max/mdev = 2.879/4.348/5.562/1.111 ms

dd-wrt

root@DD-WRT:~# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.129.254 0.0.0.0 UG 0 0 0 eth2

10.10.1.0 0.0.0.0 255.255.255.0 U 0 0 0 tun2

127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo

192.168.129.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2

192.168.131.0 0.0.0.0 255.255.255.0 U 0 0 0 br0

root@DD-WRT:~# ifconfig tun2

tun2 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

inet addr:10.10.1.1 P-t-P:10.10.1.1 Mask:255.255.255.0

UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1

RX packets:743 errors:0 dropped:0 overruns:0 frame:0

TX packets:749 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:500

RX bytes:52757 (51.5 KiB) TX bytes:680260 (664.3 KiB)

root@DD-WRT:~# ping 10.10.1.2

PING 10.10.1.2 (10.10.1.2): 56 data bytes

64 bytes from 10.10.1.2: seq=0 ttl=64 time=1.924 ms

64 bytes from 10.10.1.2: seq=1 ttl=64 time=3.034 ms

^C

--- 10.10.1.2 ping statistics ---

2 packets transmitted, 2 packets received, 0% packet loss

round-trip min/avg/max = 1.924/2.479/3.034 ms

これで完成と喜んではいけない。テストしていくとまだ不具合がある。

(つづく)

dd-wrtでOpenVPN (6)

サーバ側(dd-wrt)の設定
Services > VPNの設定でOpenVPNの設定を入れていく。
項目
OpenVPNEnable
CVE-2019-14899 MitigationEnable
Start TypeWAN Up
Inbound Firewall on TUN(no)
Configure asGUI(server)
Server modeRouter(TUN)
Network10.10.1.0
Netmask255.255.255.0
Port1194
Tunnel Protocoludp
Encryption CipherAES-256-CBC
Has AlgorithmSHA256
First Data CipherAES-256-CBC
Second Data CipherAES-256-CBC
Third Data CipherAES-256-CBC
Advanced OptionDisable
Public Server Key(server3.key)
DH PEM(dh2048.pem)
Additional Config
TLS Key ChoiceTLS Auth
TLS Key
Certificate Revoke List

クライアント側の設定(ubuntu)
参考:https://qiita.com/noraworld/items/05658055446c41482cce
$ sudo apt-get -y install network-manager-openvpn-gnome

GUIで設定できる。(設定> Network > (+) VPN)
項目
Gatewaydd-wrtIPアドレス
Authentication TypeCertificates (TLS)
User Certificateclient1.crt
CA Certificateca.crt
Private Keyclient1.key
Private Key Password
Advanced項目(変更した項目)
項目
Use LZO data compressiony
CipherAES-256-CBC
CipherAES-256-CBC
Use custom size of cipher key256
HMAC AuthenticationSHA-256
(つづく)

dd-wrtでOpenVPN (5)

まず証明書と鍵を作成する。dd-wrt上では作業できない(しにくい)ので別マシン(VMPlayer上)のUbuntuを使う。 参考 https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1157344 https://qiita.com/MoriKen/items/50d226e8c6395487c0a6 簡易認証局を使うのでパッケージをインストール # apt-get install easy-rsa # make-cadir /tmp/openvpn # cd /tmp/openvpn # vi ./vars # source ./vars varsの内容としてCOUNTRY, PROVINCE, CITY, ORG, EMAIL, OUを自分に合わせた値にする。 認証局証明書・認証鍵を作成 # ./pkitool --initca ca.crtとca.keyができる サーバ関連 DHパラメータ # ./build-dh dh2048.pemができる VPNサーバ証明書・認証鍵作成 # ./pkitool --server server3 server3.crt, server3.csr, server3.keyができる クライアント関連 クライアント証明書・認証鍵作成 # source ./vars # ./pkitool client1 cleint1,.crt, client1.csr, client1.keyができる 後はeasy-rsaはいらない、と書いてある記事も見つかるが、維持しておかないと証明書失効リスト(CRL)が作れない。それかあらかじめ作っておく。 (つづく)

dd-wrtでOpenVPN (4)

LANセグメントの追加拡張はMR3020でやったのですんなり

https://yellow.ap.teacup.com/applet/kentaro/202102/archive?b=5

...のはずだったが上流側からのpingが通らず、半日はまる。調べていくとClient Mode / Router Modeでは(勝手に)iptablesの設定が入って、WiFiインタフェース側からの接続が禁止されている。

Chain INPUT (policy ACCEPT 417 packets, 33609 bytes)

num pkts bytes target prot opt in out source destination

1 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080

2 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80

3 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443

4 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:69

5 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22

6 0 0 DROP tcp -- eth2 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:23

Firewallコマンドで立ち上がり時に設定変更 (一応telnetだけは禁止しておく)

Firewall

iptables -F INPUT

iptables -I INPUT 1 -d 192.168.129.0/24 -i eth2 -p tcp --dport 23 -j logdrop

その他のセキュリティとしてFORWRDチェインに追加する

(つづく)

dd-wrtでOpenVPN (3)

WZR-600DHP2を分解する。下記を見て分解....ツメを折らないように気をつけろと書いてあったが結局折ってしまった。 https://openwrt.org/toh/buffalo/wzr-600dhp2 https://yuuya0x.at.webry.info/201309/article_1.html JTAGにシリアル接続する。 別件で用意してあったFT231X (https://akizukidenshi.com/catalog/g/gK-06894/)を使ってTeratermから接続。 WZR-600DHP2をブートしてしばらくしてctrl-Cを待つ画面でctrl-Cをたたくと、http://192.168.1.1/でmini webが使える。 参考: https://openwrt.org/docs/techref/bootloader/cfe https://yuuya0x.at.webry.info/201309/article_1.html dd-wrtファームを流し込む CFE mini Webで Restore default NVRAM values Firmware Fileとしてhttps://download1.dd-wrt.com/dd-wrtv2/downloads/betas/2021/01-31-2021-r45632/buffalo_wzr-600dhp2/buffalo-wzr-600dhp2-webflash.bin をupload factory-to-dd-wrt.binを選んだらvalidation errorになった。追及せず上のファイルでdd-wrt化した。 あとはClient modeでおうちLANのセグメント追加をして、そこにOpenVPNを動かすことにする。 (つづく)