# Subnet prefix=2001:NNNN:NNNN:NNNN:80:: # netmask prefixlen=112
# Listen port port 8149 # Protocol proto udp # IP tunnel dev tap0 # Master certificate ca ca.crt # Server certificate cert server.crt # Server private key key server.key # Diffie-Hellman parameters dh dh2048.pem # Allow clients to communicate with each other client-to-client # Client config dir client-config-dir /etc/openvpn/ccd # Run client-specific script on connection and disconnection script-security 2 client-connect "/usr/bin/sudo -u root /etc/openvpn/server-clientconnect.sh" client-disconnect "/usr/bin/sudo -u root /etc/openvpn/server-clientdisconnect.sh" # Server mode and client subnets server 10.18.0.0 255.255.255.0 server-ipv6 2001:NNNN:NNNN:NNNN:80::/112 topology subnet # IPv6 routes push "route-ipv6 2001:NNNN:NNNN:NNNN::/64" push "route-ipv6 2000::/3" persist-key persist-tun # Ping every 10s. Timeout of 120s. keepalive 10 120 # Enable compression comp-lzo # User and group user vpn group vpn # Log a short status status openvpn-status.log verb 4 sndbuf 0 rcvbuf 0
#!/bin/sh # Check client variables if [ -z "$ifconfig_pool_remote_ip" ] || [ -z "$common_name" ]; then echo "Missing environment variable." exit 1 fi # Load server variables . /etc/openvpn/variables ipv6="" # Find out if there is a specific config with fixed IPv6 for this client if [ -f "/etc/openvpn/ccd/$common_name" ]; then # Get fixed IPv6 from client config file ipv6=$(sed -nr 's/^.*ifconfig-ipv6-push[ \t]+([0-9a-fA-F\\:]+).*$/\1/p' "/etc/openvpn/ccd/$common_name") fi # Get IPv6 from IPv4 if [ -z "$ipv6" ]; then ipp=$(echo "$ifconfig_pool_remote_ip" | cut -d. -f4) if ! [ "$ipp" -ge 2 -a "$ipp" -le 254 ] 2>/dev/null; then echo "Invalid IPv4 part." exit 1 fi hexipp=$(printf '%x' $ipp) ipv6="$prefix$hexipp" fi # Create proxy rule /sbin/ip -6 neigh add proxy $ipv6 dev eth0
#!/bin/sh # Check client variables if [ -z "$ifconfig_pool_remote_ip" ] || [ -z "$common_name" ]; then echo "Missing environment variable." exit 1 fi # Load server variables . /etc/openvpn/variables ipv6="" # Find out if there is a specific config with fixed IPv6 for this client if [ -f "/etc/openvpn/ccd/$common_name" ]; then # Get fixed IPv6 from client config file ipv6=$(sed -nr 's/^.*ifconfig-ipv6-push[ \t]+([0-9a-fA-F\\:]+).*$/\1/p' "/etc/openvpn/ccd/$common_name") fi # Get IPv6 from IPv4 if [ -z "$ipv6" ]; then ipp=$(echo "$ifconfig_pool_remote_ip" | cut -d. -f4) if ! [ "$ipp" -ge 2 -a "$ipp" -le 254 ] 2>/dev/null; then echo "Invalid IPv4 part." exit 1 fi hexipp=$(printf '%x' $ipp) ipv6="$prefix$hexipp" fi # Delete proxy rule /sbin/ip -6 neigh del proxy $ipv6 dev eth0
Defaults:vpn env_keep += "ifconfig_pool_remote_ip common_name" vpn ALL=NOPASSWD: /etc/openvpn/server-clientconnect.sh vpn ALL=NOPASSWD: /etc/openvpn/server-clientdisconnect.sh
net.ipv6.conf.all.forwarding=1 net.ipv6.conf.all.proxy_ndp = 1
ifconfig-push 10.18.0.101 255.255.255.0 ifconfig-ipv6-push 2001:NNNN:NNNN:NNNN:80::1001/112 2001:NNNN:NNNN:NNNN:80::1
# Client mode client # IPv6 tunnel dev tap # TCP protocol proto udp # Address/Port of VPN server remote SERVER_IP 8149 # Don't bind to local port/address nobind # Don't need to re-read keys and re-create tun at restart persist-key persist-tun # User/Group ;user nobody ;group nobody # Remote peer must have a signed certificate remote-cert-tls server ns-cert-type server # Enable compression comp-lzo ca ca.crt cert abyrvalg-laptop.crt key abyrvalg-laptop.key sndbuf 0 rcvbuf 0
# cd /etc/openvpn # openvpn ./server.conf
# cd /etc/openvpn # openvpn ./ipv6.conf
48: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UNKNOWN qlen 100 inet6 2001:NNNN:NNNN:NNNN:80::1001/112 scope global
PING ipv6.google.com(lr-in-x8a.1e100.net) 56 data bytes 64 bytes from lr-in-x8a.1e100.net: icmp_seq=1 ttl=46 time=110 ms 64 bytes from lr-in-x8a.1e100.net: icmp_seq=2 ttl=46 time=113 ms 64 bytes from lr-in-x8a.1e100.net: icmp_seq=3 ttl=46 time=110 ms 64 bytes from lr-in-x8a.1e100.net: icmp_seq=4 ttl=46 time=110 ms --- ipv6.google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3001ms rtt min/avg/max/mdev = 110.586/111.367/113.285/1.183 ms
Source: https://habr.com/ru/post/321486/
All Articles