iptables Linux防火墙配置工具
来源:互联网 发布:淘宝nala彩妆是正品吗 编辑:程序博客网 时间:2024/05/17 23:20
iptables Linux防火墙配置工具
iptables 是一个配置 Linux 内核 防火墙 的命令行工具
基础架构
- 请看http://lesca.me/archives/iptables-tutorial-structures-configuratios-examples.html
- 以及https://wiki.archlinux.org/index.php/Iptables_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
查看当前规则
sudo iptables -nvL --line-numbers
[admin 23:20:38 ~]:sudo iptables -nvL –line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 416 37142 ACCEPT all – * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 0 0 ACCEPT icmp – * * 0.0.0.0/0 0.0.0.0/0
3 0 0 ACCEPT all – lo * 0.0.0.0/0 0.0.0.0/0
4 3 156 ACCEPT tcp – * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 43 4411 REJECT all – * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 0 0 REJECT all – * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 265 packets, 43025 bytes)
num pkts bytes target prot opt in out source destination
每个链中都显示了通过该链的包数和字节数
重置规则
iptables -Z //封包计数清零
iptables -F //刷新链
iptables -X //清除默认规则
iptables -t nat -F //指定表
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t raw -F
iptables -t raw -X
iptables -t security -F
iptables -t security -X
iptables -P INPUT ACCEPT //设定默认进入系统的数据包处理规则
iptables -P FORWARD ACCEPT //设定默认进入系统需要转发的数据包处理规则
iptables -P OUTPUT ACCEPT //设定默认从系统发出的数据包处理规则
编辑规则
有两种方式添加规则,一种是在链上附加规则,另一种是将规则插入到链上某个特定位置。这里将讲解这两种方式。
一个建议,由于我们的系统不是路由器,因此应该禁止所有的转发,用如下操作:
iptables -A FORWARD DROP
Dropbox 的局域网同步特性 — 每30秒广播数据包到所有可视的计算机,如果我们碰巧在一个拥有 Dropbox 客户端的局域网中,但是我们不想使用这个特性,那么我们希望拒绝这些数据包。
iptables -A INPUT -p tcp –dport 17500 -j REJECT –reject-with icmp-port-unreachable
现在,我们改变对 Dropbox 的看法,并且决定安装其到我们的计算机,我们也希望局域网同步,但是我们的网络只有一个特定的 IP 地址,因此需要使用 -R 参数来替换旧规则,10.0.0.85 是我们的另一个 IP 地址。
iptables -R INPUT 1 -p tcp –dport 17500 ! -s 10.0.0.85 -j REJECT –reject-with icmp-port-unreachable
因此我们写一条新规则来立即允许受信任的用户。使用 -I 参数来在旧规则前插入一条新规则:
iptables -I INPUT -p tcp –dport 17500 -s 10.0.0.85 -j ACCEPT -m comment –comment “Friendly Dropbox”
更改第二条规则,使其拒绝 17500 端口的任何数据包:
iptables -R INPUT 2 -p tcp –dport 17500 -j REJECT –reject-with icmp-port-unreachable
一套常用配置
iptables -P INPUT ACCEPT # 设置INPUT chain默认行为为接受
iptables -P OUTPUT ACCEPT # 设置OUTPUT chain默认行为为接受
iptables -P FORWARD ACCEPT # 设置FORWARD chain默认行为为接受
iptables -A INPUT -i lo -j ACCEPT # 接受本地会回环(127.0.0.1)
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT # 接受已建立的 联建和与已建立的链接有关系的链接
iptables -A INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT # 接受回显请求的ping
iptables -A INPUT -p tcp -m tcp –dport 22 -j ACCEPT # 开放ssh端口
iptables -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
iptables -A INPUT -p tcp -m udp –dport 443 -j ACCEPT
参考文档
- https://wiki.archlinux.org/index.php/Iptables_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
- http://www.mojidong.com/linux/2013/11/12/linux-iptables/
- http://lesca.me/archives/iptables-tutorial-structures-configuratios-examples.html
man 8 iptables
- iptables Linux防火墙配置工具
- Linux-iptables配置-防火墙配置
- Linux iptables 防火墙的配置
- linux操作系统防火墙iptables配置
- Linux防火墙iptables配置详解
- linux防火墙iptables的配置
- linux防火墙的配置iptables
- linux下IPTABLES配置详解 防火墙配置
- 【笔记】使用linux的防火墙配置工具会清除 iptables 的手工配置规则
- Linux防火墙IPTables配置方法详解
- linux下iptables防火墙配置基础
- Linux上iptables防火墙配置方法
- linux下iptables防火墙配置笔记
- Linux中iptables防火墙配置实例分享
- Linux学习笔记 --iptables防火墙配置
- Linux(CentOS)下,防火墙iptables配置
- Linux(CentOS)下,防火墙iptables配置
- 在linux下配置iptables防火墙
- WEB前端-HTML-常用标签
- android_assert目录下的文件
- asp HTTP 错误 500.21 - Internal Server Error
- 使用achartengine画图,双Y轴右侧标题文字显示不全
- C# 导出 Excel 封装类 代码
- iptables Linux防火墙配置工具
- 大数据IMF传奇行动绝密课程第26课:Spark Runtime内幕揭秘
- 2016暑假练习——线段树
- C# 用数据库读取Excel出现“定义了过多字段”错误的解决方法
- 2016.8.11
- php如何实现单例模式
- cscope
- 逗号表达式
- [HDU5828] Rikka with Sequence [2016 Multi-University Training Contest 8(2016多校联合训练8) 1008]