Read this in other languages: English, 简体中文.
Warning: This helper script will remove IPsec VPN from your server. All VPN configuration will be permanently deleted, and Libreswan and xl2tpd will be removed. This cannot be undone!
wget https://git.io/vpnuninstall -O vpnunst.sh
sudo bash vpnunst.shWhen finished, reboot your server.
Alternatively, you may manually uninstall the VPN by following these steps. Commands must be run as root, or with sudo.
Warning: These steps will remove IPsec VPN from your server. All VPN configuration will be permanently deleted, and Libreswan and xl2tpd will be removed. This cannot be undone!
service ipsec stop
service xl2tpd stop
rm -rf /usr/local/sbin/ipsec /usr/local/libexec/ipsec /usr/local/share/doc/libreswan
rm -f /etc/init/ipsec.conf /lib/systemd/system/ipsec.service /etc/init.d/ipsec \
/usr/lib/systemd/system/ipsec.service /etc/logrotate.d/libreswan \
/usr/lib/tmpfiles.d/libreswan.confapt-get purge xl2tpd
yum remove xl2tpd
apk del xl2tpd
Edit /etc/iptables.rules and remove unneeded rules. Your original rules (if any) are backed up as /etc/iptables.rules.old-date-time. In addition, edit /etc/iptables/rules.v4 if the file exists.
Edit /etc/sysconfig/iptables and remove unneeded rules. Your original rules (if any) are backed up as /etc/sysconfig/iptables.old-date-time.
Note: If using Rocky Linux, AlmaLinux or CentOS/RHEL 8 and firewalld was active during VPN setup, nftables may be configured. Edit /etc/sysconfig/nftables.conf and remove unneeded rules. Your original rules are backed up as /etc/sysconfig/nftables.conf.old-date-time.
Edit /etc/sysctl.conf and remove the lines after # Added by hwdsl2 VPN script.
Edit /etc/rc.local and remove the lines after # Added by hwdsl2 VPN script. DO NOT remove exit 0 (if any).
Note: This step is optional.
Remove these config files:
- /etc/ipsec.conf*
- /etc/ipsec.secrets*
- /etc/ppp/chap-secrets*
- /etc/ppp/options.xl2tpd*
- /etc/pam.d/pluto
- /etc/sysconfig/pluto
- /etc/default/pluto
- /etc/ipsec.d (directory)
- /etc/xl2tpd (directory)
Copy and paste for fast removal:
rm -f /etc/ipsec.conf* /etc/ipsec.secrets* /etc/ppp/chap-secrets* /etc/ppp/options.xl2tpd* \
/etc/pam.d/pluto /etc/sysconfig/pluto /etc/default/pluto
rm -rf /etc/ipsec.d /etc/xl2tpdRemove IKEv2 script:
rm -f /usr/bin/ikev2.sh /opt/src/ikev2.shReboot your server.
Copyright (C) 2016-2021 Lin Song
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License
Attribution required: please include my name in any derivative and let me know how you have improved it!

