OpenVPN und IPv6

openvpn logoMein Netzwerkaufbau ist etwas komplizierter und ich bin dabei alles IPv6 ready zu machen. Ich habe bei netcup einen Root-Server auf dem IPv6 läuft. Dieses hostet mein Blog und bindet, mittels OpenVPN, noch eine Synology Diskstation an. Bisher habe ich mein ganzen Konstrukt nur auf IPv4 abgestützt und will es nun um IPv6 erweitern. Dazu gehört natürlich auch die OpenVPN Verbindung zu meiner NAS. Diese hostet den Mail-Server und noch weitere Anwendung die ich über eine feste IP erreichbar habe. Ich gehe also hier davon aus, das ihr bereits einen funktionierenden OpenVPN Server besitzt.

Ich gehe also davon aus, das ihr bereits einen funktionierenden IPv4 Tunnel habt, und diesen um IPv6 erweitert.

Ausgangssituation

Damit ihr die Einstellungen leichter versteht, gehe ich von folgenden fiktiven Adressen aus:

  • Zugeteilte IPv4-Adresse: 11.22.33.44
  • Zugeteiltes IPv6-Netz: 2003:4711:1231:2304::/64
  • IPv6-Adresse des Servers: 2003:4711:1231:2304::2
  • IPv6-Netz für VPN: 2003:4711:1231:2304:bbbb::/112

Konfiguration des OpenVPN Servers

Wir aktivieren erst mal das IPv6 forwarding und den NDP proxy. Dazu passt ihr folgende Eintrage in der /etc/sysctl.conf an.

[code]
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.proxy_ndp = 1
[/code]

 

Nun erstellen wir das Script /etc/openvpn/ndp-proxy-update.sh mit folgendem Inhalt. Eventuell müsst ihr in der Zeile 5 euer Netzwerkinterface anpassen. Mit diesem Script wird automatisch jede IPv6 Adresse eines Clients zum NDP-Proxy hinzugefügt und auch wieder nach der Trennung entfernt.

[code]
#!/bin/bash

action="$1"
addr="$2"
pubif="eth0"

if [[ "${addr//:/}" == "$addr" ]]
then
# not an ipv6 address
exit
fi

case "$action" in
add)
ip -6 neigh add proxy ${addr} dev ${pubif}
;;
update)
ip -6 neigh replace proxy ${addr} dev ${pubif}
;;
delete)
ip -6 neigh del proxy ${addr} dev ${pubif}
;;
esac
[/code]

 

Das Script muss noch ausführbar gemacht werden.

[code]

chmod 744 /etc/openvpn/ndp-proxy-update.sh

[/code]

 

Da der OpenVPN-Dienst normalerweise nicht als root laufen sollte, müsst ihr mittels visudo dem VPN-Dienst erlauben, diese Datei mit root-Rechten auszuführen. Folgende Zeile fügt ihr an das Ende an.

[code]

# OpenVPN
openvpn ALL=NOPASSWD: /etc/openvpn/ndp-proxy-update.sh

[/code]

 

Nun müsst ihr  noch ein paar Einstellungen in der /etc/openvpn/server.conf anpassen. Wichtig sind hier die Zeilen 23,31,36,37 und 43.

[code]
# Serverport
port 1194

# TCP or UDP server?
proto udp

# "dev tun" will create a routed IP tunnel,
dev tun

# Certs
ca ca.crt
cert server.crt
key server.key

# Diffie hellman parameters.
dh dh2048.pem

# Network topology
topology subnet

# Configure server mode and supply a VPN subnet
server 10.8.0.0 255.255.255.0
server-ipv6 2003:4711:1231:2304:bbbb::/112

# Maintain a record of client <-> virtual IP address
ifconfig-pool-persist ipp.txt

# Push routes to the client to allow it
# to reach other private subnets behind
# the server.
push "route-ipv6 2000::/3 2003:4711:1231:2304::/64"

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.
script-security 2
learn-address "/usr/bin/sudo -u root /etc/openvpn/scripts/ndp-proxy-setup.sh"

# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN
push "redirect-gateway def1 bypass-dhcp"
push "redirect-gateway ipv6"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

# The keepalive directive causes ping-like
# messages
keepalive 10 120

# For compression compatible with older clients use comp-lzo
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo

# It’s a good idea to reduce the OpenVPN
# daemon’s privileges after initialization.
user openvpn
group openvpn

# The persist options will try to avoid
# accessing certain resources on restart
persist-key
persist-tun

# Output a short status file
status openvpn-status.log

# Set the appropriate level of log
# file verbosity.
verb 3
[/code]

 

Nun solltet ihr euren Server neu starten, und danach eure Einstellungen testen. Eure Firewall muss sicherlich auch noch angepasst werden.

 

Anpassung der Firewall

Hier sind meine Firewall-Regeln bezüglich IPv6.  Es gibt hier sicherlich Verbesserungspotential aber sie sollen auch nur als Anhaltspunkt dienen. Wenn ich es richtig sehen, macht das letzte ip6tables -A OUTPUT alle anderen überflüssig. Na ja, es läuft.

[code]

ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A OUTPUT -o lo -j ACCEPT

ip6tables -A INPUT -p icmpv6 -j ACCEPT
ip6tables -A OUTPUT -p icmpv6 -j ACCEPT

ip6tables -A INPUT -i tun0 -j ACCEPT
ip6tables -A FORWARD -i tun0 -j ACCEPT
ip6tables -A OUTPUT -o tun0 -j ACCEPT

ip6tables -A FORWARD -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT
ip6tables -A FORWARD -i tun+ -o eth0 -m state –state NEW,RELATED,ESTABLISHED -j ACCEPT
ip6tables -A FORWARD -i eth0 -o tun+ -m state –state NEW,RELATED,ESTABLISHED -j ACCEPT

ip6tables -A FORWARD -p icmpv6 -j ACCEPT
ip6tables -A FORWARD -s 2003:4711:1231:2304::/64 -j ACCEPT

ip6tables -A INPUT -i eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT

ip6tables -A INPUT -j REJECT
ip6tables -A FORWARD -j REJECT
ip6tables -A OUTPUT -j ACCEPT

[/code]

Viel Spaß mit der Anleitung und ich hoffe es läuft für euch.

Schreibe einen Kommentar