前言

  • 本篇教程主要解决公网IPv4+IPv6双栈网络环境下,qBittorrent使用IPv6向Tracker汇报时漏汇报IPv4的问题。

  • 若无公网IPv4,则可直接忽略此问题

因为没有公网(可直接连接)的IPv4时,即使漏汇报IPv4也不会影响到上传和下载速度

方法一:

在qBittorent高级设置中设置总是向tracker汇报的ip

IP Address to report to trackers (requires restart):

在后面的选框中填入你的公网IPv4地址

适用场景

有固定公网IPv4的场景,比如:商宽、VPS、盒子等

在家宽动态公网IPv4的场景下不推荐直接使用,因为需要在IPv4发生变化时修改,也可以参照 方法二

方法二:

编写shell脚本定时自动检测并修改qBittorent高级设置中的汇报ip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash

qbittorrentIP=`cat /root/.config/qBittorrent/qBittorrent.conf | grep "Connection\InetAddress=" | awk -F'=' '{print $2}'`
publicIP=`wget -q4O- whatismyip.akamai.com`

if [ -z $qbittorrentIP ]
then
if [ -z `cat /root/.config/qBittorrent/qBittorrent.conf | grep "Connection\InetAddress="` ]
then
echo "Connection\InetAddress=$publicIP" >> /root/.config/qBittorrent/qBittorrent.conf
else
sed -i 's,Connection\InetAddress=,Connection\InetAddress=$publicIP,g' /root/.config/qBittorrent/qBittorrent.conf
fi
elif [ $qbittorrentIP != $publicIP ]
then
sed -i 's,Connection\InetAddress=$qbittorrentIP,Connection\InetAddress=$publicIP,g' /root/.config/qBittorrent/qBittorrent.conf
fi

使用crontab定时执行

1
*/10 * * * * /root/sh/qbittorrent_ip.sh

*/10 * * * *代表每10分钟执行检测一次

适用场景

注意:此方法只适用于Linux,需要的工具wgetsed(一般情况下系统已经自带)

相比于方法一,更适合在家宽动态公网IPv4的场景下使用

可能需要重启qbittorrent才能生效,这里的脚本没有重启qbittorent的代码,如有需要可自行补充

方法三:

修改hosts

通过修改Hosts文件,使qBittorrent只使用IPv4进行汇报,这样就不会出现漏汇报IPv4的情况

tips:若站点使用的是Cloudflare CDN,还可以搭配CloudflareSpeedTest使用,选出连通性最好的ip

Linux(需要su)

此处也可用vivim等代替nano修改hosts文件

1
nano /etc/hosts

添加Tracker IPv4 hosts

1
2
1.1.1.1 example.com
::1 example.com

注意:Linux在添加Tracker IPv4 hosts之后,还需添加::1的hosts,这样才能保证只使用IPv4向Tracker汇报

Windows(需以管理员身份运行)

1
notepad.exe %systemroot%\System32\Drivers\etc\hosts

添加Tracker IPv4 hosts

1
1.1.1.1 example.com

Windows只需要添加Tracker IPv4 hosts,无需再添加::1

适用场景

相比于前面的方法,更适合在家宽动态公网IPv4的场景下使用,也无需担心脚本失效、或是需要重启的问题

缺点:需要每个站点注意添加Hosts,不过一劳永逸^_^

方法四:

禁用IPv6(不推荐)