How to connect to vpn in linux

Connect to a VPN

A VPN (or Virtual Private Network ) is a way of connecting to a local network over the internet. For example, say you want to connect to the local network at your workplace while you’re on a business trip. You would find an internet connection somewhere (like at a hotel) and then connect to your workplace’s VPN. It would be as if you were directly connected to the network at work, but the actual network connection would be through the hotel’s internet connection. VPN connections are usually encrypted to prevent people from accessing the local network you’re connecting to without logging in.

There are a number of different types of VPN. You may have to install some extra software depending on what type of VPN you’re connecting to. Find out the connection details from whoever is in charge of the VPN and see which VPN client you need to use. Then, go to the software installer application and search for the NetworkManager package which works with your VPN (if there is one) and install it.

If there isn’t a NetworkManager package for your type of VPN, you will probably have to download and install some client software from the company that provides the VPN software. You’ll probably have to follow some different instructions to get that working.

To set up the VPN connection:

  1. Open the Activities overview and start typing Network .
  2. Click on Network to open the panel.
  3. At the bottom of the list on the left, click the + button to add a new connection.
  4. Choose VPN in the interface list.
  5. Choose which kind of VPN connection you have.
  6. Fill in the VPN connection details, then press Add once you are finished.
  7. When you have finished setting up the VPN, open the system menu from the right side of the top bar, click VPN off and select Connect . You may need to enter a password for the connection before it is established. Once the connection is made, you will see a lock shaped icon in the top bar.
  8. Hopefully you will successfully connect to the VPN. If not, you may need to double-check the VPN settings you entered. You can do this from the Network panel that you used to create the connection. Select the VPN connection from the list, then press the button to review the settings.
  9. To disconnect from the VPN, click the system menu on the top bar and click Turn Off under the name of your VPN connection.
Читайте также:  Linux shell scripting languages

More Information

  • Wired networking — Use a wired internet connection and set a static IP address.
  • Wireless networking — Connect to wireless networks, including hidden networks and networks created from phone tethering.

You can choose the displayed language by adding a language suffix to the web address so it ends with e.g. .html.en or .html.de.
If the web address has no language suffix, the preferred language specified in your web browser’s settings is used. For your convenience:
[ Change to English Language | Change to Browser’s Preferred Language ]

The material in this document is available under a free license, see Legal for details.
For information on contributing see the Ubuntu Documentation Team wiki page. To report errors in this documentation, file a bug.

Источник

Управление VPN подключениями из консоли Linux

В этой статье мы рассмотрим, как создать VPN подключение из консоли Linux и подключиться к удаленному VPN серверу из CLI. Отдельно рассмотрим, как создать L2TP и PPTP VPN подключения.

Как создать L2TP VPN подключение в Linux?

Вы можете использовать NetworkManager для создания VPN подключений L2TP из консоли Linux.

Для установки NetworkManager с поддержкой L2TP выполните команду:

  • В CentOS/RHEL/Fedora: # yum -y install NetworkManager-l2tp
  • Для установки в Ubuntu/Debian, нужно сначала добавить репозиторий:
    $ sudo add-apt-repository ppa:nm-l2tp/network-manager-l2tp
    $ sudo apt-get install network-manager-l2tp

установка network-manager-l2tp в linux

Для создания нового VPN подключения L2TP используется команда:

$ nmcli connection add connection.id [VPNConnectionName] con-name [VPNConnectionName] type VPN vpn-type l2tp ifname — connection.autoconnect no ipv4.method auto vpn.data «gateway = [ipv4], ipsec-enabled = yes, ipsec-psk = 0s»$(base64

  • [VPNConnectionName] — имя VPN соединения
  • [ipv4] — ip адрес VPN сервера L2TP/IPSEC
  • [PSK] — ключ PSK (Pre Shared Key)
  • [user] — имя пользователя VPN
  • [user-password] — пароль
Читайте также:  Install zip linux ubuntu

Настройки нового VPN подключения сохраняются в файл /etc/NetworkManager/system-connections/.

Вывести все подключения в NetworkManager:

Показать информацию о созданном VPN подключении:

$ nmcli c show id [VPNConnectionName]

Для Для подключения к VPN серверу из командной строки:к VPN серверу их командной строки:

$ nmcli c up [VPNConnectionName]

При подключении к удаленному VPN серверу может появится ошибка:

Error: Connection activation failed: Could not find source connection.
  • Проверьте логи journactl
  • Для физического интерфейса (например, ens33 ) задан шлюз по-умолчанию
  • Возможно на сервере используется интерфейс br0 , который не используется. Попробуйте удалить его

Чтобы завершить сессию VPN, выполните:

nmcli c down [VPNConnectionName]

Создаем PPTP VPN подключение в Linux

Для установки PPTP клиента VPN в Ubuntu/Debian, установите утилиту:

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

Добавьте следующее содержимое:

pty "pptp YOUR_VPN_SERVER --nolaunchpppd --debug" name VPNUsername password VPNPassword remotename PPTP require-mppe-128 require-mschap-v2 refuse-eap refuse-pap refuse-chap refuse-mschap noauth debug persist maxfail 0 defaultroute replacedefaultroute usepeerdns

Сохраните файл, нажав CTLR+X, Y -> Enter.

$ chmod 600 /etc/ppp/peers/PPTP

Чтобы подключится к PPTP VPN серверу, выполните:

Настройка SSTP VPN подключения в командной строке Linux

Вы можете настроить SSTP подключение к VPN серверу в Linux. В Ubuntu можно использовать пакет sstp для nmcli.

$ sudo add-apt-repository ppa:eivnaes/network-manager-sstp
$ sudo apt update
$ sudo apt install network-manager-sstp sstp-client

Для подключения к SSTP серверу используется команда:

$ sudo sstpc —cert-warn —save-server-route —user —password usepeerdns require-mschap-v2 noauth noipdefault nobsdcomp nodeflate

Можно сохранить настройки подключения к VPN серверу в текстовый файл:

remotename sstptest linkname sstptest ipparam sstptest pty "sstpc --ipparam sstptest --nolaunchpppd sstpvpn.vmblog.ru" name user1 plugin sstp-pppd-plugin.so sstp-sock /var/run/sstpc/sstpc-sstp-test usepeerdns require-mppe require-mschap-v2 refuse-eap refuse-pap refuse-chap refuse-mschap nobsdcomp nodeflate

Имя пользователя и пароль для аутентификации на VPN сервере нужно задать в файле /etc/ppp/chap-secrets

# Secrets for authentication using CHAP # client server secret IP addresses user1 * xxxxxx *

Теперь для подключения к SSTP серверу с помощью настроенного подключения, выполните:

Читайте также:  Комбинации клавиш линукс минт

Чтобы отправить весь трафик через VPN подключение, нужно добавить маршрут:

$ sudo route add default (обычно это устройствл ppp0 )

Или только трафик к определенным подсетям/хостам:

$ sudo route add -net 192.168.2.0/24 dev ppp0

Подключение к OpenVPN серверу из консоли Linux

Для установки пакета OpenVPN в Linux:

  • Debian, Ubuntu, Linux Mint, Kali Linux:
    $ sudo apt-get update && apt-get upgrade
    $ sudo apt-get install openvpn
  • RedHat, Fedora, CentOS, Oracle, Rocky Linux:
    # yum install epel-release –y
    # yum install openvpn –y

Для подключения к OpenVPN серверу вам понадобится файл конфигурации ovpn. Чтобы подключиться к VPN с помощью ovpn файла:

$ sudo openvpn —config /etc/openvpn/client.ovpn —daemon

Введите имя пользователя и пароль (если настроена AD аутентификация для OpenVPN).

Проверьте что VPN подключение установлено:

Чтобы завершить OpenVPN подключение, нажмите CTRL+C (если клиент запущен без параметра –daemon) или выполните команду:

Чтобы OpenVPN подключение автоматически устанавливалось при старте Linux, нужно создать отдельный юнит systemd:

$ sudo vi /lib/systemd/system/OpenVPNClientCorp.service

[Unit] Description=Hide.me OpenVPN Client Corp After=multi-user.target [Service] Type=idle ExecStart=/usr/sbin/openvpn --config /etc/openvpn/client.ovpn [Install] WantedBy=multi-user.target

Измените разрешения на файл:

$ sudo chmod 644 /lib/systemd/system/OpenVPNClientCorp.service

Добавьте юнит через systemctl

$ sudo systemctl daemon-reload
$ sudo systemctl enable OpenVPNClientCorp.service

Источник

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