3 Configuring a VPN by Using Libreswan
Libreswan is the software that implements VPN by using the IPsec protocol and the Internet Key Exchange (IKE) standards.
Configuring IPsec VPN
VPN configurations range from basic setups such as one between hosts to complex ones that involve entire sites.
Creating a Host to Host Connection
Regardless of the types of VPN connections that you want to configure, a common but important step involves obtaining RSA keys that would enable connections between endpoints.
On a host-to-host connection, for example, do the following:
Creating a Site to Site Connection
A VPN connection between sites means that a connection is established between two networks. When you configure a pair of hosts for this type of connection, the hosts effectively become gateways through which traffic can enter or exit to access other hosts in the network.
Note:
You can configure a Site-to-Site VPN between your on-premises network and an Oracle Cloud Infrastructure virtual cloud network (VCN) using Libreswan. Steps for setting up a Site-to-Site VPN to OCI are described in the Libreswan Oracle Cloud Infrastructure documentation.To proceed with configuring a connection between sites, follow these steps:
Verifying the Status of VPN Services
To check if the ipsec
service is running,
type this command:
sudo systemctl status ipsec
ipsec.service - Internet Key Exchange (IKE) Protocol Daemon for IPsec
Loaded: loaded (/usr/lib/systemd/system/ipsec.service; enabled; vendor prese>
Active: active (running) since Mon 2021-04-26 02:27:39 PDT; 7h ago
Docs: man:ipsec(8)
man:pluto(8)
man:ipsec.conf(5)
...
To test the tunnel connections, install the tcpdump
utility to monitor
network traffic.
Run the following command on one of the peers to monitor traffic explicitly on the interface. The utility tracks Encapsulated Security Payload (ESP) packets and traffic traversing the UDP ports 500 and 4500 that are used by the ipsec service:
tcpdump -n -i interface esp or udp port 500 or udp port 4500
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on interface, link-type EN10MB (Ethernet), capture size 262144 bytes
10:05:53.578884 IP 10.147.25.195 > 10.147.25.196: ESP(spi=0xcba1dd78,seq=0x2325), length 96
10:05:53.579353 IP 10.147.25.196 > 10.147.25.195: ESP(spi=0x979dcdbe,seq=0x2325), length 124
10:05:56.585128 IP 10.147.25.195 > 10.147.25.196: ESP(spi=0xcba1dd78,seq=0x2326), length 96
10:05:56.585527 IP 10.147.25.196 > 10.147.25.195: ESP(spi=0x979dcdbe,seq=0x2326), length 124
...
The utility first reports traffic that's generated by the peers exchanging keys.
While the tcpdump
is running, go to the other peer and perform a network
operation, such as a network ping
, to the first host. The host that's
monitoring the traffic would report network activity over the VPN from the second peer.
Press Ctrl+C to end the operations on both peers.
To check the IPSec security policies and rules that are present in the kernel, run the following commands:
-
sudo ip xfrm policy
The
ip xfrm policy
command displays information on security policies present in the kernel. Security policies determine which network traffic is to be transformed and protected by IPSec. See theip-xfrm(8)
manual page for more information. -
sudo ip xfrm state
The
ip xfrm
state command displays information on security associations present in the kernel. Security associations consist of parameters that determine, for example, the way the traffic is to be encrypted and authenticated. See theip-xfrm(8)
manual page for more information.