Skip to content

CentOS 7 搭建局域网VPN-Shadowsocks #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
johnnian opened this issue Feb 12, 2018 · 1 comment
Open

CentOS 7 搭建局域网VPN-Shadowsocks #48

johnnian opened this issue Feb 12, 2018 · 1 comment

Comments

@johnnian
Copy link
Owner

johnnian commented Feb 12, 2018

前言

想要搭建一个VPN,方便在外网的时候远程连接公司局域网,可以使用Shadowsocks,很方便滴搭建,网络拓扑图如下:

qq20180212-101958 2x

需要的资源:

  • 公网服务器(带公网IP): 1台,用于作网络请求端口转发
  • 公司局域网服务: 1台,用于搭建Shadowsocks服务端

局域网服务器:安装配置Shadowsocks

步骤1: 安装Shadowsocks

#安装 python setup tools
[root@localhost ~]# yum install python-setuptools
#安装pip
[root@localhost ~]# easy_install pip
#升级 pip
[root@localhost ~]# pip install --upgrade pip
#安装 shadowsocks
[root@localhost ~]# pip install shadowsocks

步骤2: 创建Shadowsocks服务

[root@localhost ~]# vi /usr/lib/systemd/system/shadowsocks.service
[Unit]
Description=Shadowsocks Server
Documentation=https://github.com/shadowsocks/shadowsocks
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
#设置启动时的配置文件,根据自己的需求改.
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json -d start
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/usr/bin/ssserver -d stop
[Install]
WantedBy=multi-user.target

步骤3: 创建Shadowsocks配置

[root@localhost ~]# vi /etc/shadowsocks.json
{
      "server":"0.0.0.0",
      "server_port":2082,
      "local_port":1080,
      "password":"LsY61dyK",
      "timeout":600,
      "method":"rc4-md5"
 }

备注:

  • server: 默认填写 0.0.0.0, 表示允许任何IP访问
  • server_port: shadowsocks 端口
  • password: 密码
  • method: 加密模式

步骤4: 启动服务

[root@localhost ~]#  systemctl enable shadowsocks
[root@localhost ~]#  systemctl start shadowsocks

这里需要注意:如果启动shadowsocks之后,访问还是有问题,可以确认下主机的防火墙是。

步骤5: 创建AUTOSSH反向代理

使用公网服务器作端口转发,公网服务器需要开启对应的端口,例如,这里使用 2082端口,则公网服务器需要开放2082端口。

#shadowsocks
[root@localhost ~]#  autossh -M 5678 -NR 2082:localhost:2082 -f root@123.123.123.123

备注: 对于如何使用AUTOSSH,请参考之前博文,autossh内外网穿透方法

客户端配置

qq20180212-103834 2x

客户端填写的配置:

  • 地址: 123.123.123.123(上面的公网IP)
  • 端口: 2082(公网IP作为映射的端口)
  • 加密方法: 填写RC4-MD5

参考链接

@FQLin
Copy link

FQLin commented Sep 18, 2018

只有一个前言,没有后续了么?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants