防火墙配置 linux
时间: 2023-09-25 16:09:05 浏览: 67
在Linux系统中配置防火墙可以使用iptables命令,以下是一个简单的防火墙配置示例:
1. 查看当前防火墙规则:
```
iptables -L
```
2. 清除当前防火墙规则:
```
iptables -F
```
3. 设置默认策略(允许所有流量或者拒绝所有流量):
- 允许所有流量:
```
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
```
- 拒绝所有流量:
```
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
```
4. 允许特定端口的流量通过(例如允许SSH连接):
```
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
```
5. 允许特定IP地址的流量通过(例如允许来自192.168.0.100的流量):
```
iptables -A INPUT -s 192.168.0.100 -j ACCEPT
```
6. 允许已经建立的连接通过:
```
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
```
7. 拒绝特定IP地址的流量(例如拒绝来自192.168.0.200的流量):
```
iptables -A INPUT -s 192.168.0.200 -j DROP
```
8. 保存防火墙配置:
```
iptables-save > /etc/iptables/rules.v4
```
请注意,以上只是一个简单的示例配置,具体配置需要根据实际需求进行调整。此外,对于不熟悉iptables的用户,也可以考虑使用一些基于iptables的防火墙管理工具,例如UFW(Uncomplicated Firewall)或Firewalld,它们提供了更友好的命令和配置方式。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)
![](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)