/etc/swanctl/
The /etc/swanctl/ directory is used to store configuration files for the swanctl command-line utility, which is part of the strongSwan VPN suite. This directory typically contains various configuration files, including swanctl.conf for connection definitions and additional files for certificates, private keys, and other settings related to IPsec and IKEv2 configurations.
Purpose
The /etc/swanctl/ directory centralizes the configuration and management of IPsec and IKEv2 connections, secrets, and related settings for strongSwan. This modular configuration approach allows for organized and maintainable VPN settings.
Common Files and Subdirectories
swanctl.conf: The main configuration file for defining connection profiles, secrets, and address pools.
certs/: Directory for storing certificate files.
private/: Directory for storing private key files.
conf.d/: Directory for additional configuration snippets, if modular configurations are used.
Example Directory Structure
/etc/swanctl/
├── certs/
│ └── mycert.pem
├── private/
│ └── mykey.pem
├── conf.d/
│ ├── connection1.conf
│ └── connection2.conf
└── swanctl.confExample Configuration Files
/etc/swanctl/swanctl.conf
/etc/swanctl/swanctl.confThis file defines the main connection profiles, secrets, and pools.
connections {
myvpn {
version = 2
local_addrs = 192.0.2.1
remote_addrs = 192.0.2.2
local {
auth = pubkey
certs = certs/mycert.pem
id = "CN=myvpnserver"
}
remote {
auth = pubkey
certs = certs/remote_cert.pem
id = "CN=myvpnclient"
}
children {
net {
local_ts = 10.0.0.0/24
remote_ts = 0.0.0.0/0
dpd_action = restart
esp_proposals = aes256-sha256-modp2048
}
}
}
}
secrets {
private {
file = private/mykey.pem
}
}
pools {
mypool {
addrs = 10.3.0.0/24
dns = 10.3.0.1
}
}/etc/swanctl/certs/mycert.pem
/etc/swanctl/certs/mycert.pemThis directory holds the local certificate used for authentication.
-----BEGIN CERTIFICATE-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr6Vm
...
-----END CERTIFICATE-----/etc/swanctl/private/mykey.pem
/etc/swanctl/private/mykey.pemThis directory contains the private key corresponding to the certificate.
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDX4
...
-----END PRIVATE KEY-----Managing the Configuration
Loading the Configuration
To apply the configuration defined in swanctl.conf, use the following command:
sudo swanctl --load-allThis command loads connections, secrets, and pools defined in the configuration files.
Common swanctl Commands
List all connections:
sudo swanctl --list-connsInitiate a connection:
sudo swanctl --initiate --child myvpnTerminate a connection:
sudo swanctl --terminate --child myvpnCheck the status of connections:
sudo swanctl --list-sas
Conclusion
The /etc/swanctl/ directory and its configuration files are crucial for managing strongSwan VPN connections. By organizing configuration into modular files, administrators can maintain a clear and manageable VPN setup. Properly configuring swanctl.conf and storing related certificates and keys in appropriate subdirectories ensures a secure and efficient VPN infrastructure. Always remember to load the configuration after making changes and use swanctl commands to manage the VPN connections effectively.
Last updated