在 VPS 上搭建 PPTP VPN 服务

本文最后更新于 2019 年 8 月 30 日


示例用途:游戏虚拟局域网(饥荒,分手厨房)。

本文以在大陆阿里云 VPS 上的 Debian 10 系统为例,介绍如何搭建 PPTP VPN 服务。

注:请先参照 Ubuntu (Debian) 服务器的初始化配置 一文对服务器进行各种必要的配置。本文以 sammy 用户为例,进行 VPN 的建立,并默认已按初始化配置文章对服务器进行了配置。


安装

1
sudo apt update && sudo apt install pptpd -y

配置

修改 pptpd.conf ,找到对应位置,修改如下:

1
sudo vim /etc/pptpd.conf
/etc/pptpd.conf
1
2
3
option /etc/ppp/options.pptpd
localip 10.0.0.1
remoteip 10.0.0.100-200

添加一个 pppd 配置文件,例如:

1
sudo vim /etc/ppp/options.pptpd
/etc/ppp/options.pptpd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Read man pppd to see the full list of available options

# The name of the local system for authentication purposes
name pptpd

# Refuse PAP, CHAP or MS-CHAP connections but accept connections with
# MS-CHAPv2 or MPPE with 128-bit encryption
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128

# Add entry to the ARP system table
proxyarp

# For the serial device to ensure exclusive access to the device
lock

# Disable BSD-Compress and Van Jacobson TCP/IP header compression
nobsdcomp
novj
novjccomp

# Disable file logging
nolog

# DNS servers for Microsoft Windows clients. Using Google's public servers here
ms-dns 8.8.8.8
ms-dns 8.8.4.4

添加用户,设置密码:

1
sudo vim /etc/ppp/chap-secrets
/etc/ppp/chap-secrets
1
2
username_1 pptpd password_1 *
username_2 pptpd password_2 *

注意:如果以上密码包括特殊字符,请将密码字段用 " 包裹。

允许转发:

1
sudo vim /etc/sysctl.conf
/etc/sysctl.conf
1
net.ipv4.ip_forward = 1
1
2
3
sudo sysctl -p
sudo systemctl enable pptpd
sudo systemctl restart pptpd

防火墙配置

修改 /etc/default/ufw

1
sudo vim /etc/default/ufw
/etc/default/ufw
1
DEFAULT_FORWARD_POLICY="ACCEPT"

修改 /etc/ufw/before.rules

1
sudo vim /etc/ufw/before.rules

*filter 之前添加:

/etc/ufw/before.rules
1
2
3
4
5
6
7
8
9
# nat Table rules
*nat
:POSTROUTING ACCEPT [0:0]

# Allow traffic from clients to eth0
-A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE

# commit to apply changes
COMMIT

# drop INVALID packets 之后添加:

/etc/ufw/before.rules
1
-A ufw-before-input -p 47 -i eth0 -j ACCEPT
1
2
sudo ufw allow 1723
sudo ufw disable && sudo ufw enable

开启安全组

阿里云后台安全组中添加 1723 端口(TCP)入站规则。

客户端所连 OpenWrt 路由器

针对错误:

LCP: timeout sending Config-Requests

路由器中:

1
2
3
opkg update
opkg install kmod-nf-nathelper-extra
vim /etc/sysctl.conf

最后一行添加:

/etc/sysctl.conf
1
net.netfilter.nf_conntrack_helper = 1
1
sysctl -p

References

PPTP server - ArchWiki

How To Setup a Firewall with UFW on an Ubuntu and Debian Cloud Server

Setup PPTP Server on Ubuntu 16.04

使用 PPTP 配置 Linux 上的 VPN 服务器

OpenWRT PPTP 穿透

GRE traffic dropped at firewall with explicit allow rules

PPTP NAT Traversal

在 CentOS 上安装 Gitlab CE

本文以 CentOS 7 为例,介绍如何安装搭建 Gitlab 社区版。

准备

非 root 用户,创建新用户的方法可见这篇文章

官方推荐的最低配置要求: 2 核心,8 GB 物理内存。

如有域名,A 记录指向服务器 ip 。

安装依赖:

1
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients

可选,安装 postfix 邮件功能,你可以不必安装 postfix 而使用其他的 SMTP 服务:

1
2
3
sudo yum install -y postfix
sudo systemctl enable postfix.service
sudo systemctl start postfix.service

Read More

CentOS 服务器的初始配置

本文最后更新于 2020 年 4 月 17 日


本文以 CentOS 8 为例,介绍如何对服务器进行初步配置。

本例中,普通用户名采取 sammy 为例,服务器 ip 采取 xx.xxx.xx.xxx 为例,请根据自己的实际情况做相应修改。


创建新用户

登录服务器

本地执行:

1
ssh [email protected]

如产生问题,请先查看本文 Troubleshooting 一节。

更改密码

1
passwd

更新系统

1
2
3
4
5
dnf check-update
dnf update
dnf clean all
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf config-manager --set-enabled PowerTools

安装必要软件

1
dnf install sudo vim -y

创建新用户

服务器上,以 root 用户执行:

1
adduser sammy

修改密码:

1
passwd sammy

赋予 sudo 权限

服务器上,以 root 用户:

1
gpasswd -a sammy wheel

登录此用户

在本地尝试登录此用户:

1
ssh [email protected]

设置 SSH 登录

在本地机器上执行:

1
ssh-keygen -a 1000 -t ed25519 -f ~/.ssh/sammy_host -C "sammy@sammy_host"

本地生成钥匙对后,将其中的公钥上传到服务器上:

1
ssh-copy-id -i ~/.ssh/sammy_host.pub [email protected]

按照提示输入密码。本地建立 config 文件:

1
vim ~/.ssh/config

添加如下内容:

~/.ssh/config
1
2
3
4
5
Host sammy_host    # 别名
HostName xx.xxx.xx.xxx # 替换 xx.xxx.xx.xxx 为服务器 ip 地址
Port 22 # 端口,稍后会进行修改
User sammy # 用户名
IdentityFile ~/.ssh/sammy_host # 私钥文件

修改本地 config 文件权限:

1
chmod 600 ~/.ssh/config

利用私钥的登录方式,本地执行:

1
ssh sammy_host

Read More

Mastodon