Skip to content

Commit 2f133ec

Browse files
committed
Added IPv6 examples
1 parent eda3d80 commit 2f133ec

File tree

24 files changed

+908
-0
lines changed

24 files changed

+908
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# basic_nat_ipv6
2+
3+
Features:
4+
5+
- Works out of the box on bridge or host network
6+
- NAT (Network translation protocol)
7+
- Has configuration wizard
8+
- LAN protection (does not allow traffic to LANs connected to server)
9+
10+
## Configure
11+
12+
``` bash
13+
ovpn_enconf basic_nat
14+
#Protocol udp, tcp, udp6, tcp6 [udp]:
15+
#VPN network [10.0.0.0]:
16+
#VPN IPv6 network with CIDR [2001:db8::/32]:
17+
#Port [1194]:
18+
#Public IP or domain of server: <PUBLIC IP>
19+
#DNS1 [8.8.8.8]:
20+
#DNS2 [8.8.4.4]:
21+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Basic OpenVPN server configuration
3+
# @author Martin Dagarin
4+
# @version 2
5+
# @since 12/03/2019
6+
#
7+
8+
# Basic info
9+
client
10+
dev tun0
11+
proto $PROTO
12+
nobind
13+
14+
# Remote info
15+
remote $SERVER_IP $PORT
16+
17+
# Connection settings
18+
resolv-retry infinite
19+
persist-key
20+
persist-tun
21+
22+
# Encryption settings
23+
cipher AES-256-GCM
24+
25+
# Additional settings
26+
compress lzo
27+
verb 3
28+
29+
# Permissions
30+
user nobody
31+
group nogroup
32+
33+
# CA
34+
remote-cert-tls server
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Basic OpenVPN server configuration
3+
# @author Martin Dagarin
4+
# @version 3
5+
# @since 12/03/2019
6+
#
7+
8+
# Basic info
9+
proto $PROTO
10+
port $PORT
11+
12+
# Network info (local VPN network)
13+
topology subnet
14+
server $NETWORK_ADDRESS 255.255.255.0
15+
server-ipv6 $NETWORK_ADDRESS_IPV6
16+
17+
push "redirect-gateway def1 bypass-dhcp"
18+
push "route-ipv6 ::/0"
19+
push "dhcp-option DNS $DNS1"
20+
push "dhcp-option DNS $DNS2"
21+
22+
ifconfig-pool-persist /config/tmp/ipp.txt
23+
24+
# CA files
25+
ca /config/pki/ca.crt
26+
cert /config/pki/issued/server.crt
27+
key /config/pki/private/server.key
28+
dh /config/pki/dh.pem
29+
tls-crypt /config/pki/ta.key
30+
remote-cert-tls client
31+
32+
# Connection settings
33+
persist-key
34+
persist-tun
35+
36+
# Encryption settings
37+
cipher AES-256-GCM
38+
39+
# Verify client certificate
40+
verify-client-cert require
41+
42+
# Additional settings
43+
client-to-client
44+
keepalive 10 120
45+
compress lzo
46+
explicit-exit-notify 1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
source /app/hookBaseFirewallDestroy.sh
4+
5+
#
6+
# Network clear
7+
#
8+
echo "Clearing OpenVPN releated firewall rules"
9+
10+
# Close OpenVPN port to outside
11+
ovpn-iptables -D INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
12+
ovpn-ip6tables -D INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
13+
14+
# Disable LAN protection of VPN
15+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 10.0.0.0/8 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
16+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 192.168.0.0/16 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
17+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 172.16.0.0/12 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
18+
19+
# Disable Routing Internet <--> VPN network
20+
ovpn-iptables -D FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
21+
ovpn-iptables -D FORWARD -i $OUT_INT -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
22+
ovpn-ip6tables -D FORWARD -i tun0 -s $NETWORK_ADDRESS_IPV6 -o $OUT_INT -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
23+
ovpn-ip6tables -D FORWARD -i $OUT_INT -d $NETWORK_ADDRESS_IPV6 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
24+
25+
# Disable NAT for VPN traffic
26+
ovpn-iptables -t nat -D POSTROUTING -s $NETWORK_ADDRESS/24 -o $OUT_INT -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
27+
ovpn-ip6tables -t nat -D POSTROUTING -s $NETWORK_ADDRESS_IPV6 -o $OUT_INT -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
source /app/hookBaseFirewallDestroy.sh
4+
5+
#
6+
# Network clear
7+
#
8+
echo "Clearing up basic firewall rules"
9+
10+
# Accept everything from input
11+
ovpn-iptables -P INPUT ACCEPT
12+
ovpn-ip6tables -P INPUT ACCEPT
13+
14+
# Delete: Allow established connection
15+
ovpn-iptables -D INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
16+
ovpn-ip6tables -D INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
17+
18+
# Delete: Allow ICMP ping request
19+
ovpn-iptables -D INPUT -p icmp --icmp-type 8 -j ACCEPT
20+
ovpn-ip6tables -D INPUT -p icmp --icmp-type 128 -j ACCEPT
21+
22+
# Accept all forwarded traffic
23+
ovpn-iptables -P FORWARD ACCEPT
24+
ovpn-ip6tables -P FORWARD ACCEPT
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
source /app/hookBaseFirewallSetup.sh
4+
5+
#
6+
# Network initialization
7+
#
8+
echo "Setting up basic firewall rules"
9+
10+
#
11+
# Because default iptables rules are set to ACCEPT all connection, we need to put some
12+
# security settings in place
13+
#
14+
15+
# Drop everything from input
16+
ovpn-iptables -P INPUT DROP
17+
ovpn-ip6tables -P INPUT DROP
18+
19+
# Allow established connection
20+
ovpn-iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
21+
ovpn-ip6tables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "Accept traffic from established connections"
22+
23+
# Allow ICMP ping request
24+
ovpn-iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
25+
ovpn-ip6tables -A INPUT -p icmp --icmp-type 128 -j ACCEPT
26+
27+
# Drop all forwarded traffic
28+
ovpn-iptables -P FORWARD DROP
29+
ovpn-ip6tables -P FORWARD DROP
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
source /app/hookBaseFirewallSetup.sh
4+
5+
#
6+
# Network initialization
7+
#
8+
echo "Setting up OpenVPN related firewall rules"
9+
10+
# Open OpenVPN port to outside
11+
ovpn-iptables -A INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
12+
ovpn-ip6tables -A INPUT -p udp -m udp --dport $PORT -j ACCEPT -m comment --comment "Open OpenVPN port"
13+
14+
# Protect LANs after VPN
15+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 10.0.0.0/8 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
16+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 192.168.0.0/16 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
17+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -d 172.16.0.0/12 -j REJECT -m comment --comment "Drop traffic VPN --> LANs"
18+
19+
# Allow Routing Internet <--> VPN network
20+
ovpn-iptables -A FORWARD -i tun0 -s $NETWORK_ADDRESS/24 -o $OUT_INT -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
21+
ovpn-iptables -A FORWARD -i $OUT_INT -d $NETWORK_ADDRESS/24 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
22+
ovpn-ip6tables -A FORWARD -i tun0 -s $NETWORK_ADDRESS_IPV6 -o $OUT_INT -j ACCEPT -m comment --comment "Allow traffic VPN --> Internet"
23+
ovpn-ip6tables -A FORWARD -i $OUT_INT -d $NETWORK_ADDRESS_IPV6 -o tun0 -j ACCEPT -m comment --comment "Allow traffic Internet --> VPN"
24+
25+
# Preform NAT for VPN traffic
26+
ovpn-iptables -t nat -A POSTROUTING -s $NETWORK_ADDRESS/24 -o $OUT_INT -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
27+
ovpn-ip6tables -t nat -A POSTROUTING -s $NETWORK_ADDRESS_IPV6 -o $OUT_INT -j MASQUERADE -m comment --comment "NAT traffic VPN --> Internet"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/python
2+
3+
#
4+
# Config wizard for basic_nat example
5+
# @author Martin Dagarin
6+
# @version 1
7+
# @since 19/03/2019
8+
#
9+
10+
# Defaults:
11+
# Protocol: udp
12+
# Network: 10.0.0.0
13+
# Port: 1194
14+
# DNS: 8.8.8.8, 2001:4860:4860::8888
15+
#
16+
17+
import sys, os
18+
19+
# Import libraries included in this docker
20+
sys.path.insert(0, '/app')
21+
import libovpn
22+
23+
# Check if temporary path was passed to this script
24+
if len(sys.argv) < 2:
25+
print("Temporary path was not passed to wizard")
26+
sys.exit(1)
27+
TEMP_PATH = sys.argv[1]
28+
if not os.path.isdir(TEMP_PATH):
29+
print("Specified directory does not exist")
30+
sys.exit(2)
31+
32+
# Select output interface
33+
out_int = input("Out interface [eth0]:")
34+
if len(out_int) == 0:
35+
out_int = "eth0"
36+
37+
# Select protocol
38+
protocol = input("Protocol udp, tcp, udp6, tcp6 [udp]:")
39+
AVAILABLE_PROTOCOLS = ["udp", "tcp", "udp6", "tcp6"]
40+
if len(protocol) != 0 and protocol not in AVAILABLE_PROTOCOLS:
41+
print("Invalid protocol")
42+
sys.exit(3)
43+
if len(protocol) == 0:
44+
protocol = "udp"
45+
46+
# Select network
47+
network = input("VPN network [10.0.0.0]:")
48+
if len(network) == 0:
49+
network = "10.0.0.0"
50+
networkv6 = input("VPN IPv6 network with CIDR [2001:db8::/32]:")
51+
if len(network) == 0:
52+
print("Invalid network")
53+
sys.exit(4)
54+
55+
# Select port
56+
port = input("Port [1194]:")
57+
if len(port) == 0:
58+
port="1194"
59+
60+
# Select Public IP or domain
61+
public = input("Public IP or domain of server:")
62+
if len(public) == 0:
63+
print("Invalid Public IP")
64+
sys.exit(5)
65+
66+
# DNS servers
67+
dns1 = input("DNS1 [8.8.8.8]:")
68+
if len(dns1) == 0:
69+
dns1 = "8.8.8.8"
70+
dns2 = input("DNS2 [2001:4860:4860::8888]:")
71+
if len(dns2) == 0:
72+
dns2 = "2001:4860:4860::8888"
73+
74+
75+
# Write to server config
76+
vars = [
77+
("$OUT_INT", out_int),
78+
("$PROTO", protocol),
79+
("$PORT", port),
80+
("$NETWORK_ADDRESS", network),
81+
("$NETWORK_ADDRESS_IPV6", networkv6),
82+
("$SERVER_IP", public),
83+
("$DNS1", dns1),
84+
("$DNS2", dns2)
85+
]
86+
87+
# Process config files
88+
confs = [
89+
"/config/server.conf",
90+
"/client/client.conf",
91+
"/hooks/down/10-network.sh",
92+
"/hooks/up/10-network.sh"
93+
]
94+
for config_file in confs:
95+
libovpn.conf_envsubst(TEMP_PATH + config_file, vars)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# basic_nat_wlp_ipv6
2+
3+
Features:
4+
5+
- Works out of the box on bridge or host network
6+
- NAT (Network translation protocol)
7+
- Has configuration wizard
8+
- **WITHOUT** LAN protection (does not allow traffic to LANs connected to server), so you can still access devices in LAN (but **routed** example is recommended, because here traffic is still NAT-ed)
9+
10+
## Configure
11+
12+
``` bash
13+
ovpn_enconf basic_nat
14+
#Protocol udp, tcp, udp6, tcp6 [udp]:
15+
#VPN network [10.0.0.0]:
16+
#VPN IPv6 network with CIDR [2001:db8::/32]:
17+
#Port [1194]:
18+
#Public IP or domain of server: <PUBLIC IP>
19+
#DNS1 [8.8.8.8]:
20+
#DNS2 [8.8.4.4]:
21+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Basic OpenVPN server configuration
3+
# @author Martin Dagarin
4+
# @version 2
5+
# @since 12/03/2019
6+
#
7+
8+
# Basic info
9+
client
10+
dev tun0
11+
proto $PROTO
12+
nobind
13+
14+
# Remote info
15+
remote $SERVER_IP $PORT
16+
17+
# Connection settings
18+
resolv-retry infinite
19+
persist-key
20+
persist-tun
21+
22+
# Encryption settings
23+
cipher AES-256-GCM
24+
25+
# Additional settings
26+
compress lzo
27+
verb 3
28+
29+
# Permissions
30+
user nobody
31+
group nogroup
32+
33+
# CA
34+
remote-cert-tls server

0 commit comments

Comments
 (0)