Pptp vpn server linux

Set up Your Own PPTP VPN Server On Debian, Ubuntu, CentOS

In this tutorial, I will show you how to set up your own PPTP VPN server on Debian, Ubuntu, CentOS. So you don’t have to buy VPN service anymore.

Note: PPTP is no longer a secure VPN solution. I do not recommend using it. (April 20, 2017). Instead, you can use OpenConnect VPN or WireGuard VPN.

1. Install pptpd

Debian/Ubuntu

sudo apt-get install pptpd -y

CentOS

Since the PPTP VPN daemon package is available in EPEL (Extra Package for Enterprise Linux) repository, we have to add the repository and then install pptpd.

sudo yum install epel-release sudo yum install -y pptpd

2. Adding DNS Servers

Debian/Ubuntu

sudo vi /etc/ppp/pptpd-options

CentOS

sudo vi /etc/ppp/options.pptpd

8.8.8.8 and 8.8.4.4 is Google’s DNS server. If Google’s DNS server is blocked in your area, then you can use OpenDNS Server: 208.67.222.222 and 208.67.220.220

3. Adding VPN User Accounts

Open up /etc/ppp/chap-secrets file

sudo vi /etc/ppp/chap-secrets

Add user and password as follows. Use tab key to separate them.

user1 pptpd user1-password * user2 pptpd user2-password *

4. Allocating Private IP for VPN Server and Clients

Edit /etc/pptpd.conf file.

Add the following lines to at the enf of file.

localip 10.0.0.1 remoteip 10.0.0.100-200

Save and close the file. localip is the IP for your VPN server. remoteip are for VPN clients.

5. Enable IP Forwarding

In order for the VPN server to route packets between VPN client and the outside world, we need to enable IP forwarding. Thus, the VPN server becomes a router.

Save and close the file. then apply the changes with the below command. The -p option will load sysctl settings from /etc/sysctl.conf file. This command will preserve our settings between system reboots.

6. Configure Firewall for IP Masquerading

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

The above command append (-A) a rule to the end of of POSTROUTING chain of nat table. It will link your virtual private network with the Internet. And also hide your network from the outside world. So the Internet can only see your VPN server’s IP, but can’t see your VPN client’s IP. Just like your home router hide your private home network.

Your server’s ethernet card name may not be eth0. You can use ip address or ip link command to check that. In order to save this iptables rule permanently, you can put the above command in /etc/rc.local file, so the command will be executed on system boot by root automatically. By the way, you don’t have to add sudo to the commands in rc.local.

Читайте также:  Linux расширить диск sda

On ubuntu, it may be a good idea to remove the -e part from the first line in rc.local file. If you have -e option, then when a command in rc.local fails to run, any command below will not be executed.

7. Start PPTPD Daemon

sudo systemctl start pptpd or sudo service pptpd start

If you have Systemd on your server, then enable pptpd service on system boot:

sudo systemctl enable pptpd

Now set up your vpn client and you should be able to connect to your VPN server.

Install PPTP VPN Client On Debian/Ubuntu Desktop

Open a terminal window and run this command to install PPTP VPN client.

sudo apt-get install pptp-linux network-manager-pptp network-manager-pptp-gnome

Install PPTP VPN Client on Fedora Gnome Desktop

sudo dnf install NetworkManager-pptp NetworkManager-pptp-gnome pptp pptp-setup

Источник

Поднимаем VPN – PPTP сервер на Ubuntu

Поднимаем PPTP сервер на Ubuntu

В этой статье я расскажу как поднять собственный PPTP сервер на Ubuntu. Почему именно PPTP? У каждого свои цели и задачи, кому-то нужен PPTP, кому-то L2TP/IPSec, кому-то IKEv2, а может и OpenVPN. Я постараюсь написать статьи по установке и настройке хотя бы двух протоколов VPN на Ubuntu и начну с PPTP. Все описанные действия производились на Ubuntu 14.04.5 LTS. Напоминаю, что дешевые VPS во Франции для запуска своего VPN вы можете посмотреть здесь.

Для установки понадобятся права root пользователя или sudo.

1. Устанавливаем необходимые пакеты:

После окончания установки, нам понадобится отредактировать несколько файлов. Для изменения файлов вы можете пользоваться любым удобным для вас способом, хоть nano, хоть визуальными редакторами и т.д.

Теперь вам необходимо определиться с локальной подсетью для клиентов VPN. Вы можете сделать себе подсеть из любой подсети, которая не маршрутизируется в интернете:

10.0.0.0/8 172.16.0.0/12 192.168.0.0/16

2. Открываем файл /etc/pptpd.conf, находим и раскоментируем (если вдруг закоментированы) строки localip и remoteip, затем прописываем свою ip адресацию.

localip 172.16.0.1 remoteip 172.16.0.2-254
  • localip – ip адрес из выбранной вами подсети, который будет являться локальным шлюзом для клиентов VPN.
  • remoteip – пул ip адресов для раздачи клиентам VPN.

Если на вашей машине несколько внешних IP адресов, то вы можете указать конкретный IP, по которому будет доступно подключение к VPN серверу. В конце файла добавьте:

3. Открываем файл /etc/ppp/pptpd-options и добавляем в конце файла:

mtu 1400 mru 1400 auth require-mppe

В этом же файле при необходимости вы можете указать конкретные DNS, которые будут использоваться при подключении через VPN. Найдите и раскомментируйте строки ms-dns:

4. Открываем стандартный файл /etc/sysctl.conf, находим и раскомментируем строку:

5. Добавляем необходимые правила в iptables:

iptables -A INPUT -p gre -j ACCEPT iptables -A INPUT -m tcp -p tcp --dport 1723 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Обратите внимание, что eth0 – имя вашего сетевого интерфейса. Вы можете узнать его с помощью команды ifconfig

Если вам необходимо, чтобы была локальная сеть между клиентами, подключенными к VPN, добавьте следующие правила в iptables:

iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE iptables -I INPUT -s 172.16.0.0/24 -i ppp0 -j ACCEPT iptables --append FORWARD --in-interface eth0 -j ACCEPT

Обратите внимание, что 172.16.0.0/24 – локальная подсеть, которую вы себе выбрали, а ppp0 – имя pptp интерфейса.

Читайте также:  Linux аналог paint net

Для сохранения iptables, выполните команду:

6. Пользователей для подключения к VPN серверу добавляем в файле /etc/ppp/chap-secrets

user1 pptpd password1 "*" user2 pptpd password2 "172.16.0.2"
  • user1 – имя пользователя
  • password1 – пароль пользователя
  • “*” – локальный ip будет выдаваться из пула, указанного в файле /etc/pptpd.conf
  • “172.16.0.2” – пользователю будет присвоен указанный ip адрес.

7. Перезапускаем сервис pptpd для применения новых настроек:

Ваш PPTP сервер на Ubuntu запущен!

P.S. Если вдруг вы столкнетесь с тем, что добавленные правила iptables пропадают после рестарта firewall или перезагрузки машины, то сделайте действия, описанные ниже.

1. Добавляем заново все правила, как описано в 5-м шаге.
2. Сохраняем правила в конфиг:

iptables-save > /etc/iptables.conf

3. Открываем файл /etc/network/interfaces и добавляем в самый конец:

pre-up /sbin/iptables-restore < /etc/iptables.conf

Теперь можете перезагрузить Firewall или всю машину и убедиться, что правила iptables сохраняются.

  1. Если ваши цели связаны с анонимностью и безопасностью, я крайне не рекомендую использовать PPTP. Лучше посмотрите в сторону OpenVPN или Wireguard.
  2. На новых системах уже нет возможности сохранять правила iptables способом, описанным выше. И вообще, желательно отказаться от iptables-save по той простой причине, что есть сервисы, которые сами добавляют свои правила в iptables после перезагрузки машины (например Docker) и могут возникнуть конфликты с уже сохраненными iptables-save через iptables-save правилами.

Поэтому проще делать следующим образом:

Сначала вы создаете iptables.sh и прописываете в него все собственные правила, например так:

#!/bin/sh iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # ICMP iptables -A INPUT -p icmp -j ACCEPT # SSH iptables -A INPUT -s 5.5.5.5/32 -p tcp --dport 22 -j ACCEPT # Веб-сервер iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j ACCEPT # Zabbix Agent iptables -A INPUT -s 5.5.5.5/32 -p tcp --dport 10050 -j ACCEPT iptables -P INPUT DROP iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT

Затем добавляете файлу права на запуск: chmod +x /root/iptables.sh и добавляете в крон:

@reboot root /root/iptables.sh >/dev/null 2>&1

Источник

PPTP server

Point-to-Point Tunneling Protocol (PPTP) is a method for implementing virtual private networks. PPTP uses a control channel over TCP and a GRE tunnel operating to encapsulate PPP packets.

This entry will show you on how to create a PPTP server in Arch.

Warning: The PPTP protocol is inherently insecure. See http://poptop.sourceforge.net/dox/protocol-security.phtml for details.

Installation

Configuration

A typical configuration may look like:

# Read man pptpd.conf, see samples in /usr/share/doc/pptpd # and write your pptpd configuration here # pppd options file. By default, /etc/ppp/options is used option /etc/ppp/options.pptpd # Server IP in local network localip 192.168.1.2 # IP address ranges used to assign IPs to new connecting clients # Here we define two ranges for our 192.168.1.* subnet: 234-238 and 245 remoteip 192.168.1.234-238,192.168.1.245

Now create the pppd options file, in our example this is /etc/ppp/options.pptpd :

# 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

Now create credentials file for authenticating users:

# Secrets for authentication using CHAP # client server secret IP addresses user2 pptpd 123 *

Now you can be authenticated with user2 as username and 123 for password.

Читайте также:  Alt linux поменять имя компьютера

Create a sysctl configuration file /etc/sysctl.d/30-ipforward.conf and enable kernel packet forwarding that allow connecting clients to have access to your subnet (see also Internet Share#Enable packet forwarding):

/etc/sysctl.d/30-ipforward.conf

Now apply changes to let the sysctl configuration take effect:

iptables firewall configuration

Configure your iptables settings to enable access for PPTP Clients

# Accept all packets via ppp* interfaces (for example, ppp0) iptables -A INPUT -i ppp+ -j ACCEPT iptables -A OUTPUT -o ppp+ -j ACCEPT # Accept incoming connections to port 1723 (PPTP) iptables -A INPUT -p tcp --dport 1723 -j ACCEPT # Accept GRE packets iptables -A INPUT -p 47 -j ACCEPT iptables -A OUTPUT -p 47 -j ACCEPT # Enable IP forwarding iptables -F FORWARD iptables -A FORWARD -j ACCEPT # Enable NAT for eth0 on ppp* interfaces iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE iptables -A POSTROUTING -t nat -o ppp+ -j MASQUERADE

Note: Ensure that "eth0" is replaced with the actual ethernet interface connected to the server.

Now save the new iptables rules with:

# iptables-save > /etc/iptables/iptables.rules

To load /etc/iptables/iptables.rules automatically after boot, enable the iptables.service unit.

Read Iptables for more information.

UFW firewall configuration

Configure your ufw settings to enable access for PPTP Clients.

You must change default forward policy in /etc/default/ufw

DEFAULT_FORWARD_POLICY="ACCEPT"

Now change /etc/ufw/before.rules , add following code after header and before *filter line

# nat Table rules *nat :POSTROUTING ACCEPT [0:0] # Allow traffic from clients to eth0 -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE # commit to apply changes COMMIT

Allow GRE packets (protocol 47) in /etc/ufw/before.rules , find the line with: # drop INVALID packets and add rule:

# drop INVALID packets (logs these in loglevel medium and higher) -A ufw-before-input -p 47 -i $iface -j ACCEPT -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny -A ufw-before-input -m conntrack --ctstate INVALID -j DROP

Restart ufw for good measure

Start the server

Now you can start and enable your PPTP Server using pptpd.service .

Troubleshooting

As with any service, see Systemd#Troubleshooting to investigate errors.

Error 619 on the client side

Search for the logwtmp option in /etc/pptpd.conf and comment it out. When this is enabled, wtmp will be used to record client connections and disconnections.

pptpd[xxxxx]: Long config file line ignored

Add a blank line at the end of /etc/pptpd.conf . [1]

ppp0: ppp: compressor dropped pkt

If you have this error while a client is connected to the server, add the following script to /etc/ppp/ip-up.d/mppefixmtu.sh :

#!/bin/sh CURRENT_MTU="`ip link show $1 | grep -Po '(?

Источник

Оцените статью
Adblock
detector