Jump to content
Not connected, Your IP: 3.145.154.106

Leaderboard


Popular Content

Showing content with the highest reputation on 08/14/24 in all areas

  1. 1 point
    Sj0rs

    HOWTO: OPNsense and Wireguard to AirVPN

    This HOWTO describes how to connect to AirVPN with a Wireguard VPN tunnel from OPNsense. This is the first draft of this howto, i might add (more) screenshots later on. Version: 0.1 Date: 20231029 What we are going to achieve We'll create a single Wireguard VPN Tunnel, IPv4 Only. Traffic to the tunnel will be NATted Requirements OPNsense firewall is up-and-running and updated. This howto is based on version 23.7.7_1 You have basic knowledge on using OPNsense i.e. firewall rules, NAT, routing, gateways and aliases. AirVPN Premium Access Step 1. Information gathering We'll grab some info that we need to configure the Wireguard Tunnel. Go to the Client Area. Got to VPN Devices. Add a device or edit your existing device. Note your Public Key and IPv4 under the heading "Wireguard" Go back to the Client Aerea. Go to Config Generator Select "router" under "Choose your OS" Select "Wireguard under "Choose protocols" Select your country under "By Countries". I selected Netherlands Scroll way down and download your config. This is an example of a Wireguard config: (the keys and IP are random and will not work, use your own) [Interface] Address = 10.45.95.123/32 PrivateKey = X72xgdx23XDomnSXmcy#S4Jc#9Y5G*vU$wg^n499yn6 MTU = 1320 DNS = 10.128.0.1 [Peer] PublicKey = VTSQ77Uk4^&RY4h%S$#9h8PR2T&xyya&yPTtk6oD^m$ PresharedKey = b7&&7bntmCS5q%&4J*mSKBAUvV4XEqHerwscvbappXQ Endpoint = nl3.vpn.airdns.org:1637 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 15 Step 2. Create the Tunnel configuration Peer configuration: in OPNsense go to VPN|Wireguard|Settings|Peers. Create a peer with the following information: Name: wg_airvpn_<country code>. mine is called wg_airvpn_nl Public key: <PublicKey under heading [Peer] of your generated WG Config> Pre-shared key <presharedKey under heading [Peer] of your generated WG Config> Allowed IP's: 0.0.0.0/0 Endpoint Address: <Endpoint under heading [Peer] of your generated WG Config> Endpoint port: 1637 (default port) Keepalive interval: 15 (default interval) Instance configuration: in OPNsense go to VPN|Wireguard|Settings|Instances Create an instance with the following information: Enable Advanced Mode. Name: <Endpoint Name i.e. nl.vpn.airdns.org> Public Key: <Public Key as noted with step 1.4> Private Key: <PrivateKey under heading [Interface] of your generated WG Config> Listen Port: 1637 MTU: 1320 Tunnel Address: <Address including /32 under harding [Interface] of your generated WG Config> Peers: <select peer that you created with step 2.2> Disable routes: Enabled. Step 3. Make an exception on your WAN interface in OPNsense go to Firewall|Rules Select your WAN interface, mine is called WAN_PPPOE Create a Pass rule for IPv4/UDP port 1647 to your WAN-address. Step 4. Assign Wireguard Interface in OPNsense go to Interfaces|Assignments You'll find a "wg1(Wireguard - nl.vpn.airdns.org)" (or similiar) interface. bind it to an interface with a name of your choice. mine is called WAN_WG1 as is is the first site-to-site Wireguard tunnel on my WAN interface. Step 5. Create a gateway. Remember we disabled the routes for the WG instance configuration? Because of that we need to create a gateway. In OPNsense go to System|Gateways|Single Add a Gateway with the following information: Name: WAN_WG_GW Description: Interface WAN_WG1 Gateway Interface: Select WAN_WG1 as created in step 4. Address Family: IPv4 IP address: Dynamic (leave empty) Far Gateway: Enabled (this i am not sure of but for now i'm happy it works) Disable Gateway Monitoring: enabled Step 6. Aliases We set up some aliases. This will make it more easy to redirect some hosts or networks to the Wireguard tunnel. in OPNsense, go to Firewall|Aliases Create host entries for the specific hosts you'll redirect Create network entries for the specific network(s) you'll redirect. Create a Network Group Entry with the host and network entries to group them together. My alias is called networkgroup_wireguard Step 7. Create Outbound NAT for Wireguard. (In my setup, i use Manual Outbound Rule Generation because i like to have control) In OPNsense go to Firewall|NAT|Outbound Create a new Outbound NAT rule with the following information: Interface: WAN_WG1 TCP/IP version: IPv4 Protocol: Any Source Address: <alias networkgroup_wireguard from step 6> Translation /target WAN_WG1 address Description: Wireguard VPN Outbound NAT rule Step 8. Create Outbound Redirect rule. In this example we create 2 rules on our LAN interface, one for redirecting to WG, the other to prevent leaks. In OPNsense go to Firewall|Rules Select your LAN interface add an outbound Pass rule: Action: Pass Source: Networkgroup_wireguard Destination: Any (in my case i use an inverted network group called networkgroup_local where all my local vlans are grouped together) Gateway: WAN_WG1_GW (the gateway you created in step 5.) Add an outbound block rule below that: Action: Block Source: Networkgroup_wireguard Destination: Any Gateway: default Your WG VPN tunnel should now work. Test with https://ipleak.net The following steps are more advanced and i'm still finetuning/experimenting with the settings. your experience may vary. Step 9. Prevent VPN leakage I'm new to OPNsense and i am not sure what the default setting is, but from my pfSense experience i know the following setting is important when you want to make sure your VPN does not leak when for instance the tunnel is down. In OPNsense go to Firewall|Settings|Advanced Under "Gateway Monitoring" enable "Skip Rules when gateway is down" Step 10. MTU/MSS optimization For now i have set thte MTU according to the default setting of AirVPN. I want it to be higher but for now i'm just happy it works. My settings are as follows: In the properties of the WAN_WG1 interface i set the MTU to 1320 and the MSS to 1280. I created a normalize rule (Firewall|Settings|Normalization) with the following settings. this should enable me to clamp the MSS to 1280 for the wireguard group but leave the MSS to the desired setting (1452) as defined on my LAN interface for the rest of the hosts on my LAN; Interface: LAN Direction, Protocol: Any Source: networkgroup_wireguard Max MSS: 1280
  2. 1 point
    fsy

    ANSWERED High latency to AMS servers

    No problems for me from the Netherlands, residential landline. Today I am in Belgium, different mobile ISP, no probs. No problems from my VPS in Ireland (AWS).
  3. 1 point
    Hey, pictures would make this post indeed so much better. So, I have done it and posted below. Please note the following: My OPNsense Firewall is "clean" I did a factory reset before conducting the steps and completing the guide. For simplicity, I copy and pasted most of the Text but added it with the missing pictured and did fix where I believe it was necessary. All Credits for this goes to the original poster @Sj0rs I configure OPNsense from the WAN interface. To do this, I did the following steps as a preparation before this guide. Disclaimer In general, DO NOT TRUST ME ! I'm not a security expert. I do not know what I'm doing here ! Preparation (not required if you access the firewall from LAN) Some advice here… Opening the WAN interface to allow administration is not good ! I am doing this because the firewall sits in my private LAN, and I'm not doing any port forwarding on my main router ! If your firewall is connected directly to the internet, do not do this ! Again, in general, DO NOT TRUST ME ! I'm not a security expert. I do not know what I'm doing here ! Now that you know it… 1. Deselect "Block private networks" and "Block bogon networks" in Interfaces → WAN. After doing so: hit save and "Apply changes". 2. Select "Disable reply-to" in Firewall → Settings → Advanced. Hit save at the end. 3. Add incoming WAN rule to allow administration. Go to Firewall → Rules → WAN Add a TCP rule from "WAN net" to "This Firewall" on HTTPs. Step 1. Information gathering. We'll grab some info that we need to configure the WireGuard Tunnel. Go to the Client Area. Got to VPN Devices. Add a device or edit your existing device. Note your Public Key and IPv4 under the heading "WireGuard" Go back to the Client Area. Go to Config Generator Select "router" under "Choose your OS" Select "WireGuard under "Choose protocols" Select your country under "By Countries". I selected Netherlands Scroll way down and download your config. This is an example of a WireGuard config: (the keys and IP are random and will not work, use your own) [Interface] Address = 10.10.10.10/32 PrivateKey = X72xgdx23XDomnSXmcy#S4Jc#9Y5G*vU$wg^n499yn6 MTU = 1320 DNS = 10.128.0.1 [Peer] PublicKey = VTSQ77Uk4^&RY4h%S$#9h8PR2T&xyya&yPTtk6oD^m$ PresharedKey = b7&&7bntmCS5q%&4J*mSKBAUvV4XEqHerwscvbappXQ Endpoint = nl3.vpn.airdns.org:1637 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 15 Step 2. Create the Tunnel configuration. Pre Configuration — Install WireGuard plugin 0.1 Go to System → Firmware → Plugins and install the "os-wireguard" plugin. Peer configuration: in OPNsense go to VPN → WireGuard → Settings → Peers. Create a peer with the following information: Name: wg_airvpn_<country code>. Mine is called wg_airvpn_nl Public key: <PublicKey under heading [Peer] of your generated WG Config> Pre-shared key <presharedKey under heading [Peer] of your generated WG Config> Allowed IP's: 0.0.0.0/0 Endpoint Address: <Endpoint under heading [Peer] of your generated WG Config> Endpoint port: 1637 (default port) Keepalive interval: 15 (default interval) Click "Save" and you should see the below Instance configuration: in OPNsense go to VPN → Wireguard → Settings → Instances Create an instance with the following information: Enable Advanced Mode. (upper left corner) Name: <Endpoint Name i.e. nl.vpn.airdns.org> Public Key: <Public Key as noted with step 1.4> Private Key: <PrivateKey under heading [Interface] of your generated WG Config> Listen Port: 1637 MTU: 1320 Tunnel Address: <Address including /32 under harding [Interface] of your generated WG Config> Peers: <select peer that you created with step 2.2> Disable routes: Enabled. Hit the "Save" button. Enable WireGuard configuration Go to VPN → Wireguard → Settings → General and click on "Enable WireGuard" Hit "Apply" Step 3. Make an exception on your WAN interface in OPNsense go to Firewall → Rules → WAN On the WAN interface, default is called WAN, create a Pass rule for IPv4/UDP port 1647 to your WAN-address. Scroll down and hit "Save". It should look like this: Step 4. Assign WireGuard Interface in OPNsense go to Interfaces → Assignments You'll find a "wg1(WireGuard - nl.vpn.airdns.org)" (or similar) interface. bind it to an interface with a name of your choice. Mine is called WAN_WG1 as is the first site-to-site WireGuard tunnel on my WAN interface. Click the "Add" button Enable the Interface Interfaces → Assignments → WAN_WG1 Enable: Enable the Interface. Dynamic gateway policy: Selected (I found it's not working without this. Not sure why) No further configuration required. Ensure the "Block private networks" and "Block bogon networks" options are not selected, as shown below. Hit "Save" and "Apply changes". Step 5. Create a gateway. Remember, we disabled the routes for the WG instance configuration? Because of that, we need to create a gateway. In OPNsense go to System → Gateways → Single Add a Gateway with the following information: Name: WAN_WG_GW Description: Interface WAN_WG1 Gateway Interface: Select WAN_WG1 as created in step 4. Address Family: IPv4 IP address: Dynamic (leave empty) Far Gateway: Enabled (this I am not sure of, but for now I'm happy it works) Disable Gateway Monitoring: enabled Hit the "Save" button. Step 6. Aliases I did not use aliases in my setup. I use the default LAN network group. Step 7. Create Outbound NAT for WireGuard. (In my setup, I use Manual Outbound Rule Generation because I like to have control) In OPNsense go to Firewall → NAT → Outbound Click "Manual outbound NAT rule generation" then "Save" then "Apply changes". Create a new Outbound NAT rule with the following information: Interface: WAN_WG1 TCP/IP version: IPv4 Protocol: Any Source Address: LAN net (or use alias) Translation /target WAN_WG1 address Description: WireGuard VPN Outbound NAT rule Click the "Save" button and then the "Apply changes" button. Step 8. Create Outbound Redirect rule. In this example we create 2 rules on our LAN interface, one for redirecting to WG, the other to prevent leaks. In OPNsense go to Firewall → Rules → LAN add an outbound Pass rule: Action: Pass Source: LAN net (or use alias) Destination: Any Gateway: WAN_WG_GW (the gateway you created in step 5.) Hit the "Save" button. Add an outbound block rule below that: Action: Block Source: LAN net Destination: Any Gateway: default Hit the "Save" button and then the "Apply changes" button. You need to disable the existing Default rules by clicking on the green arrow then "apply changes" again. (I have removed them as we do not need them anyway) Step 9. Prevent DNS leaks Create an alias to use all available AirVPN servers. Firewall → Aliases Click add Enable: selected Name: VPN_DNS Content: 10.4.0.1 128.0.1 10.5.0.1 10.7.0.1 Click Save Create NAT port forward rule. Firewall → NAT → Port Forward Click Add Interface: LAN TCP/IP Version: IPv4 Protocol: TCP/UP (DNS traffic is usually UDP, but I thought it's better to do it like this) Source: LAN net Destination: This Firewall Destination port range: DNS Redirect target IP: VPN_DNS (the alias we created in 9.1) Redirect target port: DNS NAT reflection: Disable Filter rule association: None Hit "Save", then "Apply changes". Your WG VPN tunnel should now work. Test with https://ipleak.net Step 10. Port forwarding (Optional) If you need port forwarding for something, make sure It's configured in your AirVPN Member settings ! Firewall → Rules → WAN_WG1 → Add Action: Pass Interface: WAN_WG1 Direction: In Protocol: select your protocol Source: any (or if you can define it, do this here) Destination: Single host or Network and the IP of the device Destination port range: select the port (range) reply-to: WAN_WG1_GW (this is very Important!) Hit "Save", then "Apply changes". Firewall → NAT→ Port Forward → Add Interface: WAN_WG1 Protocol: Same as in 10.5 Destination: WAN_WG1 address Destination port range: Same as in 10.8 Redirect target IP: Same as in 10.7 Redirect target port: Same as in 10.8 Hit "Save", then "Apply changes". That's it for port forwarding. Test the setting. Let me know if something is not correct or clear. END of the Guide... Everything below here can be ignored. It seems the board software adds all the pictures I have added again to the bottom of the post, so ignore everything below here ! Thanks
  4. 1 point
    I also use this script I made for wireguard automation.. might help somebody, this automatically 'randomizes' (gets new) IP and randomizes exposed port (from list of ports you define in variable and of course you have reserved in your account) This should be in (docker-compose related) `.env` file AIRVPN_WG_PRIVATE_KEY=xxxxxxxxxxxxxxxxxxxx AIRVPN_WG_PRESHARED_KEY=xxxxxxxxxxxxxxxxxxxxxx AIRVPN_WG_ADDRESSES=x.x.x.x/32,x:x:x:x:x:x:x:x/128 AIRVPN_PEER_PORT=xxxxx AIRVPN_DEVICE_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AIRVPN_SERVER_NAMES=xxxxx xxxxx AIRVPN_COUNTRIES=xxxxx AIRVPN_CUNTRY_CODE=xx AIRVPN_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AIRVPN_PORTS=xxxx xxxx xxxxx xxxxx xxxxx xxxxx xxxx xxxx xxxx xxxx xxxx xxxxx And this is `docker-compose.yml` part: gluetun: image: qmcgaw/gluetun container_name: gluetun ports: - 8888:8888/tcp # HTTPPROXY sysctls: - net.ipv6.conf.all.disable_ipv6=0 cap_add: - NET_ADMIN environment: - TZ=Europe/Amsterdam - HTTPPROXY=on - HTTPPROXY_STEALTH=on - VPN_TYPE=wireguard - VPN_SERVICE_PROVIDER=airvpn - SERVER_NAMES=${AIRVPN_SERVER_NAMES} - SERVER_COUNTRIES=${AIRVPN_COUNTRIES} - FIREWALL_VPN_INPUT_PORTS=${AIRVPN_PEER_PORT} - WIREGUARD_ADDRESSES=${AIRVPN_WG_ADDRESSES} - WIREGUARD_PRIVATE_KEY=${AIRVPN_WG_PRIVATE_KEY} - WIREGUARD_PRESHARED_KEY=${AIRVPN_WG_PRESHARED_KEY} volumes: - /volume1/docker/gluetun:/gluetun devices: - /dev/net/tun:/dev/net/tun restart: always mem_limit: 1024m memswap_limit: 1024m Finally put this part to `.bashrc` (or alternative), `source .bashrc` then execute 'rand' function (change path to your env file as well as docker compose file) * you should have `jq`, `awk`, `sed`, `curl` and `shuf` binaries available. export DOCKER_ENV_FILE=/volume1/docker/.env export DOCKER_COMPOSE_FILE=/volume1/docker/docker-compose.yml rand () { CURRENT_DEVICE_ID=$(awk -F '=' '/AIRVPN_DEVICE_ID/ {print $2}' $DOCKER_ENV_FILE) AIRVPN_API_KEY=$(awk -F '=' '/AIRVPN_API_KEY/ {print $2}' $DOCKER_ENV_FILE) AIRVPN_CUNTRY_CODE=$(awk -F '=' '/AIRVPN_CUNTRY_CODE/ {print $2}' $DOCKER_ENV_FILE) AIRVPN_PORTS=$(awk -F '=' '/AIRVPN_PORTS/ {print $2}' $DOCKER_ENV_FILE) [ ! -f $CURRENT_DEVICE_ID ] && \ curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/disconnect/?device=$CURRENT_DEVICE_ID" && sleep 1 && \ curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/devices/?action=delete&id=$CURRENT_DEVICE_ID" && sleep 1 AIRVPN_DEVICE_ID=$(curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/devices/?action=add" | jq -r .id[0:50]) && sleep 10 CONFIG_FILE=$(curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/generator/?protocols=wireguard_3_udp_1637&servers=${AIRVPN_CUNTRY_CODE}&system=linux&device_id=New%20device") AIRVPN_WG_ADDRESSES=$(awk '/Address/ {print $3$4}' <<<$CONFIG_FILE) AIRVPN_WG_PRESHARED_KEY=$(awk '/PresharedKey/ {print $3}' <<<$CONFIG_FILE) AIRVPN_WG_PRIVATE_KEY=$(awk '/PrivateKey/ {print $3}' <<<$CONFIG_FILE) AIRVPN_PEER_PORT=$(shuf -n1 -e $AIRVPN_PORTS) sed -i 's#^AIRVPN_WG_ADDRESSES=.*$#AIRVPN_WG_ADDRESSES='"$AIRVPN_WG_ADDRESSES"'#g' $DOCKER_ENV_FILE sed -i 's#^AIRVPN_WG_PRESHARED_KEY=.*$#AIRVPN_WG_PRESHARED_KEY='"$AIRVPN_WG_PRESHARED_KEY"'#g' $DOCKER_ENV_FILE sed -i 's#^AIRVPN_WG_PRIVATE_KEY=.*$#AIRVPN_WG_PRIVATE_KEY='"$AIRVPN_WG_PRIVATE_KEY"'#g' $DOCKER_ENV_FILE sed -i 's#^AIRVPN_PEER_PORT=.*$#AIRVPN_PEER_PORT='"$AIRVPN_PEER_PORT"'#g' $DOCKER_ENV_FILE sed -i 's#^AIRVPN_DEVICE_ID=.*$#AIRVPN_DEVICE_ID='"$AIRVPN_DEVICE_ID"'#g' $DOCKER_ENV_FILE docker-compose --env-file $DOCKER_ENV_FILE -f $DOCKER_COMPOSE_FILE up --detach --quiet-pull --remove-orphans } There is a single limitation, you can only have a single "New device" named device on your account, this gets re-cycled (current deleted and new created) by the script. This is because we can't set device name via API so I am forced to use the default "New device" name while calling API to generate a new config. Oh and the api calls must go without using VPN, because understandably, its killing the connection so you'd be unable to finish the process.
×
×
  • Create New...