Linux之iptables使用
2015-11-24 00:18
363 查看
netfilter | | |
3表 | Filter表:(默认表)防火墙相关 NAT表:snat(源地址转换)、dnat(目标地址转换)、pnat(目标端口转换) Mangle表:修改报文再整合 Raw | |
iptables 内置链 | PREROUTING:数据包进入路由表之前 | |
INPUT:通过路由表后目的地为本机(过滤进入本机的数据包,攻击) | ||
FORWARDING:通过路由表后,目的地不为本地(经过而不入主机NAT相关) | ||
OUTPUT:由本机产生,向外转发(处理本机发出的数据包,泄密) | ||
POSTROUTING:发送到网卡接口之前 | ||
规则 | iptables [-t 表名] -命令 -匹配 -j 动作/目标 -s:源IP段 -d:目标网段 -i:数据流入的网口eth0 -o:数据流出的网口eth0 -p:协议tcp udp 对于严谨的规则,一般默认规则都是拒绝未知,允许已知 | |
iptables具备的3表5链 | ||
编号 | 命令 | |
1 |
| |
查看filter表 | ||
2 | iptables -t nat -L | |
查看nat表 | ||
3 | iptables -t mangle -L | |
查看mangle表 | ||
4 | iptables -F iptables -Z | |
清除所选链中的所有规则 计数器清零 | ||
4 | iptables -A INPUT | |
为INPUT链追加 | ||
5 | iptables -t filter -P INPUT -j DROP 丢弃 iptables -t filter -P INPUT -j REJECT 拒绝 iptables -t filter -P INPUT -j ACCEPT 接受 iptables -t filter -P INPUT -j RETURN 返回主链继续匹配 iptables -t filter -P INPUT -j REDIRECT 端口重定向 iptables -t filter -P INPUT -j MASQUERADE地址伪装 iptables -t filter -P INPUT -j DNAT|SNAT 地址转换 iptables -t filter -P INPUT -j MARK 打标签 iptables -t filter -P INPUT LOG | |
设置filter表INPUT链的默认Policy为丢弃 SNAT:代理内部客户端访问外部网络,在POSTROUTING或OUTPUT链上来做规则限制 DNAT:将内部服务器公开至外部网络,需在PREROUTING做限制 | ||
6 | iptables -N filter_web iptables -X iptables -E | |
自定义链被调用才发挥作用 清除filter中使用者自定链中的规则(X Z同理),内置链不能删除 重命名自定义链 | ||
7 | | |
| ||
8 | iptables -t nat -A iptables -t nat -I3 iptables -t nat -D iptables -t nat -R3 | |
nat表末尾追加规则 nat插入为第3条规则 删除第几条规则 替换第几条规则 | ||
9 | iptables -A INPUT -s 10.0.10.0/24 -d 10.0.10.0/24 -j ACCEPT iptables -A INPUT -s 10.0.10.0/24 -d 10.0.10.0/24 -I eth0 -j ACCEPT | |
允许10.0.10.0/24网段的ip地址访问 只允许指定网段10.0.10.0/24内的IP可以访问到eth0网卡 | ||
10 | iptables-P INPUT DORP iptables-A INPUT -s 10.0.10.0/24 -d 10.0.10.0/24 -j ACCEPT iptables-P OUTPUT DORP iptables-A OUTPUT -d 10.0.10.0/24 -s 10.0.10.0/24-j ACCEPT | |
对于严谨的规则,一般默认规则都是拒绝未知,允许已知 | ||
11 | /etc/init.d/iptables save iptables-save > /tmp/iptables iptables-restore < /tmp/iptables | |
保存规则到默认配置 保存规则到其它文件 加载iptables文件规则 | ||
4 | iptables -A INPUT | |
为INPUT链追加 | ||
4 | iptables -A INPUT | |
为INPUT链追加 | ||
4 | iptables -A INPUT | |
为INPUT链追加 | ||
4 | iptables -A INPUT | |
为INPUT链追加 | ||
4 | iptables -A INPUT -d 10.0.10.62 -ptcp --dport 80 -j ACCEPT | |
放行对本机web的访问 | ||
4 | iptables -A OUTPUT -s 10.0.10.62 -p tcp --sport 80 -j ACCEPT | |
放行出去的报文,源端口未80 | ||
iptables -A OUTPUT -s 10.0.10.62 -d 10.0.10.0/24 -p icmp --icmp-type8 -j ACCEPT | ||
允许本机ping通 10.0.10.0/24网段 |
相关文章推荐
- Linux之route配置
- Linux之ifconfig命令
- Linux之网卡配置
- Linux之DHCPD服务配置
- Linux之DNS服务配置
- Linux rpm命令参数使用大全(经典)
- 解压rpm包的linux命令及rpm命令使用简介
- 详解Linux 操作系统下安装rpm包的方法步骤
- Linux 中 RPM包 安装 查询 卸载命令小结及yum命令详解
- linux系统启动过程分析
- SSH操作linux命令
- linux 常用命令
- linux环境变量
- Linux 网桥设置固定MAC
- 在LINUX下面建立GPRS无线MODEM拨号
- TQ210 NFS服务器的配置和使用
- Linux里find和grep命令
- Linux使用ssh-keygen实现SSH无密码登录
- Linux系统挂载点与分区的关系
- Linux Is Not Matrix——Jenkins的安装和启动