掌握科学上网的方法

最近因为apple music的关系,国内一直听得断断续续,没办法,最后只有尝试用传说中的“SS”来翻出去才能流畅的听了。吐槽一下水果的服务器,真是够了!

闲话少说,如果不想动手呢,那就到网上去买账号吧,但是安全性,真的不好说,如果要自己动手来,那么往下看喽:

 

centos和debian都可以,但是如果想做多用户限制一下流量那就需要一个小工具:ss-bash,通过这个工具就可以做流量限制!作者建议使用debian系统,详细使用方法往后看。

 

首先我们要安装ss的服务端,网上已经有大神写好了现成的脚本,方便大家了具体步骤:

 

1.wget –no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh   //下载脚本文件
2.chmod +x shadowsocks.sh    //设置可执行权限
3../shadowsocks.sh 2>&1 | tee shadowsocks.log      //保存安装日志

安装开始后会提示你输入你的端口和密码,这个根据自己需求来改。默认也可以,安装后可以自己修改。

Congratulations, shadowsocks install completed!
Your Server IP: x.x.x.x
Your Server Port: xxxx
Your Password: xxxx
Your Local IP: 127.0.0.1
Your Local Port: 1080
Your Encryption Method: aes-256-cfb

到这步基本就已经安装成功了,ss的配置文件在/etc/shadowsocks.json

默认的文件为单用户,如果你需要设置多端口用户需要修改一下:

{
“server”:”0.0.0.0″,
“local_address”:”127.0.0.1″,
“local_port”:1080,
“port_password”:{
“8989”:”password0″,
“9001”:”password1″,
“9002”:”password2″,
“9003”:”password3″,
“9004”:”password4″
},
“timeout”:300,
“method”:”aes-256-cfb”,
“fast_open”: false
}

常用命令:

启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status

至此ss部分搞定!然后我们去下载ss-bash,需要注意的事项:

  • 目前只支持python版Shadowsocks
  • 目前只支持统计ipv4流量

顺便把工作原理也粘一下吧:

不同的用户分配不同端口,使用iptables规则获取各端口的流量,脚本循环运行,在固定时间间隔根据iptables结果统计流量使用情况,并在流量超过限制时,添加对应端口的iptables reject规则以禁用端口。

 

好,现在来下载:

wget https://github.com/hellofwy/ss-bash/archive/v1.0-beta.3.tar.gz

然后解压到你指定的目录下

         tar zxvf v1.0-beta.3.tar.gz

首次运行时需要创建可管理的用户,例如:

sudo ./ssadmin.sh add 8388(端口号) passwd(密码) 10G(限制流量数)


然后启动sssserver:

sudo ./ssadmin.sh start


当启动成功后,你做得操作就生效了,当此端口用户使用流量达到阈值时就会断掉ss。

小贴士:需要bc计算器的支持,如果没安装的话debian安装命令为:sudo apt-get install bc    CENTOS安装命令:yum install bc      注意要在联网情况下

基本上上述操作做完之后就可以使用了,当然如果你想更详细的去自定义,我也摘抄了一份原作者的说明:

 

自定义ssserver的配置

打开文件ssmlt.template,添加相关选项。

请注意每个选项后必需有逗号(’,’)

默认选项为:

"server": "0.0.0.0",
"timeout": 60,
"method": "aes-256-cfb",

比如添加fastopen和worker选项后:

"server": "0.0.0.0",
"timeout": 60,
"method": "aes-256-cfb",
"fast_open": true,
"workers": 5,

修改之后,如果ssserver正在运行,请执行下面命令,重新加载文件并启动:

sudo ss-bash/ssadmin.sh soft_restart

修改流量统计间隔

默认的流量采样间隔为5分钟

流量间隔可根据实际需求调整,但最好不要太小,比如小于10秒

打开文件sslib.sh,修改INTERVEL的值,单位为秒。比如设置流量间隔为10分钟:

INTERVEL=600

修改ssserver文件位置

如果shadowsocks不是使用apt-get或者pip安装,无法自动找到ssserver文件时,请手动指定程序的具体位置。

打开文件sslib.sh,修改SSSERVER的值,比如ssserver的路径为/usr/local/bin/ssserver时,修改为

SSSERVER=/usr/local/bin/ssserver

文件夹中的相关文件

  • ssadmin.sh – 管理程序,所有命令通过该程序执行
  • sscounter.sh – 流量统计程序。由ssadmin.sh自动调用执行,注意:不要手动运行该程序
  • sslib.sh – 包含一些参数配置和流量统计函数。由ssadmin.sh自动调用执行,注意:不要手动运行该程序
  • ssmlt.template – ssserver的配置文件

程序运行后,会产生以下文件:

  • ssmlt.json – 根据用户列表和ssmlt.template生成的ssserver实际使用的配置文件
  • ssusers – 用户列表,包括端口、密码、流量限制参数。ssadmin.sh showpw 命令,显示该文件内容。
  • sstraffic – 用户流量使用情况,包括流量限制,已用流量,剩余流量等。ssadmin.sh show 命令,显示该文件内容。
  • traffic.log – 用户流量记录,供程序内部使用。
  • 其它文件 – .tmp、.lock、.pid等文件、文件夹tmp及其中文件为程序内部使用文件,请不要手动删除。

 

下面为帮助文件:

 

用法:
显示版本:
ssadmin.sh -v|v|version
显示帮助:
ssadmin.sh [-h|h|help]
启动ss:
ssadmin.sh start
停止ss:
ssadmin.sh stop
查看ss状态:
ssadmin.sh status
重启ss:
ssadmin.sh restart
软重启ss:
ssadmin.sh soft_restart
在不影响现有连接的情况下重启ss服务。用于ss服务参数修改,
和手动直接修改配置文件后,重启ss服务。
添加用户:
ssadmin.sh add port passwd limit
port:端口号, 0<port<=65535
passwd:密码, 不能有空格,引号等字符
limit:流量限制,可以用K/M/G/T、KB/MB/GB/TB等(不区
分大小写)。支持小数。比如10.5G、10.5GB等。
1KB=1024 bytes,以此类推。
示例: ssadmin.sh add 3333 abcde 10.5G
显示用户流量信息:
ssadmin.sh show port
显示所有用户流量信息:
ssadmin.sh show
显示用户密码信息:
ssadmin.sh showpw port
显示所有用户密码信息:
ssadmin.sh showpw
删除用户:
ssadmin.sh del port
修改用户:
ssadmin.sh change port passwd limit
修改用户密码:
ssadmin.sh cpw port passwd
修改用户流量限制:
ssadmin.sh clim port limit
修改所有用户流量限制:
ssadmin.sh change_all_limit limit
用户流量使用量置零:
ssadmin.sh rused limit
所有用户流量使用量置零:
ssadmin.sh reset_all_used
用户流量限制置零:
ssadmin.sh rlim port
全部用户流量限制置零:
ssadmin.sh reset_all_limit
显示已添加的iptables规则:
ssadmin.sh lrules
分享到:

168 条评论

昵称
  1. apps for pc download

    below youll discover the link to some internet sites that we think you need to visit

  2. pc apps for windows 10

    we prefer to honor several other online web pages around the web, even when they arent linked to us, by linking to them. Under are some webpages worth checking out

  3. games for pc download

    usually posts some incredibly intriguing stuff like this. If you are new to this site

  4. that is the end of this post. Right here youll discover some websites that we think youll appreciate, just click the links over

  5. pc games for windows 7

    Here are some of the sites we advocate for our visitors

  6. pc games for windows 8

    below youll discover the link to some web sites that we assume you ought to visit

  7. Bella Aurora Zonnebrand

    just beneath, are numerous completely not associated web pages to ours, having said that, they may be surely worth going over

  8. gay anal cleaning

    just beneath, are several completely not connected web pages to ours, nonetheless, they are certainly really worth going over

  9. best thrusting rabbit

    here are some hyperlinks to web-sites that we link to due to the fact we feel they may be really worth visiting

  10. rencontres adulte

    very handful of websites that take place to be in depth below, from our point of view are undoubtedly properly really worth checking out

  11. full apps download

    Here is a good Weblog You might Obtain Fascinating that we Encourage You

  12. always a massive fan of linking to bloggers that I appreciate but do not get lots of link enjoy from

  13. ушаков словарь

    please go to the websites we follow, which includes this one, as it represents our picks in the web

  14. apps download for windows 7

    just beneath, are many completely not connected websites to ours, even so, they are certainly really worth going over

  15. https://siam-shipping.com/

    freight forwarder to mexico – freight forwarder georgia – freight forwarder exam – freight forwarder uk to singapore – freight forwarder world ranking

  16. blue dolphin vibe

    Here is a superb Weblog You might Locate Interesting that we Encourage You

  17. although internet sites we backlink to below are considerably not connected to ours, we feel they are essentially worth a go by means of, so possess a look

  18. app download for pc

    here are some hyperlinks to web pages that we link to simply because we consider they may be worth visiting

  19. pc games free download

    although websites we backlink to beneath are considerably not connected to ours, we feel they’re really worth a go via, so have a look

  20. pc games apps free download

    Wonderful story, reckoned we could combine several unrelated data, nonetheless definitely worth taking a search, whoa did one particular learn about Mid East has got additional problerms too

  21. Google

    The time to read or stop by the subject material or websites we’ve linked to below.

  22. Apex Legends Season 1

    Very good post! We will be linking to this particularly great content on our website. Keep up the good writing.

  23. Cameron

    After reading your blog post, I browsed your website a bit and noticed you aren’t ranking nearly as well in Google as you could be. I possess a handful of blogs myself, and I think you should take a look at “seowebsitetrafficnettools”, just google it. You’ll find it’s a very lovely SEO tool that can bring you a lot more visitors and improve your ranking. They have more than 30+ tools only 20$. Very cheap right? Keep up the quality posts

  24. Eleanore

    After reading your blog post, I browsed your website a bit and noticed you aren’t ranking nearly as well in Google as you could be. I possess a handful of blogs myself, and I think you should take a look at “seowebsitetrafficnettools”, just google it. You’ll find it’s a very lovely SEO tool that can bring you a lot more visitors and improve your ranking. They have more than 30+ tools only 20$. Very cheap right? Keep up the quality posts

  25. Make Your Website Popular

    If you are seeking for the top service to get website visitors to your web page, i advise to use seowebsitetrafficnet. I am using it with a great result. Simply just type seowebsitetrafficnet in google.

  26. Janessa

    After reading your blog post, I browsed your website a bit and noticed you aren’t ranking nearly as well in Google as you could be. I possess a handful of blogs myself, and I think you should take a look at “groupbuyseotoolsinfo”, just google it. You’ll find it’s a very lovely wordpress SEO tools that can bring you a lot more visitors and improve your ranking. Keep up the quality posts

  27. Echo

    感谢楼主,一键式搞定 , 之前看其他的一步步配置自己多此一举把公网ip配置到了json的server中导致启动服务失败一直找不到原因.

  28. ererermao

    有设置ssserver路径,但是ssserver一直启动失败,不知道原因

  29. day

    root@localhost:~/oneinstack# ssadmin.sh -v|v|version
    -bash: version: command not found
    -bash: v: command not found
    -bash: ssadmin.sh: command not found
    root@localhost:~/oneinstack# ssadmin.sh show 8388
    -bash: ssadmin.sh: command not found
    root@localhost:~/oneinstack#
    怎么我出错呢,debian 7….可以正常统计限制了,但是命令ssadmin.sh……无效???缺少安装啥软件了吗(已经安装git, bc,awk)

    1. matt

      你能确定你的执行文件目录是正确的吗

    2. Htao

      命令路径不对就出错啊。 你应该输入 ss-bash/ssadmin.sh show 应该就可以了。

  30. 维安ss科学上网

    sudo ./ssadmin.sh add 8388(端口号) passwd(密码) 10G(限制流量数)
    输入这句以后提示cannot not found
    请问这是怎么回事呢

    1. matt

      是debian吗?

      1. day

        root@localhost:~/oneinstack# ssadmin.sh -v|v|version
        -bash: version: command not found
        -bash: v: command not found
        -bash: ssadmin.sh: command not found
        root@localhost:~/oneinstack# ssadmin.sh show 8388
        -bash: ssadmin.sh: command not found
        root@localhost:~/oneinstack#
        怎么我出错呢,debian 7….可以正常统计限制了,但是命令ssadmin.sh……无效???缺少安装啥软件了吗(已经安装git, bc,awk)

      2. ko

        请问下作者,centeros7下的都正常,就是监控不到流量,使用一直未0,这是什么原因。有什么解决办法吗

      3. Charla

        and believed that he was in the Army Rangers/ Special Forces. I also believe that the Pro-Defeat faction wanted it to be true so they di1&8#n2d7;t bother doing their homework. Or if you want to think that they are a nefarious group then you might think that they did know Jesse was delusional and still used him and his contrived stories to further their agenda of lies.

    2. Htao

      这条命令要在ss-bash文件夹下才会正常运行。

    3. Jaylin

      Should we use this technique for paginated pages as well? I am asking that because paginated pages do not have the same content, but have duplicate meta tags since they do not defer from the main page in any substantial way.For example when someone is looking for widgets, I have 3 pages. What should the meta tags be of the 2nd and 3rd page since they are just a cotnniuation of the results shown on the first page??