使用支持Netflix的VPS,解锁其他VPS,使其他VPS也支持Netflix

理解了,其实很简单。 1、VPS A:支持Netflix;VPS B:不支持Netflix 2、原理是:VPS A用Tinyproxy架设https代理,然后在VPS B用redsocks转成透明代理然后转发

架设Tinyproxy Https代理

其实很简单,直接apt-get install tinyproxy就可以了。设置上我也几乎没有修改,仅仅是添加了一个Allow语句,给VPS B的IP放行,否则是无法使用的。而且这样默认也屏蔽了其他IP的访问,避免了变成冤大头。 最后的配置如下:

User tinyproxy Group tinyproxy Port 8888 Timeout 600 DefaultErrorFile "/usr/share/tinyproxy/default.html" StatFile "/usr/share/tinyproxy/stats.html" Logfile "/var/log/tinyproxy/tinyproxy.log" LogLevel Info PidFile "/run/tinyproxy/tinyproxy.pid" MaxClients 100 MinSpareServers 5 MaxSpareServers 20 StartServers 10 MaxRequestsPerChild 0 Allow 127.0.0.1 Allow YOUR_VPS_B_IP ViaProxyName "tinyproxy" ConnectPort 443 ConnectPort 563

架设Redsocks代理

也是直接apt-get install redsocks,配置中只需要设置好https代理的IP和端口就行,记得https代理的类型是填http-connect。

base { // debug: connection progress & client list on SIGUSR1 log_debug = off; // info: start and end of client session log_info = on; /* possible `log' values are: * stderr * "file:/path/to/file" * syslog:FACILITY facility is any of "daemon", "local0"..."local7" */ log = "syslog:daemon"; // detach from console daemon = on; /* Change uid, gid and root directory, these options require root * privilegies on startup. * Note, your chroot may requre /etc/localtime if you write log to syslog. * Log is opened before chroot & uid changing. */ user = redsocks; group = redsocks; // chroot = "/var/chroot"; /* possible `redirector' values are: * iptables - for Linux * ipf - for FreeBSD * pf - for OpenBSD * generic - some generic redirector that MAY work */ redirector = iptables; } redsocks { /* `local_ip' defaults to 127.0.0.1 for security reasons, * use 0.0.0.0 if you want to listen on every interface. * `local_*' are used as port to redirect to. */ local_ip = 127.0.0.1; local_port = 12345; // `ip' and `port' are IP and tcp-port of proxy-server // You can also use hostname instead of IP, only one (random) // address of multihomed host will be used. ip = YOUR_VPS_A_IP; port = 8888; // known types: socks4, socks5, http-connect, http-relay type = http-connect; // login = "foobar"; // password = "baz"; }

然后配置iptables,先建立一个REDSOCKS链:

iptables -t nat -N REDSOCKS

这里有两套思路进行转发,一套是找出Netflix所有的IP地址,然后添加到REDSOCKS链,例如:

iptables -t nat -A OUTPUT -d 198.38.0.0/16 -j REDSOCKS

但问题是Netflix使用了akamai的CDN主机,IP地址范围是在太大了,我已经把Netflix整个AS的地址都添加了也还是会提示在使用proxy。

干脆暴力点,直接把所有https流量都添加进去:

iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDSOCKS

最后,转发到redsocks的透明代理端口:

iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 12345

最后记得用iptables-persistent之类的工具保存一下iptables规则,这样不论是从VPS B本机访问,还是透过VPS B上的代理,最后Netflix的HTTPS流量都会通过VPS A访问,而Netflix是全Https的,所以http部分我们不需要关心。

更小的IP范围

全部转发可能还是太暴力了,简单一点的做法是转发Netflix所有的IP和AWS所有的IP(因为当前Netflix有很多服务是架设在AWS上的)。

Netflix的IP可以在这里查到,而AWS的IP可以在这里看到,然后把这些IP范围分别添加到两个IPSET中,我把它们分别命名为aws和netflix。

ipset create aws hash:net ipset create netflix hash:net

怎么转成命令我就懒得写了,这里有现成的脚本。 Update:生成bash命令的Python脚本在这里,自己去看吧。

然后,把这两个IPSET里IP的443端口目标流量全部转发到REDSOCKS的透明代理上。

iptables -t nat -A PREROUTING -p tcp --dport 443 -m set --match-set aws dst -j REDIRECT --to-ports 12345 iptables -t nat -A PREROUTING -p tcp --dport 443 -m set --match-set netflix dst -j REDIRECT --to-ports 12345 iptables -t nat -A OUTPUT -p tcp --dport 443 -m set --match-set aws dst -j REDIRECT --to-ports 12345 iptables -t nat -A OUTPUT -p tcp --dport 443 -m set --match-set netflix dst -j REDIRECT --to-ports 12345

可能的问题: 你的代理主机本身就是AWS主机,这个就比较尴尬了,自己添加一个排除规则吧,其实AWS的主机就算能看Netflix也是暂时的,早晚被封。 重启后ipset丢失,这是个问题,我目前也不知道有什么更优雅的方式来解决,简单点可以在启动项里重写ipset。

保存这些规则

ipset save > /etc/ipset.conf iptables-save > /etc/iptables.conf

然后在/etc/rc.local里写入:

ipset restore

转自:https://lifetyper.com/posts/setup_netflix_unblocker_for_vps.html

推荐站内搜索:便宜虚拟主机、站长ip、香港vps主机租用、免费域名空间申请、美国域名注册、移动代理ip、双线双ip、shopex空间、韩国cn2服务器、动态ip服务器、