dd-wrtでOpenVPN (9)
sshログインができず調べていくと297byteまでしか通らないことがわかり、試行錯誤して変更。1374 bytesまでは通るようになった。ssh loginもできる。
サーバ(dd-wrt)側変更点
項目 | 値 |
---|---|
Advanced Option | Enable |
Compression | Yes |
Redirect default Gateway | Disable |
Allow Client to Client | Disable |
Allow duplicate Clients | Disable |
Tunnel MTU setting | 1500 |
Tunnel UDP Fragment | (blank) |
Tunnel UDP MSS-Fix | Disable |
Use ECDH instead of DH.PEM | Disable |
クライアント側変更点
項目 | 値 |
---|---|
Use LZO data compression | y |
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 Gateway | Disable |
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)
テスト
UbuntuのGUIでOpenVPNを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
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)
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)
Services > VPNの設定でOpenVPNの設定を入れていく。
項目 | 値 |
---|---|
OpenVPN | Enable |
CVE-2019-14899 Mitigation | Enable |
Start Type | WAN Up |
Inbound Firewall on TUN | (no) |
Configure as | GUI(server) |
Server mode | Router(TUN) |
Network | 10.10.1.0 |
Netmask | 255.255.255.0 |
Port | 1194 |
Tunnel Protocol | udp |
Encryption Cipher | AES-256-CBC |
Has Algorithm | SHA256 |
First Data Cipher | AES-256-CBC |
Second Data Cipher | AES-256-CBC |
Third Data Cipher | AES-256-CBC |
Advanced Option | Disable |
Public Server Key | (server3.key) |
DH PEM | (dh2048.pem) |
Additional Config | |
TLS Key Choice | TLS 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)
項目 | 値 |
---|---|
Gateway | dd-wrtのIPアドレス |
Authentication Type | Certificates (TLS) |
User Certificate | client1.crt |
CA Certificate | ca.crt |
Private Key | client1.key |
Private Key Password |
項目 | 値 |
---|---|
Use LZO data compression | y |
Cipher | AES-256-CBC |
Cipher | AES-256-CBC |
Use custom size of cipher key | 256 |
HMAC Authentication | SHA-256 |
dd-wrtでOpenVPN (5)
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だけは禁止しておく)
iptables -F INPUT
iptables -I INPUT 1 -d 192.168.129.0/24 -i eth2 -p tcp --dport 23 -j logdrop
その他のセキュリティとしてFORWRDチェインに追加する
(つづく)