IPIP IPsec VPN tunnel between Linux machine and Mikrotik behind NAT provider

Linux: Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-91-generic x86_64)

  • Eth0 1.1.1.1/32 external IP
  • ipip-ipsec0 192.168.0.1/30 will be our tunnel

Miktoik: CCR 1009, RouterOS 6.46.5

  • Eth0 10.0.0.2/30 internal IP from the provider. The provider's external NAT IP is dynamic.
  • ipip-ipsec0 192.168.0.2/30 will be our tunnel

We will set up an IPsec tunnel on a Linux machine using racoon. I will not describe the details, there is a good article Ρƒ vvpoloskin.

Install the required packages:

sudo install racoon ipsec-tools

We configure racoon, it will conditionally act as an ipsec server. Since mikrotik in main mode cannot transmit an additional client identifier, and the external ip address through which it connects to Linux is dynamic, it will not work to use a preshared key (password authorization), since the password must be matched either with the ip address of the connecting host, or with identifier.

We will use authorization by RSA keys.

The racoon daemon uses RSA keys, while mikrotik uses PEM keys. If you generate keys with the plainrsa-gen utility that comes with racoon, then you will not be able to convert the public key for Mikrotika to PEM format with it - it only converts in one direction: PEM to RSA. The key generated by plainrsa-gen could not be read by either openssl or ssh-keygen, so they will also fail to convert.

We will generate a PEM key with openssl and then convert it for racoon with plainrsa-gen:

#  Π“Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΠ΅ΠΌ ΠΊΠ»ΡŽΡ‡
openssl genrsa -out server-name.pem 1024
# ИзвлСкаСм ΠΏΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹ΠΉ ΠΊΠ»ΡŽΡ‡
openssl rsa -in server-name.pem -pubout > server-name.pub.pem
# ΠšΠΎΠ½Π²Π΅Ρ€Ρ‚ΠΈΡ€ΡƒΠ΅ΠΌ
plainrsa-gen -i server-name.pem -f server-name.privet.key
plainrsa-gen -i server-name.pub.pem -f server-name.pub.key

We put the received keys in the folder: /etc/racoon/certs/server. Do not forget to set the owner of the user on whose behalf the racoon daemon is launched (usually root) to 600 rights.

I will describe the mikrotik setting when connecting via WinBox.

Upload the server-name.pub.pem key to mikrotik: Menu "Files" - "Upload".

Open the section "IP" - "IP sec" - tab "Keys". Now we generate the keys - the β€œGenerate Key” button, then we export the mikrotika public key β€œExpor Pub. Key", you can download it from the "Files" section, right-click on the file - "Download".

We import the racoon public key, β€œImport”, in the drop-down list of the β€œFile name” field, look for the server-name.pub.pem we loaded earlier.

mikrotik public key needs to be converted

plainrsa-gen -i mikrotik.pub.pem -f mikrotik.pub.key

and put it in the /etc/racoon/certs folder without forgetting the owner and rights.

racoon config with comments: /etc/racoon/racoon.conf

log info; # Π£Ρ€ΠΎΠ²Π΅Π½ΡŒ логирования, ΠΏΡ€ΠΈ ΠΎΡ‚Π»Π°Π΄ΠΊΠ΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Debug ΠΈΠ»ΠΈ Debug2.

listen {

    isakmp 1.1.1.1 [500]; # АдрСс ΠΈ ΠΏΠΎΡ€Ρ‚, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ ΡΠ»ΡƒΡˆΠ°Ρ‚ΡŒ Π΄Π΅ΠΌΠΎΠ½.
    isakmp_natt 1.1.1.1 [4500]; # АдрСс ΠΈ ΠΏΠΎΡ€Ρ‚, Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ Π±ΡƒΠ΄Π΅Ρ‚ ΡΠ»ΡƒΡˆΠ°Ρ‚ΡŒ Π΄Π΅ΠΌΠΎΠ½ для ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ² Π·Π° NAT.
    strict_address; # Π’Ρ‹ΠΏΠΎΠ»Π½ΡΡ‚ΡŒ ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ привязки ΠΊ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΌ Π²Ρ‹ΡˆΠ΅ IP.
}

path certificate "/etc/racoon/certs"; # ΠŸΡƒΡ‚ΡŒ Π΄ΠΎ ΠΏΠ°ΠΏΠΊΠΈ с сСртификатами.

remote anonymous { # БСкция, Π·Π°Π΄Π°ΡŽΡ‰Π°Ρ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ для Ρ€Π°Π±ΠΎΡ‚Ρ‹ Π΄Π΅ΠΌΠΎΠ½Π° с ISAKMP ΠΈ согласования Ρ€Π΅ΠΆΠΈΠΌΠΎΠ² с ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰ΠΈΠΌΠΈΡΡ хостами. Π’Π°ΠΊ ΠΊΠ°ΠΊ IP, с ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ Mikrotik, динамичСский, Ρ‚ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ anonymous, Ρ‡Ρ‚ΠΎ Ρ€Π°Π·Ρ€Π΅ΡˆΠ°Π΅Ρ‚ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ с любого адрСса. Если IP Ρƒ хостов статичСский, Ρ‚ΠΎ ΠΌΠΎΠΆΠ½ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½Ρ‹ΠΉ адрСс ΠΈ ΠΏΠΎΡ€Ρ‚.

    passive on; # Π—Π°Π΄Π°Π΅Ρ‚ "сСрвСрный" Ρ€Π΅ΠΆΠΈΠΌ Ρ€Π°Π±ΠΎΡ‚Ρ‹ Π΄Π΅ΠΌΠΎΠ½Π°, ΠΎΠ½ Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΡ‹Ρ‚Π°Ρ‚ΡŒΡΡ ΠΈΠ½ΠΈΡ†ΠΈΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ.
    nat_traversal on; # Π’ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ использованиС Ρ€Π΅ΠΆΠΈΠΌΠ° NAT-T для ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ², Ссли ΠΎΠ½ΠΈ Π·Π° NAT. 
    exchange_mode main; # Π Π΅ΠΆΠΈΠΌ ΠΎΠ±ΠΌΠ΅Π½Π° ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΡ, Π² Π΄Π°Π½Π½ΠΎΠΌ случаС ---согласованиС.
    my_identifier address 1.1.1.1; # Π˜Π΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΡ†ΠΈΡ€ΡƒΠ΅ΠΌ наш linux хост ΠΏΠΎ Π΅Π³ΠΎ ip адрСсу.
    certificate_type plain_rsa "server/server-name.priv.key"; # ΠŸΡ€ΠΈΠ²Π°Ρ‚Π½Ρ‹ΠΉ ΠΊΠ»ΡŽΡ‡ сСрвСра.
    peers_certfile plain_rsa "mikrotik.pub.key"; # ΠŸΡƒΠ±Π»ΠΈΡ‡Π½Ρ‹ΠΉ ΠΊΠ»ΡŽΡ‡ Mikrotik.

    proposal_check claim; # Π Π΅ΠΆΠΈΠΌ согласования ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ISAKMP туннСля. Racoon Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ значСния ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰Π΅Π³ΠΎΡΡ хоста (ΠΈΠ½ΠΈΡ†ΠΈΠ°Ρ‚ΠΎΡ€Π°) для срока дСйствия сСссии                   ΠΈ Π΄Π»ΠΈΠ½Ρ‹ ΠΊΠ»ΡŽΡ‡Π°, Ссли Π΅Π³ΠΎ срок дСйствия сСссии большС, ΠΈΠ»ΠΈ Π΄Π»ΠΈΠ½Π° Π΅Π³ΠΎ ΠΊΠ»ΡŽΡ‡Π° ΠΊΠΎΡ€ΠΎΡ‡Π΅, Ρ‡Π΅ΠΌ Ρƒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Ρ‚ΠΎΡ€Π°. Если срок дСйствия сСссии ΠΊΠΎΡ€ΠΎΡ‡Π΅, Ρ‡Π΅ΠΌ Ρƒ ΠΈΠ½ΠΈΡ†ΠΈΠ°Ρ‚ΠΎΡ€Π°, racoon ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ собствСнноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ срока дСйствия сСссии ΠΈ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΡ‚ΠΏΡ€Π°Π²Π»ΡΡ‚ΡŒ сообщСниС RESPONDER-LIFETIME.
    proposal { # ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ISAKMP туннСля.

        encryption_algorithm aes; # ΠœΠ΅Ρ‚ΠΎΠ΄ ΡˆΠΈΡ„Ρ€ΠΎΠ²Π°Π½ΠΈΡ ISAKMP туннСля.
        hash_algorithm sha512; # Алгоритм Ρ…Π΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΡ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹ΠΉ для ISAKMP туннСля.
        authentication_method rsasig; # Π Π΅ΠΆΠΈΠΌ Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ для ISAKMP туннСля - ΠΏΠΎ RSA ΠΊΠ»ΡŽΡ‡Π°ΠΌ.
        dh_group modp2048; # Π”Π»ΠΈΠ½Π° ΠΊΠ»ΡŽΡ‡Π° для Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠ° Π”ΠΈΡ„Ρ„ΠΈ-Π₯Π΅Π»Π»ΠΌΠ°Π½Π° ΠΏΡ€ΠΈ согласовании ISAKMP туннСля.
        lifetime time 86400 sec; ВрСмя дСйствия сСссии.
    }

    generate_policy on; # АвтоматичСскоС созданиС ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ ΠΈΠ· запроса, ΠΏΡ€ΠΈΡˆΠ΅Π΄ΡˆΠ΅Π³ΠΎ ΠΎΡ‚ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°ΡŽΡ‰Π΅Π³ΠΎΡΡ хоста.
}

sainfo anonymous { # ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ, anonymous - ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ Π±ΡƒΠ΄ΡƒΡ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Π½Ρ‹ ΠΊΠ°ΠΊ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ. Для Ρ€Π°Π·Π½Ρ‹Ρ… ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ², ΠΏΠΎΡ€Ρ‚ΠΎΠ², ΠΏΡ€ΠΎΡ‚ΠΎΠΊΠΎΠ»ΠΎΠ² ΠΌΠΎΠΆΠ½ΠΎ              Π·Π°Π΄Π°Π²Π°Ρ‚ΡŒ Ρ€Π°Π·Π½Ρ‹Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹, сопоставлСниС происходит ΠΏΠΎ ip адрСсам, ΠΏΠΎΡ€Ρ‚Π°ΠΌ, ΠΏΡ€ΠΎΡ‚ΠΎΠΊΠΎΠ»Π°ΠΌ.

    pfs_group modp2048; # Π”Π»ΠΈΠ½Π° ΠΊΠ»ΡŽΡ‡Π° для Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠ° Π”ΠΈΡ„Ρ„ΠΈ-Π₯Π΅Π»Π»ΠΌΠ°Π½Π° для ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ.
    lifetime time 28800 sec; # Π‘Ρ€ΠΎΠΊ дСйствия ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ.
    encryption_algorithm aes; # ΠœΠ΅Ρ‚ΠΎΠ΄ ΡˆΠΈΡ„Ρ€ΠΎΠ²Π°Π½ΠΈΡ ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ.
    authentication_algorithm hmac_sha512; # Алгоритм Ρ…Π΅ΡˆΠΈΡ€ΠΎΠ²Π°Π½ΠΈΡ, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹ΠΉ для Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ ESP Ρ‚ΡƒΠ½Π½Π΅Π»Π΅ΠΉ.
    compression_algorithm deflate; # Π‘ΠΆΠΈΠΌΠ°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π΄Π°Π²Π°Π΅ΠΌΡ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅, Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌ сТатия прСдлагаСтся Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ΄ΠΈΠ½.
}

mikrotik config

We return to the section "IP" - "IPsec"

Profiles Tab
Parameter
Value

Name
At your discretion (default default)

Hash Algorithm
sha512

Encryption Algorithm
aes-128

D.H. Group
modp2048

Proposhal_check
claim

Lifetime
1d 00:00:00

NAT Traversal
true (tick)

DPD
120

DPD maximum failure
5

Peers tab
Parameter
Value

Name
At your discretion (hereinafter MyPeer)

Address
1.1.1.1 (IP linux machines)

Local address
10.0.0.2 (IP WAN interface mikrotik)

Profile
default

Exchange Mode
main

passive
false

Send INITIAL_CONTACT
true

Proposal Tab
Parameter
Value

Name
At your discretion (hereinafter MyPeerProposal)

Auth. Algorithms
sha512

Encr. Algorithms
aes-128-cbc

Lifetime
08:00:00

PFS Group
modp2048

Identities tab
Parameter
Value

Peer
MyPeer

Atuh. method
rsa key

Key
mikrotik.privet.key

remote key
server-name.pub.pem

Policy Template Group
default

Notrack Chain
is empty

My ID Type
auto

Remote ID Type
auto

Match By
remote id

Mode Configuration
is empty

Generate Policy
No.

Policies - General Tab
Parameter
Value

Peer
MyPeer

Tunnels
true

src. Address
192.168.0.0/30

Dest. address
192.168.0.0/30

Protocol
255 (all)

template
false

Policies - Action Tab
Parameter
Value

Action
encrypt

Level
require

IPsec Protocols
esp

Proposal
MyPeerProposal

Most likely, you, like me, have snat / masquerade configured on the WAN interface, this rule needs to be adjusted so that outgoing ipsec packets go to our tunnel:
Go to the "IP" - "Firewall" section.
Tab "NAT", open our snat/masquerade rule.

Advanced tab
Parameter
Value

IPsec Policy
out: none

Restarting the racoon daemon

sudo systemctl restart racoon

If racoon does not start when restarting, then there is an error in the config, in the syslog racoon displays information about the line number in which the error was found.

The racoon daemon, when the OS boots, starts before raising the network interfaces, and we specified the strict_address option in the listen section, it is necessary to add the racoon unit to the systemd file
/lib/systemd/system/racoon.service, to the [Unit] section, After=network.target line.

Now our ipsec tunnels should go up, we look at the output:

sudo ip xfrm policy

src 192.168.255.0/30 dst 192.168.255.0/30 
    dir out priority 2147483648 
    tmpl src 1.1.1.1 dst "IP NAT Ρ‡Π΅Ρ€Π΅Π· ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ mikrotik"
        proto esp reqid 0 mode tunnel
src 192.168.255.0/30 dst 192.168.255.0/30 
    dir fwd priority 2147483648 
    tmpl src "IP NAT Ρ‡Π΅Ρ€Π΅Π· ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ mikrotik" dst 1.1.1.1
        proto esp reqid 0 mode tunnel
src 192.168.255.0/30 dst 192.168.255.0/30 
    dir in priority 2147483648 
    tmpl src "IP NAT Ρ‡Π΅Ρ€Π΅Π· ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ mikrotik" dst 1.1.1.1
        proto esp reqid 0 mode tunnel

If the tunnels are not up, see syslog, or journalctl -u racoon.

Now you need to configure L3 interfaces so that traffic can be routed. There are different options, we will use IPIP, since mikrotik supports it, I would use vti, but, unfortunately, it has not yet been implemented in mikrotik. It differs from IPIP in that it can additionally encapsulate multicast and put labels (fwmark) on packets by which they can be filtered in iptables and iproute2 (policy-based routing). If you need maximum functionality, then, for example, GRE. But do not forget that for additional functionality we pay a big overhead.

Translation of a good overview of tunnel interfaces can be viewed here.

On Linux:

# Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ интСрфСйс
sudo ip tunnel add ipip-ipsec0 local 192.168.255.1 remote 192.168.255.2 mode ipip
# АктивируСм
sudo ip link set ipip-ipsec0 up
# НазначаСм адрСс
sudo ip addr add 192.168.255.1/30 dev ipip-ipsec0

Now you can add routes for networks for mikrotik

sudo ip route add A.B.C.D/Prefix via 192.168.255.2

In order for our interface and routes to rise after a reboot, we need to describe the interface in /etc/network/interfaces and add routes in post-up there, or write everything in one file, for example, /etc/ipip-ipsec0.conf and pull it through post-up, don't forget about file owner, permissions and make it executable.

Under the cut is an example file

#!/bin/bash
ip tunnel add ipip-ipsec0 local 192.168.255.1 remote 192.168.255.2 mode ipip
ip link set ipip-ipsec0 up
ip addr add 192.168.255.1/30 dev ipip-ipsec0

ip route add A.B.C.D/Prefix via 192.168.255.2

On Mikrotik:

Section "Interfaces", add a new interface "IP tunnel":

Tab "IP tunnel" - "General"
Parameter
Value

Name
At your discretion (hereinafter referred to as IPIP-IPsec0)

MTU
1480 (if not specified, then mikrotik starts cutting mtu to 68)

Local address
192.168.0.2

remote address
192.168.0.1

IPsec Secret
Deactivate the field (otherwise a new Peer will be created)

keepalive
Deactivate the field (otherwise the interface will be constantly turned off, since mikrotika has some kind of its own format for these packages and does not work with linux)

DSCP
Inherit

Don't Fragment
No.

Clamp TCP MSS
true

Allow Fast Path
true

Section "IP" - "Addresses", add the address:

Parameter
Value

Address
192.168.0.2/30

Interface
IPIP-IPsec0

Now you can add routes on the network behind the linux machine, when adding a route, gateway will be our IPIP-IPsec0 interface.

PS

Since our linux server is transit, it makes sense to set the Clamp TCP MSS parameter for ipip interfaces on it:

create a file /etc/iptables.conf with the following content:

*mangle
-A POSTROUTING -o ipip+ -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
COMMIT

and in /etc/network/interfaces
post-up iptables-restore < /etc/iptables.conf

On the network behind mikrotik, nginx works for me (ip 10.10.10.1), we make it available from the Internet, add it to /etc/iptables.conf:

*nat
-A PREROUTING -d 1.1.1.1/32 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.10.10.1
#На mikrotik, Π² Ρ‚Π°Π±Π»ΠΈΡ†Π΅ mangle, Π½Π°Π΄ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΏΡ€Π°Π²ΠΈΠ»ΠΎ route с Π½Π°Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ΠΌ 192.168.0.1 для ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ² с адрСсом источника 10.10.10.1 ΠΈ ΠΏΠΎΡ€Ρ‚ΠΎΠ² 80, 443.

# Π’Π°ΠΊ ΠΆΠ΅ Π½Π° linux Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ OpenVPN сСрвСр 172.16.0.1/24, для ΠΊΠ»ΠΈΠ΅Π½Ρ‚ΠΎΠ² ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ΠΊ Π½Π΅ΠΌΡƒ Π² качСствС шлюза Π΄Π°Π΅ΠΌ доступ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π½Π΅Ρ‚
-A POSTROUTING -s 172.16.0.0/24 -o eth0 -j SNAT --to-source 1.1.1.1
COMMIT 

Don't forget to add the appropriate permissions to iptables if you have packet filters enabled.

Be healthy!

Source: habr.com

Add a comment