На версии 3.8.2 эта команда не работает. Поэтому был модифицирован скрипт /opt/etc/ndm/ifstatechanged.d/000-fix-Wireguard2.sh
#!/bin/sh
[ "$1" == "hook" ] || exit 0
[ "$change" == "link" ] || exit 0
[ "$id" == "Wireguard2" ] || exit 0
ip6t() {
if ! ip6tables -C "$@" &>/dev/null; then
ip6tables -A "$@"
fi
}
case ${id}-${change}-${connected}-${link}-${up} in
${id}-link-yes-up-up)
cat << EOF >/tmp/fix-${id}.conf
[Interface]
PrivateKey = MMVM2wVNQqUyug1cBY=
[Peer]
PublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = engage.cloudflareclient.com:2408
EOF
ip -6 addr add fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d/128 dev nwg2
wg setconf nwg2 /tmp/fix-${id}.conf
ip6t POSTROUTING -t nat -o nwg2 -j MASQUERADE
;;
esac
exit 0
Сам тест:
wg show nwg2
ifconfig nwg2
ip -6 rule add from all lookup 123 priority 1123
ip -6 route add table 123 2a03:1b20:1:f410::ff1 dev nwg2
ip -6 rule
ip -6 route show table 123
traceroute6 2a03:1b20:1:f410::ff1
Результат:
~ # uname -a
Linux ZyAvenger 4.9-ndm-5 #0 SMP Tue Jun 21 16:39:31 2022 mips GNU/Linux
~ # wg show nwg2
interface: nwg2
public key: JL+TtFAHd2heTNrACYj8tlkn9f4rrZi7auvuQRBkajY=
private key: (hidden)
listening port: 49203
peer: bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=
endpoint: [2606:4700:d0::a29f:c001]:2408
allowed ips: 0.0.0.0/0, ::/0
latest handshake: 1 minute, 33 seconds ago
transfer: 15.29 KiB received, 6.19 KiB sent
~ # ifconfig nwg2
nwg2 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:172.16.0.2 P-t-P:172.16.0.2 Mask:255.255.255.255
inet6 addr: fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d/128 Scope:Global
UP POINTOPOINT RUNNING NOARP MTU:1280 Metric:1
RX packets:52643 errors:0 dropped:53 overruns:0 frame:0
TX packets:63283 errors:3 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:50
RX bytes:14968865 (14.2 MiB) TX bytes:8037372 (7.6 MiB)
~ # ip -6 rule
0: from all lookup local
233: from all fwmark 0x2333 lookup 233
1123: from all lookup 123
1778: from all fwmark 0xd1001 lookup 1001
32766: from all lookup main
~ # ip -6 route show table 123
2a03:1b20:1:f410::ff1 dev nwg2 metric 1024 pref medium
~ # traceroute6 2a03:1b20:1:f410::ff1
traceroute to 2a03:1b20:1:f410::ff1 (2a03:1b20:1:f410::ff1) from fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d, port 33434, from port 45415, 30 hops max, 60 bytes packets
1 fd01:5ca1:ab1e::1 (fd01:5ca1:ab1e::1) 10.845 ms 10.961 ms 10.997 ms
2 2400:cb00:87:1000::1 (2400:cb00:87:1000::1) 11.906 ms 17.869 ms 20.842 ms
3 mow-b4-link.ip.twelve99.net (2001:2000:3080:539::1) 11.994 ms 11.797 ms 11.299 ms
4 mow-b8-v6.ip.twelve99.net (2001:2034:0:220::1) 11.474 ms 11.974 ms 12.476 ms
5 kbn-bb2-v6.ip.twelve99.net (2001:2034:1:78::1) 40.321 ms 41.409 ms 72.470 ms
^C22% completed...
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
avn
Добрый день!
Может кому-то пригодится выборочная маршрутизация через Wireguard по ipv6.
На версии 3.7.4 ipv6 адрес на интерфейсе nwg можно было задать командой:
interface Wireguard2 ipv6 address fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d
На версии 3.8.2 эта команда не работает. Поэтому был модифицирован скрипт /opt/etc/ndm/ifstatechanged.d/000-fix-Wireguard2.sh
#!/bin/sh [ "$1" == "hook" ] || exit 0 [ "$change" == "link" ] || exit 0 [ "$id" == "Wireguard2" ] || exit 0 ip6t() { if ! ip6tables -C "$@" &>/dev/null; then ip6tables -A "$@" fi } case ${id}-${change}-${connected}-${link}-${up} in ${id}-link-yes-up-up) cat << EOF >/tmp/fix-${id}.conf [Interface] PrivateKey = MMVM2wVNQqUyug1cBY= [Peer] PublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo= AllowedIPs = 0.0.0.0/0, ::/0 Endpoint = engage.cloudflareclient.com:2408 EOF ip -6 addr add fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d/128 dev nwg2 wg setconf nwg2 /tmp/fix-${id}.conf ip6t POSTROUTING -t nat -o nwg2 -j MASQUERADE ;; esac exit 0
Сам тест:
wg show nwg2 ifconfig nwg2 ip -6 rule add from all lookup 123 priority 1123 ip -6 route add table 123 2a03:1b20:1:f410::ff1 dev nwg2 ip -6 rule ip -6 route show table 123 traceroute6 2a03:1b20:1:f410::ff1
Результат:
~ # uname -a Linux ZyAvenger 4.9-ndm-5 #0 SMP Tue Jun 21 16:39:31 2022 mips GNU/Linux ~ # wg show nwg2 interface: nwg2 public key: JL+TtFAHd2heTNrACYj8tlkn9f4rrZi7auvuQRBkajY= private key: (hidden) listening port: 49203 peer: bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo= endpoint: [2606:4700:d0::a29f:c001]:2408 allowed ips: 0.0.0.0/0, ::/0 latest handshake: 1 minute, 33 seconds ago transfer: 15.29 KiB received, 6.19 KiB sent ~ # ifconfig nwg2 nwg2 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:172.16.0.2 P-t-P:172.16.0.2 Mask:255.255.255.255 inet6 addr: fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d/128 Scope:Global UP POINTOPOINT RUNNING NOARP MTU:1280 Metric:1 RX packets:52643 errors:0 dropped:53 overruns:0 frame:0 TX packets:63283 errors:3 dropped:1 overruns:0 carrier:0 collisions:0 txqueuelen:50 RX bytes:14968865 (14.2 MiB) TX bytes:8037372 (7.6 MiB) ~ # ip -6 rule 0: from all lookup local 233: from all fwmark 0x2333 lookup 233 1123: from all lookup 123 1778: from all fwmark 0xd1001 lookup 1001 32766: from all lookup main ~ # ip -6 route show table 123 2a03:1b20:1:f410::ff1 dev nwg2 metric 1024 pref medium ~ # traceroute6 2a03:1b20:1:f410::ff1 traceroute to 2a03:1b20:1:f410::ff1 (2a03:1b20:1:f410::ff1) from fd01:5ca1:ab1e:891f:c4fc:4a2e:e64d:503d, port 33434, from port 45415, 30 hops max, 60 bytes packets 1 fd01:5ca1:ab1e::1 (fd01:5ca1:ab1e::1) 10.845 ms 10.961 ms 10.997 ms 2 2400:cb00:87:1000::1 (2400:cb00:87:1000::1) 11.906 ms 17.869 ms 20.842 ms 3 mow-b4-link.ip.twelve99.net (2001:2000:3080:539::1) 11.994 ms 11.797 ms 11.299 ms 4 mow-b8-v6.ip.twelve99.net (2001:2034:0:220::1) 11.474 ms 11.974 ms 12.476 ms 5 kbn-bb2-v6.ip.twelve99.net (2001:2034:1:78::1) 40.321 ms 41.409 ms 72.470 ms ^C22% completed...
Link to comment
Share on other sites
47 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.