
RT,
见之前讨论的帖子。v2ex.com/t/800905
现在遇到新的情况,因为在光猫上无法用 wg-quick,有很多命令光猫上没有,所以看了下 wg-quick 脚本,用原始命令直接敲
insmod /lib/modules/4.4.197/kernel/drivers/net/tun.ko LOG_LEVEL=debug wireguard-go wg0 #set ip ip -4 address add 10.0.1.88 dev wg0 #up wg0 ip link set mtu 1280 up dev wg0 #add route, ONLY ALLOW .1 through wg, just for test. ip -4 route add 10.0.1.1 dev wg0 #set conf wg setconf wg0 wg0.conf [root@x6 /mnt/jffs2/hw] # 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 10 0 0 ppp257 10.0.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 wg0 #ping test on x6 [root@x6 /mnt/jffs2/hw] # ping 10.0.1.1 PING 10.0.1.1 (10.0.1.1): 56 data bytes 64 bytes from 10.0.1.1: seq=0 ttl=64 time=19.197 ms 64 bytes from 10.0.1.1: seq=1 ttl=64 time=20.565 ms #ping on pc C:\Users\xxx>ping 10.0.1.1 Pinging 10.0.1.1 with 32 bytes of data: not use 系统自带的busybox, all binary is compiled statically
/sbin/insmod /lib/modules/4.4.197/kernel/drivers/net/tun.ko /mnt/jffs2/plug/app/bin/wireguard-go wg0 > /dev/null 2>&1 & sleep 3 #/mnt/jffs2/plug/app/busybox/sbin/ip link set mtu 1420 up dev wg0 /mnt/jffs2/plug/app/busybox/sbin/ip -4 address add 10.0.1.88 dev wg0 /mnt/jffs2/plug/app/busybox/sbin/ip link set mtu 1420 up dev wg0 /mnt/jffs2/plug/app/busybox/sbin/ip -4 route add 10.0.1.1/32 dev wg0 /mnt/jffs2/plug/app/bin/wg setconf wg0 /mnt/jffs2/hw/wg0.conf 查了下 iptables 网络层和链路层 forward链,出站,貌似没有路有决策? dXBsb2FkLndpa2ltZWRpYS5vcmcvd2lraXBlZGlhL2NvbW1vbnMvMy8zNy9OZXRmaWx0ZXItcGFja2V0LWZsb3cuc3Zn
花了一个下午的时间,各种排查,终于解决了。
#查看 ppp 的iptables策略,发现有下面一行,虽然没看懂,
[root@x6 /mnt/jffs2/hw] # iptables-save | grep ppp -A POST_WANNAT -o ppp257 -j CONENA #给wg0 加一条同样的策略
iptables -t nat -I POST_WANNAT -o wg0 -j CONENAT 走了好多弯路,在 input output postrouting prerouing 打转 。
^C C:\Users\xxx>ping 10.0.1.1 -t Pinging 10.0.1.1 with 32 bytes of data: Reply from 10.0.1.1: bytes=32 time=19ms TTL=63 Reply from 10.0.1.1: bytes=32 time=19ms TTL=63 Ping statistics for 10.0.1.1: Packets: Sent = 2, Received = 2, Lost = 0 (0% l Approximate round trip times in milli-seconds: Minimum = 19ms, Maximum = 19ms, Average = 19ms 虚拟内存占用有点高, go 语言不适合 arm
PPID USER STAT VSZ %VSZ CPU %CPU COMMAND 2 0 SW 0 0.0 0 0.2 [kworker/0:3] 4696 0 R 0.2 1 0.0 top 1 srv_bbsp S 5.0 1 0.0 bbsp 1 cfg_oam S 2.8 1 0.0 oam 2 0 SW 0 0.0 0 0.0 [eth_manager] 2 0 SW 0 0.0 0 0.0 [pcie_thread] 1 0 S 778m158.1 0 0.0 /mnt/jffs2/plug/app/bin/wireguard-go wg0 对比下 op 上的策略,只需要加2条策略
iptables -I A FORWARD -o wg0 -j ACCEPT iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE 全配置,MASQUERADE 策略不能 用 I 插入 到最前面 ,要用 A 追加,此是一坑 。 wg.sh 代理 所有流量 配置如下:
# wireguard-go usermode /sbin/insmod /lib/modules/4.4.197/kernel/drivers/net/tun.ko sleep 2 /mnt/jffs2/plug/app/bin/wireguard-go wg0 2>/dev/null & sleep 3 /mnt/jffs2/plug/app/busybox/sbin/ip link set mtu 1420 up dev wg0 sleep 1 /mnt/jffs2/plug/app/busybox/sbin/ip -4 address add 10.0.1.88 dev wg0 sleep 1 /mnt/jffs2/plug/app/busybox/sbin/ip -4 route add 10.0.1.1/32 dev wg0 /mnt/jffs2/plug/app/busybox/sbin/ip -4 route add 0.0.0.0/0 dev wg0 sleep 1 /mnt/jffs2/plug/app/bin/wg setconf wg0 /mnt/jffs2/hw/wg0.conf iptables -t nat -A POST_WANNAT -o wg0 -j CONENAT iptables -t nat -A POSTROUTING -o ppp257 -j MASQUERADE iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE wg0.conf
[Interface] PrivateKey = *** [Peer] PublicKey = *** Endpoint = ***:port PersistentKeepalive = 25 AllowedIPs = 10.0.1.1/32 AllowedIPs = 0.0.0.0/0 1 Qetesh 2021-09-11 13:14:54 +08:00 via iPhone pc 的网段对方没写策略吧?或者加 nat |
2 guanyin9cn OP @Qetesh 试了下,没成功。我也感觉是 iptables 问题。 |
3 Qetesh 2021-09-11 16:54:06 +08:00 via iPhone traceroute 、tcpdump 抓包排查吧 |
4 guanyin9cn OP @Qetesh 已解决 |
5 Kinnice 2021-09-11 20:12:23 +08:00 via Android 这个可以和 tr069 联动了 |