极路由壹S折腾笔记-shadowsocks篇

IT资讯
IT资讯
IT资讯
1168
文章
239
评论
2016-02-1811:17:411 4,157 10577字

这篇教程有些一笔带过看不明白的可以先过一遍上一篇(http://www.gaofumei.net/network/304.html),这次换用shadowsocks不是因为goagent不好用,之前部署的goagent的工 作状态一直很好,换用shadowsocks一是因为之前刷的潘多拉固件搞不上去IPv6,需要重新编译一个Openwrt,所以纯属折腾一下,二是因为 手头有个香港的VPS速度很好,除了youtube速度没有goagent快之外,其他似乎都要快些,主要是shadowsocks现在已经成规模了,免 费的账号很多,也有很多在卖SS的账号。

已实现的功能

防DNS污染
特定网站自动穿墙
局域网设备IPv6支持
双(多)拨网速叠加
QOS流量控制
过滤联盟和部分视频网站广告
DDNS以及网站搭建

关于Openwrt的编译流程可以参考这篇极路由编译OpenWRT教程,由于我们编译的是trunk版,它的更新速度很快所以有关内核的东西如果编译的时候不选择好的话,后面可能会无法安装,即使是使用opkg install xxx --force-depends强制安装,也会出现很多问题(血的教训),所以这里着重说一下make menuconfig的部分

极路由壹S折腾笔记-shadowsocks篇

Openwrt的编译make menuconfig部分

Target System(Ralink RT288x/RT3xxx)
Subtarget(MT7620a based boards)

Base system -> block-mount
Base system -> dnsmasq-full

Libraries -> libmnl (ipset依赖)
Libraries -> libpcre (nginx依赖)

LuCI -> 1. Collections -> luci
LuCI -> 3. Applications -> luci-app-commands
LuCI -> 3. Applications -> luci-app-ddns
LuCI -> 3. Applications -> luci-app-firewall
LuCI -> 3. Applications -> luci-app-multiwan
LuCI -> 3. Applications -> luci-app-ntpc
LuCI -> 3. Applications -> luci-app-qos-emong (QOS流量控制 可设置单IP限速)
LuCI -> 3. Applications -> luci-app-samba
LuCI -> 3. Applications -> luci-app-upnp
LuCI -> 3. Applications -> luci-app-wol
LuCI -> 4. Themes -> luci-theme-bootstrap
LuCI -> 4. Themes -> luci-theme-openwrt
LuCI -> 5. Translations -> luci-i18n-chinese
LuCI -> 6. Protocols -> luci-proto-ipv6

Kernel modules -> Filesystems -> kmod-fs-ext4
Kernel modules -> Filesystems -> kmod-fs-nfs
Kernel modules -> Filesystems -> kmod-fs-nfs-common
Kernel modules -> Filesystems -> kmod-fs-ntfs
Kernel modules -> Filesystems -> kmod-fs-vfat
Kernel modules -> Native Language Support -> kmod-nls-cp437
Kernel modules -> Native Language Support -> kmod-nls-iso8859-1
Kernel modules -> Native Language Support -> kmod-nls-utf8
Kernel modules -> Netfilter Extensions -> kmod-ipt-ipset (dnsmasq IPSET 支持)
Kernel modules -> Netfilter Extensions -> kmod-nfnetlink (kmod-ipt-ipset依赖)
Kernel modules -> Network Devices -> kmod-macvlan (虚拟WAN口多拨)
Kernel modules -> Network Devices -> kmod-sched (QOS依赖)
Kernel modules -> Other modules -> kmod-mmc
Kernel modules -> Other modules -> kmod-sdhci
Kernel modules -> Other modules -> kmod-sdhci-mt7620

Network -> Firewall -> iptables -> iptables-mod-nat-extra (QOS & shadowsocks依赖)
Network -> Firewall -> iptables -> iptables-mod-iprange (QOS依赖)
Network -> Web Servers/Proxies -> nginx (Web服务器和去视频广告做反向代理)
Network -> Web Servers/Proxies -> pdnsd (防止DNS污染)
Network -> 6in4
Network -> ipset
Network -> ppp-mod-pppoe
Network -> shadowsocks-libev-polarssl (主角)

Utilities -> bzip2
Utilities -> Filesystem -> badblocks
Utilities -> Filesystem -> e2fsprogs
Utilities -> disc -> fdisk

默认的trunk版中是没有pdnsd/luci-app-qos-emong/shadowsocks-libev-polarssl/multiwan这4个源文件的,使用下面的命令获取编译需要的文件

cd ~/openwrt/trunk/packagegit clone https://github.com/madeye/shadowsocks-libev.gitgit clone https://github.com/prochip/mybox.gitsvn co svn://svn.openwrt.org/openwrt/branches/packages_14.07/net/multiwansvn co svn://svn.openwrt.org/openwrt/branches/packages_14.07/net/pdnsd

由于实在找不到luci-app-qos-emong的完整版本,这里从mybox中获取到luci-app-qos-emong缺少一个文件/mybox/luci-qos-emong/files/usr/bin/qos-emong,我们可以从其他地方提取,比如别人发布的编译好的ipk或者解压潘多拉的固件,记得设置这个文件属性为0755。

另外编译之前需要先配置uhttpd的设置,在编译之前配置是因为同时安装了uhttpd和nginx,这两个人会抢占80端口,nginx会优先uhttpd启动导致luci打不开。我们可以建立~/openwrt/trunk/files/etc/目录,并放置一些配置文件,这里的文件会覆盖到固件中的overlay中覆盖默认的设置。

建立文件~/openwrt/trunk/files/etc/config/uhttpd输入内容

config uhttpd 'main'list listen_http '0.0.0.0:10'list listen_http '[::]:10'#list listen_https '0.0.0.0:443'#list listen_https '[::]:443'option home '/www'option rfc1918_filter '1'option max_requests '3'option max_connections '100'option cert '/etc/uhttpd.crt'option key '/etc/uhttpd.key'option cgi_prefix '/cgi-bin'option script_timeout '60'option network_timeout '30'option http_keepalive '20'option tcp_keepalive '1'option ubus_prefix '/ubus' config cert 'px5g'option days '730'option bits '1024'option country 'DE'option state 'Berlin'option location 'Berlin'option commonname 'OpenWrt'

主要是修改uhttpd的端口,有需要的话其他的配置文件也可以放到这里,一并刷进去,当然也可以刷好之后再配置下面的部分。

开机加载SD卡,文件~/openwrt/trunk/files/etc/config/fstab

config globaloption anon_swap '0'option anon_mount '0'option auto_swap '1'option auto_mount '1'option delay_root '5'option check_fs '0' config mountoption uuid '7bdb-42fd'option target '/mnt/sd'option fstype 'ext4'option enabled '1'

建立虚拟wan口~/openwrt/trunk/files/etc/rc.loca

# Put your custom commands here that should be executed once# the system init finished. By default this file does nothing. ip link add link eth0.2 name vth1 type macvlanifconfig vth1 hw ether 00:18:F8:B5:E5:5Eifconfig vth1 up exit 0

pdns配置文件~/openwrt/trunk/files/etc/pdnsd.conf

global {# debug = on;perm_cache=1024;cache_dir="/var/pdnsd";run_as="nobody";server_port = 10053;server_ip = 127.0.0.1;status_ctl = on;query_method=tcp_only; min_ttl=15m;max_ttl=1w;timeout=10;} server {label= "GooglePublicDNS";ip = "8.8.4.4";root_server = on;uptest = none;} source {owner=localhost;#serve_aliases=on;file="/etc/hosts";} rr {name=localhost;reverse=on;a=127.0.0.1;owner=localhost;soa=localhost,root.localhost,42,86400,900,86400,86400;}

切记uhttpd的配置文件必须要在编译的时候编译进去,或者不编译nginx,等到刷好之后再执行opkg install nginx安装。

做完上面的步骤就可以执行make -j 2 V=99进行编译了。

开启IPv6

https://tunnelbroker.net/ 注册个账号,然后会获得一堆信息,编辑/etc/config/network添加

config interface 'henet'option proto '6in4'option username '用户名'option peeraddr '服务器IP'option ip6addr '2/64结尾的那串IP'option ip6prefix '::/64结尾的那串IP'option tunnelid '你的ID'option password '更新的KEY'

在Luci中点击这个端口后面的连接就可以了。

双拨网速叠加

这才是真正的加量不加价,上面我们已经配置了开机自动虚拟出来一个vth1,在接口中新建一个接口配置PPPOE拨号就可以了,编辑/etc/config/network添加wan2的配置信息。

config interface 'wan'option ifname 'eth0.2'option proto 'pppoe'option username '运营商提供的宽带账号'option password '密码'option peerdns '1' config interface 'wan2'option ifname 'vth1'option macaddr '00:18:F8:B5:E5:5E'option proto 'pppoe'option username '运营商提供的宽带账号'option password '密码'option peerdns '0'

我这里的情况是在日志中可以看到pppoe在不停的拨号,不时返回一个用户限制的错误信息,不用理会,一般拨6多个小时就拨上了,下面到multiwan中配置一下流量均衡。

/etc/config/multiwan

config multiwan 'config'option enabled '1'option default_route 'balancer' config interface 'wan'option health_interval '10'option timeout '3'option health_fail_retries '3'option health_recovery_retries '5'option failover_to 'wan2'option dns 'auto'option weight '5'option icmp_hosts 'www.baidu.com' config interface 'wan2'option health_interval '10'option timeout '3'option health_fail_retries '3'option health_recovery_retries '5'option failover_to 'balancer'option dns 'auto'option weight '5'option icmp_hosts 'www.baidu.com'

shadowsocks的具体设置

这里我们用的是dnsmasq-full提供的ipset功能自动维护IP库,依然和goagent一样指定域名就可以了。

/etc/shadowsocks.d/shadowsocks.json中配置好服务器的IP和端口等信息

{ "server":"222.222.222.222", "server_port":8080, "password":"1111", "timeout":600, "method":"rc4-md5", "fast_open":false, "fast_open": true, "workers": 1}

除了自动转发的端口外,我们还可以搭建一个SOCKS5的代理,因为为了减少不必要的流量通过SS的服务器,这里使用的是黑名单模式,那就难免会有漏网之鱼,我们可以再开放一个代理端口来和SwitchySharp之类的插件配合,需要的时候启用全局代理。

shadowsocks自1.4.6版本起增加了acl白名单功能,这样在我们启用全局代理的时候,不会把国内IP和局域网IP也通过SS服务器,内容可以通过GitHub获取。

编辑/etc/init.d/shadowsocks文件内容如下

#!/bin/sh /etc/rc.common# Copyright (C) 2006-2011 OpenWrt.org START=95 SERVICE_USE_PID=1SERVICE_WRITE_PID=1SERVICE_DAEMONIZE=1 start() { service_start /usr/bin/ss-local -c /etc/shadowsocks.d/shadowsocks.json -l "8888" --fast-open service_start /usr/bin/ss-redir -c /etc/shadowsocks.d/shadowsocks.json -l "10080"} stop() { service_stop /usr/bin/ss-local service_stop /usr/bin/ss-redir}

如果你的服务器和客户端Linux内核版本都大于3.7(Openwrt trunk现在是3.14),可以打开fast_open功能,速度会提升不少。将配置文件中的"fast_open":false修改成"fast_open":true,在Shell中执行echo "net.ipv4.tcp_fastopen=3" >> /etc/sysctl.conf && sysctl -p来打开tcp_fastopen功能。

编辑/etc/dnsmasq.conf文件,在尾部追加

conf-dir=/etc/dnsmasq.d

建立/etc/dnsmasq.d/gfwlist.conf文件来维护需要穿透GFW的域名列表,dnsmasq会用ipset自动维护ip列表,记录的IP库可以使用ipset -L命令查看。

#Facebookserver=/.facebook.com/.facebook.net/.fbcdn.net/.thefacebook.com/.akamaihd.net/127.0.0.1#10053ipset=/.facebook.com/.facebook.net/.fbcdn.net/.thefacebook.com/fbcdn-profile-a.akamaihd.net/fbcdn-sphotos-a.akamaihd.net/outwall #Twitterserver=/.twitter.com/.twitter4j.org/.twittercounter.com/.twitterfeed.com/.twittergadget.com/.twitterkr.com/.twittermail.com/.twittertim.es/.t.co/.twimg.com/.tinypic.com/.yfrog.com/.bitly.com/.mobilepicture.com/127.0.0.1#10053ipset=/.twitter.com/.twitter4j.org/.twittercounter.com/.twitterfeed.com/.twittergadget.com/.twitterkr.com/.twittermail.com/.twittertim.es/.t.co/.twimg.com/.tinypic.com/.yfrog.com/.bitly.com/api.mobilepicture.com/outwall

上 面是Facebook和Twitter的示例,可以按照需要维护这个列表,我在这里配置的Google的相关服务使用IPv4/IPv6配合直接解析的, 毕竟直连的速度要好的多(起码不比百度慢吧),Google北京的服务器直接访问是404错误,但是不代表它什么都不处理,translate/code /gstatic是可以解析到国内IP的,具体的东西自己挖掘吧,建议不要公开的好,别把国内仅剩的这几台也玩坏了,所以同理许多网站是可以通过 dnsmasq指定IP地址来访问,至于速度、时间成本就各有各的看法了。

我目前在用的方案是Google解析ip,dropbox目前只需要解决DNS污染问题就可以了,特定的常用网站和一些乱七八糟的不值得去找真实IP的通过ipset走shadowsocks。

配置转发,在/etc/firewall.user文件中追加

ipset -N outwall iphashiptables -t nat -A PREROUTING -p tcp -m set --match-set outwall dst -j REDIRECT --to-port 10080

重启防火墙,这里的10080是上面提到的本地监听端口,两者要保持一致。

广告过滤

建立/etc/dnsmasq.d/adblock.conf文件来过滤一些明显的联盟广告

#ADblockbogus-nxdomain=218.30.64.194#Taobaoaddress=/s8.taobao.com/127.0.0.1address=/s.click.taobao.com/127.0.0.1#Baiduaddress=/pos.baidu.com/127.0.0.1address=/cpro.baidustatic.com/127.0.0.1address=/cpro.baidu.com/127.0.0.1address=/cb.baidu.com/127.0.0.1address=/cbjs.baidu.com/127.0.0.1address=/drmcmm.baidu.com/127.0.0.1address=/duiwai.baidu.com/127.0.0.1address=/eiv.baidu.com/127.0.0.1address=/spcode.baidu.com/127.0.0.1address=/baidutv.baidu.com/127.0.0.1address=/bar.baidu.com/127.0.0.1#popupaddress=/100tjs.com/127.0.0.1address=/114zhaofang.com/127.0.0.1address=/116b.com/127.0.0.1address=/234y.com/127.0.0.1address=/arpg2.com/127.0.0.1address=/game3896.com/127.0.0.1address=/gelo.tw/127.0.0.1address=/resmkt.dipan.com/127.0.0.1address=/web.7k7k.com/127.0.0.1address=/xp3366.com/127.0.0.1address=/xp9365.com/127.0.0.1#Unionaddress=/.allyes.com/127.0.0.1address=/.cnxad.com/127.0.0.1address=/.cnxad.net/127.0.0.1address=/.unionsky.cn/127.0.0.1address=/.unionsky2.cn/127.0.0.1address=/.keyrun.cn/127.0.0.1address=/.keytui.com/127.0.0.1address=/.100fenlm.cn/127.0.0.1address=/.chanet.com.cn/127.0.0.1address=/.doubleclick.net/127.0.0.1address=/p.tanx.com/127.0.0.1#Otheraddress=/atm.youku.com/127.0.0.1address=/hudong.pl.youku.com/127.0.0.1

网站搭建

编辑nginx的配置文件/etc/nginx/nginx.conf,内容如下

user nobody nogroup; #设定用户及其用户名worker_processes 1; #允许线程个数error_log /mnt/sd/logs/nginx/error.log; #指定error.log的位置#pid /var/run/nginx.pid; #指定pid的存放位置events { use epoll; worker_connections 1024; #指定最大连接数}http { server_tokens off; #关闭在错误页面中的nginx版本 include mime.types; #default_type application/octet-stream; #access_log logs/access.log main; access_log off; #关闭访问日志 sendfile on; tcp_nopush on; keepalive_timeout 65; reset_timedout_connection on; #关闭不响应的客户端连接 send_timeout 10; #指定客户端的响应超时时间 #proxy_buffering off; #关闭缓存 #gzip on; include vhost.conf; #server 配置文件}

新建主机配置文件/etc/nginx/vhost.conf

server{ listen 80; location / { root /mnt/sd/www/; index index.html index.htm; }}

在shell中执行/etc/init.d/nginx restart重启nginx,详细的配置信息可以参考nginx官方网站。由于去掉了”臃肿”的goagent,内存和存储节省下来的部分可以考虑上个php+mysql,具体的看自己的需求。

DDNS

编译的时候我们已经选择了ddns-scripts,可以自己选择列表中的服务商,如果你拥有自己的域名,可以参考这篇OpenWrt下使用dnspod来实现DDNS功能

  • Copyright ©  PC在线云端  版权所有.
  • 转载请务必保留本文链接:https://nrcs.xyz/networks/307.html
Orgorg速率最高可达1000Mbps,流畅观看Youtube 4K、TikTok,支持 Windows、Android、iOS、Mac,支持 微信、支付宝 付款!
全球数据中心,多点BGP保证速度,无视晚高峰,全天4K秒开,IPLC专线无惧封锁
全IEPL /青云跨境,高峰时期稳定8K播放,流媒体影视, ChatGPT 解锁保障,客户端无日志保护您的隐私安全,稳定运行5年+
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

评论:1   其中:访客  1   博主  0
    • 龙在江湖 龙在江湖 0

      有点难…… :sad: