月度归档:2019年11月

在Windows Server 上搭建Shadowsocks服务器

这里是在windows上搭建Shadowsocks服务器,使用的是github上的libQtShadowsocks项目。
项目地址:https://github.com/shadowsocks/libQtShadowsocks

准备

一台可以翻墙的windows。

下载libQtShadowsocks

https://github.com/shadowsocks/libQtShadowsocks/releases下载一个已经编译好的版本,这里是shadowsocks-libqss-v2.0.2-win64.7z。
下载后解压到任意位置,里面就一个shadowsocks-libqss.exe文件。

配置文件

在解压目录下创建2个文件,一个config.json,一个shadowsocks-server.bat。
config.json放置配置信息。
内容如下:

1
2
3
4
5
6
7
8
9
10
11
{
“server”:”0.0.0.0″,
“server_port”:8023,
“local_address”:”127.0.0.1″,
“local_port”:1080,
“password”:”password”,
“timeout”:600,
“method”:”aes-256-cfb”,
“http_proxy”: false,
“auth”: false
}

配置说明:
server
the address your server listens(服务器IP)
local_address
the address your local listens(本地代理地址)
local_port
local port(本地代理端口)(写之前创建的ss的端口)
port_password
password used for encryption(自己设定的服务器端口和密码)(自己可以随便设定)
timeout
in seconds(超时断开,以秒为单位)
method
default: “aes-256-cfb”, see Encryption(加密方式)
fast_open
use TCP_FASTOPEN, true / false(是否使用TCP)
workers
number of workers, available on Unix/Linux(这个只在Unix和Linux下有用,可不设置)。

shadowsocks-server.bat内容如下:

1
2
@echo off
shadowsocks-libqss.exe -c config.json -S

运行Shadowsocks服务

直接运行shadowsocks-server.bat即可运行Shadowsocks服务,你也可以在命令提示符进入软件目录,运行shadowsocks-libqss.exe -c config.json -S这行命令。

客户端配置

这里使用的客户端为Shadowsocks,github地址:https://github.com/shadowsocks/shadowsocks-windows

注意:要以PAC模式运行,如果选择全局模式,所有的访问都会使用shadowsocks;如果选择了PaC模式,则只有pac.txt中的网址才会使用shadowsocks。

注意防火墙开通相应的端口。

自定义规则

参考:http://honglu.me/2015/06/26/ShadowSocks%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%84%E5%88%99/
从网上查阅的资料
编辑FGWList的用户规则


但我本地最后从FGWList更新本地pac时报错了

所以我是直接修改的pac.txt文件,在其中加入你想使用shadowsocks访问的网址,最后选择使用PAC模式即可。

多用户

如果希望多个用户使用shadowsocks服务,使用下面的配置替换password:xxx部分。

1
2
3
4
5
6
“port_password”: {
“8381”: “foobar1”,
“8382”: “foobar2”,
“8383”: “foobar3”,
“8384”: “foobar4”
},

问题

更新于2018-05-31.
某天shadowsocks服务不能使用了。
server端日志:

1
2
3
4
5
6
7
8
9
10
11
12
2018-05-31 16:15:41.382 INFO: Connecting clients1.google.com:443 from 183.62.174.53:48977
2018-05-31 16:15:44.649 INFO: Connecting clients1.google.com:443 from 183.62.174.53:49021
2018-05-31 16:15:44.665 INFO: Connecting clients1.google.com:443 from 183.62.174.53:49032
2018-05-31 16:15:50.803 INFO: Connecting clients1.google.com:443 from 183.62.174.53:49103
2018-05-31 16:15:56.177 INFO: Connecting www.google.com:443 from 183.62.174.53:49199
2018-05-31 16:15:56.185 INFO: Connecting www.google.com:443 from 183.62.174.53:49200
2018-05-31 16:16:11.364 DEBUG: Local socket: The remote host closed the connection
2018-05-31 16:16:14.637 DEBUG: Local socket: The remote host closed the connection
2018-05-31 16:16:14.654 DEBUG: Local socket: The remote host closed the connection
2018-05-31 16:16:20.794 DEBUG: Local socket: The remote host closed the connection
2018-05-31 16:16:26.164 DEBUG: Local socket: The remote host closed the connection
2018-05-31 16:16:26.172 DEBUG: Local socket: The remote host closed the connection

更换了算法、端口还是不行,客户端更新版本也不行,最后更新服务端版本后ok了。这里使用的版本是:shadowsocks-libqss-v2.0.2-win64.7z。

PS:有问题先看看github上相关的Issues。

手動解除 fail2ban 封鎖的 IP

假設以下是已經被 ban 的 iptables 清單

iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
f2b-sshd   tcp  --  anywhere             anywhere             multiport dports ssh
f2b-sshd   tcp  --  anywhere             anywhere             multiport dports ssh
f2b-sshd   tcp  --  anywhere             anywhere             multiport dports ssh
f2b-sshd   tcp  --  anywhere             anywhere             multiport dports ssh

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain f2b-sshd (4 references)
target     prot opt source               destination         
REJECT     all  --  112.11.11.11        anywhere             reject-with icmp-port-unreachable
RETURN     all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere    
#删除在f2b-sshd中的第一条
iptables -D f2b-sshd 1

iptables --list
iptables-save

重新載入讓設定生效

service fail2ban reload

Linux Start Restart and Stop The Cron or Crond Service

Commands for RHEL/Fedora/CentOS/Scientific Linux user

If you are using Redhat (RHEL)/Fedora/CentOS Linux use the following commands.

Task: Start cron service

To start the cron service, use:
# /etc/init.d/crond start
OR RHEL/CentOS 5.x/6.x user:
# service crond start
OR RHEL/Centos Linux 7.x user:
# systemctl start crond.service

Task: Stop cron service

To stop the cron service, use:
# /etc/init.d/crond stop
OR RHEL/CentOS 5.x/6.x user:
# service crond stop
OR RHEL/Centos Linux 7.x user:
# systemctl stop crond.service

Task: Restart cron service

To restart the cron service, use:
# /etc/init.d/crond restart
OR RHEL/CentOS 5.x/6.x user:
# service crond restart
OR RHEL/Centos Linux 7.x user:
# systemctl restart crond.service

Commands for Ubuntu/Mint/Debian based Linux distro

If you are using Debian or Ubuntu or Mint Linux the following commands.

Task: Debian Start cron service

To start the cron service, use:
# /etc/init.d/cron start
OR
$ sudo /etc/init.d/cron start
OR
$ sudo service cron start

Task: Debian Stop cron service

To stop the cron service, use:
# /etc/init.d/cron stop
OR
$ sudo /etc/init.d/cron stop
OR
$ sudo service cron stop

Task: Debian Restart cron service

To restart the cron service, use:
# /etc/init.d/cron restart
OR
$ sudo /etc/init.d/cron restart
OR
$ sudo service cron restart

Task : Start the cron service at boot time

It is recommended that you start the service at boot time so that job can run w/o problems.

If you are using Redhat (RHEL)/Fedora Core/Cent OS Linux use the following commands to ensure that the service remains enabled after a reboot:
# chkconfig crond on
You can use a text based GUI tool called ntsysv to enable crond service:
# ntsysv

If you are using Debian or Ubuntu Linux use the following commands to ensure that the service remains enabled after a reboot:
# rcconf
OR
$ sudo rcconf
You can use command line tool update-rc.d:
# update-rc.d cron defaults
OR
$ sudo update-rc.d cron defaults