64 lines
3.4 KiB
Plaintext
64 lines
3.4 KiB
Plaintext
# Description:
|
|
# This configuration allows you to connect an OPNsense or pfSense router at home and link it to a VPS IP.
|
|
# It uses a public IP to redirect traffic to different machines behind the VPS for security reasons rather than opening ports on your home router.
|
|
|
|
# Prerequisites:
|
|
# - Have a VPS server at OVH or Ionos with Debian
|
|
# - Install https://github.com/angristan/wireguard-install and generate a client
|
|
# - Know the network interface using the 'ip a' command and replace 'ens6' with the correct interface name
|
|
# - Know the public IP address or IP addresses of the clients
|
|
|
|
# Backup the current configuration before modifying it
|
|
# Perform this backup before any modification
|
|
# cp /etc/wireguard/wg0.conf /etc/wireguard/wg0.conf.bak
|
|
|
|
# Stopping the WireGuard service before modifying the configuration
|
|
# Make sure to stop the service before modifying the configuration
|
|
# sudo systemctl stop wg-quick@wg0
|
|
|
|
# Modify the WireGuard configuration
|
|
# Open the configuration file to modify it
|
|
# nano /etc/wireguard/wg0.conf
|
|
# Delete the section between 'PrivateKey = x' and '### Client opnsense'
|
|
# Replace 'your-port' and 'your-public-ip' with actual port and IP information
|
|
|
|
# WireGuard server side configuration
|
|
[Interface]
|
|
Address = 10.66.66.1/24, fd42:42:42::1/64
|
|
ListenPort = your-port
|
|
PrivateKey = x
|
|
|
|
# iptables rules to apply after setting up the WireGuard interface
|
|
PostUp = iptables -I INPUT -p udp --dport your-port -j ACCEPT # Replace 'your-port' with actual port number
|
|
PostUp = iptables -A FORWARD -i wg0 -o ens6 -j ACCEPT
|
|
PostUp = iptables -A FORWARD -i ens6 -o wg0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
|
PostUp = iptables -I FORWARD -i wg0 -s 10.66.66.0/24 -d 10.66.66.0/24 -j DROP
|
|
|
|
PostUp = iptables -t nat -A POSTROUTING -s 10.66.66.2/32 -o ens6 -j SNAT --to-source your-public-ip # NAT for outgoing traffic from the opnsense client
|
|
PostUp = iptables -t nat -A PREROUTING -i ens6 -d your-public-ip -p tcp --dport 80 -j DNAT --to-destination 10.66.66.2:80 # Redirect port 80 to the opnsense client
|
|
PostUp = iptables -t nat -A PREROUTING -i ens6 -d your-public-ip -p tcp --dport 443 -j DNAT --to-destination 10.66.66.2:443 # Redirect port 443 to the opnsense client
|
|
|
|
# iptables rules to remove when deleting the WireGuard interface
|
|
PostDown = iptables -D INPUT -p udp --dport your-port -j ACCEPT || true # Replace 'your-port' with actual port number
|
|
PostDown = iptables -D FORWARD -i wg0 -o ens6 -j ACCEPT || true
|
|
PostDown = iptables -D FORWARD -i ens6 -o wg0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT || true
|
|
PostDown = iptables -t nat -D POSTROUTING -s 10.66.66.2/32 -o ens6 -j SNAT --to-source your-public-ip || true
|
|
PostDown = iptables -t nat -D PREROUTING -i ens6 -d your-public-ip -p tcp --dport 80 -j DNAT --to-destination 10.66.66.2:80 || true
|
|
PostDown = iptables -t nat -D PREROUTING -i ens6 -d your-public-ip -p tcp --dport 443 -j DNAT --to-destination 10.66.66.2:443 || true
|
|
|
|
### Client opnsense Configuration
|
|
[Peer]
|
|
PublicKey = x
|
|
PresharedKey = x
|
|
AllowedIPs = 10.66.66.2/32, fd42:42:42::2/128
|
|
|
|
# Restart the WireGuard service after modifying the configuration
|
|
# sudo systemctl restart wg-quick@wg0
|
|
# sudo systemctl status wg-quick@wg0
|
|
|
|
# OPNsense configuration:
|
|
# Follow the steps described in the OPNsense documentation:
|
|
# https://docs.opnsense.org
|
|
# Configure port forwarding from the OPNsense router to the local IP of the WireGuard client
|
|
# For example, forward the port from 192.168.1.x to [local_ip_of_wireguard_client]
|