Remove a rule from iptables

To remove the last line of the iptables rule in the PREROUTING chain, you can delete it by specifying the chain and rule number. First, check the exact rule number with:

sudo iptables -t nat -L PREROUTING --line-numbers -v -n

This will display each rule in the PREROUTING chain with its corresponding line number.

Once you have identified the line number for the rule you want to delete (in your case, the last rule for UDP on enp1s0), use the following command to delete it:

sudo iptables -t nat -D PREROUTING [line-number]

Replace [line-number] with the actual line number of the rule to delete. For example, if the last rule is number 3, you would use:

sudo iptables -t nat -D PREROUTING 3

To remove the specific SNAT rule from the POSTROUTING chain, you can follow these steps:

  1. List the rules with line numbers to identify the exact rule number for the SNAT rule you want to delete:

    sudo iptables -t nat -L POSTROUTING --line-numbers -v -n
    
  2. Once you identify the rule number corresponding to this line:

    2787  528K SNAT       0    --  *      *       10.7.0.0/24         !10.7.0.0/24          to:45.77.43.22
    
  3. Use the iptables -t nat -D POSTROUTING [line-number] command to delete the rule. Replace [line-number] with the rule’s line number.

For example, if the SNAT rule is the 4th rule in the POSTROUTING chain, the command would be:

sudo iptables -t nat -D POSTROUTING 4

This will remove the specific SNAT rule from the POSTROUTING chain.

If you accidentally removed a rule:

Chain POSTROUTING (policy ACCEPT 51126 packets, 3774K bytes)
pkts bytes target prot opt in out source destination
111K 15M MASQUERADE all – * enp1s0 10.8.0.0/24 0.0.0.0/0

To restore the MASQUERADE rule, you can re-add it with the following command:

sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o enp1s0 -j MASQUERADE

This rule will ensure that traffic from the 10.8.0.0/24 OpenVPN network is masqueraded when leaving through the enp1s0 interface. This should fix the issue and restore OpenVPN functionality.

You can confirm that the rule has been re-added by listing the rules again:

sudo iptables -t nat -L POSTROUTING -v -n

sudo iptables -t nat -L POSTROUTING -v -n

## Linux 加固命令及步骤 Linux 加固命令主要有以下几个方面: ### 1. 禁用不必要的服务和端口 在 Linux 中,运行一些不必要的服务和开启不必要的端口都会增加系统被攻击的风险。因此,我们需要尽量禁用这些不必要的服务和端口。 具体步骤如下: 1. 首先,使用 `netstat -tulpn` 命令查看当前系统中所有正在运行的服务和端口。 2. 然后,根据需要,使用 `systemctl disable` 命令关闭不必要的服务。 3. 最后,使用 `firewall-cmd --zone=public --remove-port=端口号/tcp --permanent` 命令关闭不必要的端口。 ### 2. 增强密码策略 强密码策略可以有效地提高系统的安全性,防止被黑客猜解或者暴力破解密码。 具体步骤如下: 1. 修改 `/etc/login.defs` 文件,增加密码复杂度要求。 2. 修改 `/etc/pam.d/system-auth` 文件,增加密码复杂度要求。 3. 修改 `/etc/passwd` 文件,将用户的 shell 改为 `/sbin/nologin` 或 `/bin/false`。 ### 3. 安装安全软件 安全软件可以监控系统的安全状态,发现异常行为,及时阻止攻击。 具体步骤如下: 1. 安装主机防火墙,如 iptablesfirewalld。 2. 安装入侵检测软件,如 Snort 或 Tripwire。 3. 安装漏洞扫描软件,如 Nessus 或 OpenVAS。 ## Windows 加固命令及步骤 Windows 加固命令主要有以下几个方面: ### 1. 禁用不必要的服务和端口 与 Linux 类似,运行一些不必要的服务和开启不必要的端口都会增加系统被攻击的风险。 具体步骤如下: 1. 首先,使用 `netstat -ano` 命令查看当前系统中所有正在运行的服务和端口。 2. 然后,根据需要,使用 `sc config 服务名 start= disabled` 命令关闭不必要的服务。 3. 最后,使用 `netsh advfirewall firewall add rule name="规则名称" dir=in action=block protocol=TCP localport=端口号` 命令关闭不必要的端口。 ### 2. 增强密码策略 与 Linux 类似,强密码策略可以有效地提高系统的安全性。 具体步骤如下: 1. 打开“本地安全策略”,找到“账户策略”->“密码策略”,增加密码复杂度要求。 2. 打开“组策略编辑器”,找到“计算机配置”->“Windows 设置”->“安全设置”->“账户策略”->“密码策略”,增加密码复杂度要求。 ### 3. 安装安全软件 安装安全软件可以监控系统的安全状态,发现异常行为,及时阻止攻击。 具体步骤如下: 1. 安装杀毒软件,如 Windows Defender 或 Symantec Endpoint Protection。 2. 安装主机防火墙,如 Windows 自带防火墙或 Comodo Firewall。 3. 安装漏洞扫描软件,如 Nessus 或 OpenVAS。 ## MySQL 加固命令及步骤 MySQL 加固命令主要有以下几个方面: ### 1. 修改默认密码和用户名 MySQL 默认的用户名是 root,密码为空。这样的默认设置会给攻击者提供便利。 具体步骤如下: 1. 使用 `mysql -u root -p` 命令登录 MySQL。 2. 使用 `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';` 命令修改 root 用户的密码。 3. 使用 `CREATE USER '新用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';` 命令创建新用户。 ### 2. 禁用不必要的权限 MySQL 默认会给一些用户授予一些不必要的权限,如 FILE,PROCESS,SUPER,SHUTDOWN 等。 具体步骤如下: 1. 使用 `mysql -u root -p` 命令登录 MySQL。 2. 使用 `REVOKE 权限 ON 数据库名.* FROM '用户名'@'localhost';` 命令撤销不必要的权限。 ### 3. 安装安全插件 MySQL 提供了一些安全插件,可以增强服务器的安全性。 具体步骤如下: 1. 使用 `mysql -u root -p` 命令登录 MySQL。 2. 使用 `INSTALL PLUGIN 插件名 SONAME '插件文件.so';` 命令安装安全插件。 ## Linux 应急响应命令及步骤 Linux 应急响应命令主要有以下几个方面: ### 1. 关闭不必要的服务和端口 在 Linux 中,关闭不必要的服务和端口可以减小被攻击的风险。 具体步骤如下: 1. 使用 `netstat -tulpn` 命令查看当前系统中所有正在运行的服务和端口。 2. 使用 `systemctl stop 服务名` 命令关闭不必要的服务。 3. 使用 `firewall-cmd --zone=public --remove-port=端口号/tcp --permanent` 命令关闭不必要的端口。 ### 2. 查杀恶意进程 查杀恶意进程可以有效地防止攻击者进一步操作系统。 具体步骤如下: 1. 使用 `ps -ef` 命令查看当前系统中所有正在运行的进程。 2. 使用 `kill 进程号` 命令结束恶意进程。 ### 3. 备份重要数据 备份重要数据可以保护数据不被攻击者破坏或者篡改。 具体步骤如下: 1. 使用 `tar -cvpzf /backup/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys /` 命令备份系统重要文件。 2. 使用 `mysqldump -u 用户名 -p 数据库名 > 备份文件.sql` 命令备份 MySQL 数据库。 ## Windows 应急响应命令及步骤 Windows 应急响应命令主要有以下几个方面: ### 1. 关闭不必要的服务和端口 与 Linux 类似,关闭不必要的服务和端口可以减小被攻击的风险。 具体步骤如下: 1. 使用 `netstat -ano` 命令查看当前系统中所有正在运行的服务和端口。 2. 使用 `sc stop 服务名` 命令关闭不必要的服务。 3. 使用 `netsh advfirewall firewall add rule name="规则名称" dir=in action=block protocol=TCP localport=端口号` 命令关闭不必要的端口。 ### 2. 查杀恶意进程 与 Linux 类似,查杀恶意进程可以有效地防止攻击者进一步操作系统。 具体步骤如下: 1. 打开“任务管理器”,找到恶意进程。 2. 点击“结束进程”按钮结束恶意进程。 ### 3. 备份重要数据 与 Linux 类似,备份重要数据可以保护数据不被攻击者破坏或者篡改。 具体步骤如下: 1. 使用“文件资源管理器”或者“命令提示符”备份系统重要文件。 2. 使用 `mysqldump -u 用户名 -p 数据库名 > 备份文件.sql` 命令备份 MySQL 数据库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fareast_mzh

打赏个金币

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值