2022-07-29 07:55:47 +03:00
[English ](uninstall.md ) | [中文 ](uninstall-zh.md )
2016-06-24 02:10:25 +03:00
2022-07-29 07:55:47 +03:00
# Uninstall the VPN
2016-06-25 01:54:24 +03:00
2021-09-29 07:13:45 +03:00
* [Uninstall using helper script ](#uninstall-using-helper-script )
* [Manually uninstall the VPN ](#manually-uninstall-the-vpn )
2021-09-07 10:56:49 +03:00
## Uninstall using helper script
2016-06-24 02:10:25 +03:00
2022-05-15 17:50:49 +03:00
To uninstall IPsec VPN, run the [helper script ](../extras/vpnuninstall.sh ):
2021-09-07 10:56:49 +03:00
2022-05-21 03:07:55 +03:00
**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** !
2021-09-07 10:56:49 +03:00
```bash
2022-10-15 07:35:22 +03:00
wget https://get.vpnsetup.net/unst -O unst.sh & & sudo bash unst.sh
2021-09-07 10:56:49 +03:00
```
2022-06-03 16:29:09 +03:00
< details >
< summary >
Alternative commands.
< / summary >
You may also use `curl` to download:
```bash
2022-10-15 07:35:22 +03:00
curl -fsSL https://get.vpnsetup.net/unst -o unst.sh & & sudo bash unst.sh
2022-06-03 16:29:09 +03:00
```
Alternative script URLs:
```bash
https://github.com/hwdsl2/setup-ipsec-vpn/raw/master/extras/vpnuninstall.sh
https://gitlab.com/hwdsl2/setup-ipsec-vpn/-/raw/master/extras/vpnuninstall.sh
```
< / details >
2021-09-07 10:56:49 +03:00
## Manually uninstall the VPN
2022-05-15 23:07:23 +03:00
Alternatively, you may manually uninstall IPsec VPN by following these steps. Commands must be run as `root` , or with `sudo` .
2021-09-07 10:56:49 +03:00
2021-10-10 07:44:25 +03:00
**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** !
2021-09-07 10:56:49 +03:00
### Steps
2016-06-24 02:16:01 +03:00
* [First step ](#first-step )
* [Second step ](#second-step )
* [Third step ](#third-step )
* [Fourth step ](#fourth-step )
* [Optional ](#optional )
* [When finished ](#when-finished )
2021-09-07 10:56:49 +03:00
### First step
2016-06-25 01:54:24 +03:00
2017-02-05 23:48:11 +03:00
```bash
2016-06-24 02:10:25 +03:00
service ipsec stop
service xl2tpd stop
2021-09-09 08:22:34 +03:00
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.conf
2016-06-24 02:10:25 +03:00
```
2021-09-07 10:56:49 +03:00
### Second step
2016-06-24 02:10:25 +03:00
2021-09-07 10:56:49 +03:00
#### Ubuntu & Debian
2016-06-24 02:10:25 +03:00
2016-06-29 22:35:28 +03:00
`apt-get purge xl2tpd`
2016-06-24 02:10:25 +03:00
2022-03-21 07:10:40 +03:00
#### CentOS/RHEL, Rocky Linux, AlmaLinux, Oracle Linux & Amazon Linux 2
2016-06-24 02:10:25 +03:00
`yum remove xl2tpd`
2021-09-11 23:34:15 +03:00
#### Alpine Linux
`apk del xl2tpd`
2021-09-07 10:56:49 +03:00
### Third step
2016-06-24 02:10:25 +03:00
2021-09-11 23:34:15 +03:00
#### Ubuntu, Debian & Alpine Linux
2016-06-24 02:10:25 +03:00
2020-05-25 22:20:32 +03:00
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.
2016-06-24 02:10:25 +03:00
2022-03-21 07:10:40 +03:00
#### CentOS/RHEL, Rocky Linux, AlmaLinux, Oracle Linux & Amazon Linux 2
2016-06-24 02:10:25 +03:00
2020-05-25 22:20:32 +03:00
Edit `/etc/sysconfig/iptables` and remove unneeded rules. Your original rules (if any) are backed up as `/etc/sysconfig/iptables.old-date-time` .
2022-03-21 07:10:40 +03:00
**Note:** If using Rocky Linux, AlmaLinux, Oracle Linux 8 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` .
2016-06-24 02:10:25 +03:00
2021-09-07 10:56:49 +03:00
### Fourth step
2016-06-24 02:10:25 +03:00
2016-06-25 01:54:24 +03:00
Edit `/etc/sysctl.conf` and remove the lines after `# Added by hwdsl2 VPN script` .
2016-06-25 04:42:57 +03:00
Edit `/etc/rc.local` and remove the lines after `# Added by hwdsl2 VPN script` . DO NOT remove `exit 0` (if any).
2016-06-24 02:10:25 +03:00
2021-09-07 10:56:49 +03:00
### Optional
2016-06-24 02:10:25 +03:00
2020-05-25 22:20:32 +03:00
**Note:** This step is optional.
2016-06-25 04:42:57 +03:00
2016-06-24 02:10:25 +03:00
Remove these config files:
2016-06-25 01:54:24 +03:00
2016-06-29 22:35:28 +03:00
* /etc/ipsec.conf*
* /etc/ipsec.secrets*
* /etc/ppp/chap-secrets*
* /etc/ppp/options.xl2tpd*
2016-06-24 02:10:25 +03:00
* /etc/pam.d/pluto
* /etc/sysconfig/pluto
2016-06-29 22:35:28 +03:00
* /etc/default/pluto
2016-06-25 04:42:57 +03:00
* /etc/ipsec.d (directory)
2016-06-29 22:35:28 +03:00
* /etc/xl2tpd (directory)
2016-06-24 02:10:25 +03:00
2016-06-25 01:54:24 +03:00
Copy and paste for fast removal:
2017-02-05 23:48:11 +03:00
```bash
2016-06-29 22:35:28 +03:00
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/xl2tpd
2016-06-25 04:42:57 +03:00
```
2016-06-24 02:10:25 +03:00
2022-09-10 07:53:53 +03:00
Remove helper scripts:
2021-09-25 16:35:55 +03:00
```bash
2022-09-10 07:53:53 +03:00
rm -f /usr/bin/ikev2.sh /opt/src/ikev2.sh \
/usr/bin/addvpnuser.sh /opt/src/addvpnuser.sh \
/usr/bin/delvpnuser.sh /opt/src/delvpnuser.sh
```
Remove fail2ban:
**Note:** This is optional. Fail2ban can help protect SSH on your server. Removing it is NOT recommended.
```bash
service fail2ban stop
# Ubuntu & Debian
apt-get purge fail2ban
# CentOS/RHEL, Rocky Linux, AlmaLinux, Oracle Linux & Amazon Linux 2
yum remove fail2ban
# Alpine Linux
apk del fail2ban
2021-09-25 16:35:55 +03:00
```
2021-09-07 10:56:49 +03:00
### When finished
2016-06-24 02:10:25 +03:00
Reboot your server.
2021-03-29 23:05:45 +03:00
## License
2022-01-02 09:09:03 +03:00
Copyright (C) 2016-2022 [Lin Song ](https://github.com/hwdsl2 ) [![View my profile on LinkedIn ](https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x25.png )](https://www.linkedin.com/in/linsongui)
2021-03-29 23:05:45 +03:00
2021-06-05 01:27:21 +03:00
[![Creative Commons License ](https://i.creativecommons.org/l/by-sa/3.0/88x31.png )](http://creativecommons.org/licenses/by-sa/3.0/)
This work is licensed under the [Creative Commons Attribution-ShareAlike 3.0 Unported License ](http://creativecommons.org/licenses/by-sa/3.0/ )
2021-03-29 23:05:45 +03:00
Attribution required: please include my name in any derivative and let me know how you have improved it!