Ol VPN
Ol VPN
Ol VPN
F45242-08
January 2024
Oracle Linux Configuring Virtual Private Networks,
F45242-08
iii
Preface
Preface
Oracle Linux: Configuring Virtual Private Networks describes how to use virtual private
networks (VPNs) in Oracle Linux to deploy tunneled connections to remote systems.
Documentation License
The content in this document is licensed under the Creative Commons Attribution–
Share Alike 4.0 (CC-BY-SA) license. In accordance with CC-BY-SA, if you distribute
this content or an adaptation of it, you must provide attribution to Oracle and retain the
original copyright notices.
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user
interface elements associated with an
action, or terms defined in text or the
glossary.
italic Italic type indicates book titles, emphasis,
or placeholder variables for which you
supply particular values.
monospace Monospace type indicates commands
within a paragraph, URLs, code in
examples, text that appears on the screen,
or text that you enter.
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the Oracle
Accessibility Program website at https://www.oracle.com/corporate/accessibility/.
For information about the accessibility of the Oracle Help Center, see the Oracle
Accessibility Conformance Report at https://www.oracle.com/corporate/accessibility/
templates/t2-11535.html.
iv
Preface
v
1
About Virtual Private Networks
Note:
This document includes content that was tested against Oracle Linux 8 and Oracle
Linux 9, but applies to most Oracle Linux releases, and might also apply to other
distributions.
VPNs are used to enable remote access between endpoints and provide site-to-site
connections that simulate a larger network beyond the limitations of a deployed physical
network. Encryption is applied to secure the traffic traversing the tunneled connections.
Implementations of VPNs have varied over time through the release of different VPN
protocols, technologies, and applications. Oracle Linux supports two VPN technologies:
IPsec OpenVPN implementation in Libreswan and WireGuard®.
WireGuard differs from OpenVPN in that OpenVPN uses certificates for identification and
encryption. WireGuard uses public key encryption for those tasks. Secure key generation and
management is handled in the background, and an option is available to preshare a key for
an added layer of security.
For more information, see the following resources:
• WireGuard: https://www.wireguard.com
• Libreswan: https://libreswan.org
1-1
2
Configuring a VPN by Using WireGuard
WireGuard is a cross-platform technology that enables you to create a VPN setup that's
simple, fast, but secure through its implementation of the latest cryptography.
Note:
WireGuard is supported beginning with Unbreakable Enterprise Kernel Release 6
Update 3. Ensure that the system is upgraded to this release or later before
proceeding to the steps in this chapter. For more information, see Unbreakable
Enterprise Kernel Release 6 Update 3: Release Notes (5.4.17-2136).
Installing WireGuard
To configure a VPN with WireGuard, download the package with the following command:
You must install WireGuard on the server and all its clients.
Configuring WireGuard
For simplicity, the following sections describe how to deploy WireGuard by using two hosts as
examples. One host functions as the VPN server while the other is a client.
To use WireGuard, you need the following requirements:
• IP addresses of both hosts. Use the ip addr sh command to obtain this information.
For the procedures that follow, the IP address of the server is 10.0.0.1 and the IP address
of the client is 10.0.0.2.
• Private IP addresses to be assigned to the WireGuard interfaces of both hosts. For the
procedures that follow, the private IP address of the server is 192.168.2.1 and the private
IP address of the client is 192.168.2.2.
• Name of the WireGuard interface. For the procedures that follow, the Wireguard interface
name of both server and client is wg0.
• Console connections to the client.
Instructions for setting up console connections is outside the scope of this
documentation. To use a VNC server for remote connections, see https://
docs.oracle.com/en/learn/install-vnc-oracle-linux/#introduction. If you're using an instance
in Oracle Cloud Infrastructure, see https://docs.oracle.com/iaas/Content/Compute/
References/serialconsole.htm#Instance_Console_Connections.
On the server
2-1
Chapter 2
Configuring WireGuard
net.ipv4.ip_forward = 1
sudo sysctl -p
You can disregard the error messages that might appear about the command not
being able to perform stat.
3. Create a directory where you can store the WireGuard key pair, for example:
mkdir ~/.wireguard
cd ~/.wireguard
umask 077
5. Obtain the server's private and public keys and store them in a temporary storage.
cat ~/.wireguard/privatekey
cat ~/.wireguard/publickey
On the client
1. Create a directory where you can store the WireGuard key pair, for example:
mkdir ~/.wireguard
cd ~/.wireguard
umask 077
3. Obtain the client's private and public keys and store them in a temporary storage.
cat ~/.wireguard/privatekey
cat ~/.wireguard/publickey
[Interface]
Address = 192.168.2.2/24
SaveConfig = true
ListenPort = 60477
2-2
Chapter 2
Enabling the WireGuard Tunnel
[Peer]
PublicKey = server's public key
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 10.0.0.1:51820
On the server
1. Edit the /etc/wireguard/wg0.conf file to contain the following:
[Interface]
Address = 192.168.2.1/24
SaveConfig = true
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A
POSTROUTING -o eno1 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D
POSTROUTING -o eno1 -j MASQUERADE
ListenPort = 51820
PrivateKey = server's private key
[Peer]
PublicKey = client's public key
AllowedIPs = 192.168.2.2/32
Endpoint = 10.0.0.2:60477
Note:
In the PostUp and PostDown lines of the example, the server's interface name is
eno1. Ensure that you specify the correct interface name of your server for
those same lines. To display the server's IP interface, run the ip addr sh
command.
wg-quick up wg0
2-3
Chapter 2
Enabling the WireGuard Tunnel
sudo wg
interface: wg0
public key: server's public key
private key: (hidden)
listening port: 51820
wg-quick up wg0
sudo wg
interface: wg0
public key: client's public key
private key: (hidden)
listening port: 60477
fwmark: 0xca6c
2-4
Chapter 2
Testing the WireGuard Tunnel
You can use other commands to check the tunnel information, such as ip addr sh and ip
link, for example:
ip addr sh
...
3: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 8920 qdisc noqueue state UNKNOWN
group default
qlen 1000 link/none
inet 192.168.2.1/24 scope global wg0
valid_lft forever preferred_lft forever
ip link
...
3: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 8920 qdisc noqueue state UNKNOWN
mode DEFAULT group
default qlen 1000 link/none
ping -c 3 192.168.2.1
ping -c 3 192.168.2.1
sudo wg
interface: wg0
public key: client's public key
private key: (hidden)
listening port: 60477
fwmark: 0xca6c
2-5
Chapter 2
Shutting Down the WireGuard Tunnel
The handshake and transfer output show the traffic in the tunneled connection.
If communications between the server and the client can't be established, check if the
firewall might be blocking access to the ports that have been set up for WireGuard.
You might need to open the ports to link both server and client. For example, you
would type the following commands on the server:
After shutting down, you can optionally check the status of the tunnels by using one of
the commands that have been provided elsewhere in this document, such as wg, ip
addr, or ip link.
2-6
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.
Installing Libreswan
To configure an IPsec VPN with Libreswan, download the package as follows:
1. Ensure that the AppStream repository is enabled.
2. Install Libreswan.
The command generates an RSA key pair with a specific ckaid value.
You must run the command on both hosts.
3-1
Chapter 3
Configuring IPsec VPN
Note:
Typically in libreswan, the left designation refers to the local host, while
the right designation refers to the remote host. However, because both
hosts are peers, the designations can be used interchangeably.
# rsakey AwEAAaxdf
leftrsasigkey=0sAwEAAaxdfaCPrZ72pAm1kjvhAQHHLn3Wg3gAu1Z0U+3FWeh7FN+b
Htfy
...
9f8=
# rsakey AwEAAb1nC
rightrsasigkey=0sAwEAAdSSYrNO2QOY8RXgLlJZilBokPb9cFzCbU+VYY7eFcoZMmV
WPVI
...
zu+/7BE5kjXHAAI1fvYha+CFbuh6KYAlpoHvX81ALusfQs+6wwTsde5jlfcrXNlqX
conn tunnel-name
leftid=@host1-tunnel-id
left=host1-IPaddress
3-2
Chapter 3
Configuring IPsec VPN
leftrsasigkey=host1-leftrsasigkey
rightid=@host2-tunnel-id
right=host2-IPaddress
rightrsasigkey=host2-rightrsasigkey
authby=rsasig
For more information about the configuration file and other parameters you can set, see
the ipsec.conf(5) manual page.
5. Restart the IPsec service.
6. Start libreswan.
9. Start the tunnel automatically when the ipsec service is started by adding the following
line to the configuration file:
auto=start
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.
3-3
Chapter 3
Verifying the Status of VPN Services
1. Create a copy of the host to host configuration file to serve as the configuration file
for the site to site connection, for example:
conn subnet-name
also=tunnel-name
leftsubnet=subnet1-IP
rightsubnet=subnet2-IP
auto=start
Note:
The subnets can be in CIDR notation.
3-4
Chapter 3
Verifying the Status of VPN Services
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:
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.
3-5