iptables重要的指令
时间: 2023-11-01 20:08:54 浏览: 129
iptables 是 Linux 系统下的一个防火墙工具,可以用来设置、管理和审计网络规则。以下是一些常用的 iptables 指令:
1. iptables -L:列出当前所有的规则;
2. iptables -F:清空所有规则;
3. iptables -A INPUT -p tcp --dport 80 -j ACCEPT:允许所有来源的 TCP 流量通过 80 端口;
4. iptables -A INPUT -s 192.168.1.0/24 -j DROP:拒绝来自 192.168.1.0/24 网段的所有流量;
5. iptables -A INPUT -p tcp --dport 22 -j ACCEPT:允许所有来源的 TCP 流量通过 22 端口(SSH)。
相关问题
iptables常用指令
iptables 是 Linux 系统中用于设置和管理防火墙规则的工具。以下是一些常用的 iptables 命令:
1. 查看当前防火墙规则
```
iptables -L
```
这个命令会列出当前所有的防火墙规则。
2. 清空所有防火墙规则
```
iptables -F
```
这个命令会清空所有防火墙规则。
3. 允许指定 IP 地址或 IP 地址段的访问
```
iptables -A INPUT -s 192.168.1.100 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -j ACCEPT
```
这个命令会允许来自 IP 地址为 192.168.1.100 或 IP 地址段为 192.168.2.0/24 的主机访问本机。
4. 允许指定端口的访问
```
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
```
这个命令会允许 TCP 端口号为 80 或 UDP 端口号为 53 的数据包访问本机。
5. 拒绝指定 IP 地址或 IP 地址段的访问
```
iptables -A INPUT -s 192.168.1.100 -j DROP
iptables -A INPUT -s 192.168.2.0/24 -j DROP
```
这个命令会拒绝来自 IP 地址为 192.168.1.100 或 IP 地址段为 192.168.2.0/24 的主机访问本机。
6. 拒绝指定端口的访问
```
iptables -A INPUT -p tcp --dport 22 -j DROP
iptables -A INPUT -p udp --dport 123 -j DROP
```
这个命令会拒绝 TCP 端口号为 22 或 UDP 端口号为 123 的数据包访问本机。
7. 允许所有本机发出的数据包
```
iptables -A OUTPUT -j ACCEPT
```
这个命令会允许本机发出的所有数据包。
8. 允许所有已建立的连接通过防火墙
```
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
```
这个命令会允许所有已建立的连接通过防火墙。
9. 禁止所有数据包通过防火墙
```
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
```
这个命令会禁止所有数据包通过防火墙,默认情况下所有数据包都会被拒绝。
iptables相关指令
iptables是Linux中一个强大的防火墙工具,可以通过一系列指令来配置和管理防火墙规则。以下是一些常用的iptables指令:
1. iptables -F:清空所有防火墙规则。
2. iptables -P INPUT DROP:设置默认输入策略为拒绝。
3. iptables -P OUTPUT DROP:设置默认输出策略为拒绝。
4. iptables -P FORWARD DROP:设置默认转发策略为拒绝。
5. iptables -A INPUT -p tcp --dport 22 -j ACCEPT:开放SSH端口(22)。
6. iptables -A INPUT -p tcp --dport 80 -j ACCEPT:开放HTTP端口(80)。
7. iptables -A INPUT -p tcp --dport 443 -j ACCEPT:开放HTTPS端口(443)。
8. iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT:允许192.168.1.0/24网段的IP访问本机。
9. iptables -A OUTPUT -d 192.168.1.0/24 -j ACCEPT:允许本机访问192.168.1.0/24网段的IP。
10. iptables -L:列出所有防火墙规则。
11. iptables -nvL:列出所有防火墙规则,并显示数据包计数信息。
12. iptables-save:将当前防火墙规则保存到文件中。
13. iptables-restore:从文件中加载防火墙规则。
注意:以上指令需要root权限才能执行,否则会提示权限不足。同时,配置防火墙时需要谨慎操作,以避免误操作导致网络不可用。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)