Skip to content

Commit 5414cdf

Browse files
committed
Improve IPv6 setup
- Use a /116 subnet (4096 addresses) for IPv6. - Set IPv6 forwarding in rc.local, in addition to sysctl.conf. In some cases, setting it in sysctl.conf may not work reliably.
1 parent 40d0be8 commit 5414cdf

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

extras/ikev2setup.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ confirm_or_abort() {
169169
show_header() {
170170
cat <<'EOF'
171171
172-
IKEv2 Script Copyright (c) 2020-2026 Lin Song 16 Mar 2026
172+
IKEv2 Script Copyright (c) 2020-2026 Lin Song 20 Mar 2026
173173
174174
EOF
175175
}
@@ -1178,11 +1178,12 @@ add_ikev2_connection() {
11781178
bigecho2 "Adding a new IKEv2 connection..."
11791179
XAUTH_POOL=${VPN_XAUTH_POOL:-'192.168.43.10-192.168.43.250'}
11801180
IP6_NET=${VPN_IP6_NET:-'fddd:500:500:500::/64'}
1181+
IP6_PREFIX=$(printf '%s' "$IP6_NET" | sed 's|/[0-9]*$||; s|::$||')
11811182
lsubnet="0.0.0.0/0"
11821183
rpool="$XAUTH_POOL"
11831184
if [ -n "$VPN_PUBLIC_IP6" ]; then
11841185
lsubnet="0.0.0.0/0,::/0"
1185-
rpool="$XAUTH_POOL,$IP6_NET"
1186+
rpool="$XAUTH_POOL,${IP6_PREFIX}::1000-${IP6_PREFIX}::1fff"
11861187
fi
11871188
if ! grep -qs '^include /etc/ipsec\.d/\*\.conf$' "$IPSEC_CONF"; then
11881189
echo >> "$IPSEC_CONF"

extras/vpnuninstall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ update_rclocal() {
211211
bigecho "Updating rc.local..."
212212
conf_bk "/etc/rc.local"
213213
if [ "$os_type" = "alpine" ]; then
214-
sed -i '/# Added by hwdsl2 VPN script/,+4d' /etc/rc.local
214+
sed -i '/# Added by hwdsl2 VPN script/,/)&$/d' /etc/rc.local
215215
else
216-
sed --follow-symlinks -i '/# Added by hwdsl2 VPN script/,+4d' /etc/rc.local
216+
sed --follow-symlinks -i '/# Added by hwdsl2 VPN script/,/)&$/d' /etc/rc.local
217217
fi
218218
fi
219219
}

vpnsetup_amzn.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,16 @@ enable_on_boot() {
579579
else
580580
echo '#!/bin/sh' > /etc/rc.local
581581
fi
582-
cat >> /etc/rc.local <<'EOF'
582+
ip6_fwd_rc=""
583+
[ -n "$ip6" ] && ip6_fwd_rc='
584+
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding'
585+
cat >> /etc/rc.local <<EOF
583586
584587
# Added by hwdsl2 VPN script
585588
(sleep 15
586589
service ipsec restart
587590
service xl2tpd restart
588-
echo 1 > /proc/sys/net/ipv4/ip_forward)&
591+
echo 1 > /proc/sys/net/ipv4/ip_forward${ip6_fwd_rc})&
589592
EOF
590593
fi
591594
}

vpnsetup_centos.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,16 @@ enable_on_boot() {
760760
else
761761
echo '#!/bin/sh' > /etc/rc.local
762762
fi
763-
cat >> /etc/rc.local <<'EOF'
763+
ip6_fwd_rc=""
764+
[ -n "$ip6" ] && ip6_fwd_rc='
765+
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding'
766+
cat >> /etc/rc.local <<EOF
764767
765768
# Added by hwdsl2 VPN script
766769
(sleep 15
767770
service ipsec restart
768771
service xl2tpd restart
769-
echo 1 > /proc/sys/net/ipv4/ip_forward)&
772+
echo 1 > /proc/sys/net/ipv4/ip_forward${ip6_fwd_rc})&
770773
EOF
771774
fi
772775
}

vpnsetup_ubuntu.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,16 @@ EOF
725725
if uname -m | grep -qi '^arm'; then
726726
rc_delay=60
727727
fi
728+
ip6_fwd_rc=""
729+
[ -n "$ip6" ] && ip6_fwd_rc='
730+
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding'
728731
cat >> /etc/rc.local <<EOF
729732
730733
# Added by hwdsl2 VPN script
731734
(sleep $rc_delay
732735
service ipsec restart
733736
service xl2tpd restart
734-
echo 1 > /proc/sys/net/ipv4/ip_forward)&
737+
echo 1 > /proc/sys/net/ipv4/ip_forward${ip6_fwd_rc})&
735738
exit 0
736739
EOF
737740
fi

0 commit comments

Comments
 (0)