码迷,mamicode.com
首页 > 其他好文 > 详细

iptables(2)

时间:2018-10-01 11:56:38      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:拨号连接   转换   post   6.2   表示   ping   防火   内网   x86_64   


MASQUERADE同样是做源地址转换,只不过防火墙会根据该策略自动查找可用的公网IP地址,适应变化的情况
?若接口使用ppp+,表示匹配ppp0、ppp1……中任意可用的拨号连接
?若需要演示操作,可以针对前一个SNAT策略的例子进行改写(因没有ADSL连接,接口仍然使用eth0):
先执行“iptables -t nat -F”清空nat表
再添加规则“iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE”

?讲解应用DNAT策略的基本步骤,其中涉及到的相关操作
?同样可适当强调:外网测试机并不需要将默认网关地址设为该Linux网关主机的IP地址
?确认路由功能状态时,可以执行sysctl命令查看:
[root@gateway ~]# sysctl -a | grep "ip_forward"
net.ipv4.ip_forward = 1

执行 “elinks http://218.29.30.29” 或者“lynx http://218.29.30.29”均可以进行测试
[root@localhost ~]# tail -f /var/log/httpd/access_log
218.29.30.29 - - [04/Jun/2009:14:35:53 +0800] "GET / HTTP/1.1" 200 15 "-" "ELinks/0.11.1 (textmode; Linux; 80x25-2)"


NAT转换
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth1 -j SNAT --to-source 218.29.30.31
先执行“iptables -t nat -F”清空nat表
再添加规则“iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE”
[root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
[root@gateway ~]# sysctl -a | grep "ip_forward" net.ipv4.ip_forward = 1
iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.6
[root@localhost ~]# iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 2222 -j DNAT --to-destination
192.168.1.5:22
--------------------------理解ESTABLISHED
vm1
# iptables -P INPUT DROP
ping 192.168.56.201
ssh 192.168.56.201

全部失败
# iptables -A INPUT -p all -m state --state ESTABLISHED -j ACCEPT
ping 192.168.56.201
ssh 192.168.56.201
全部成功

vm2关闭防火墙
成功穿越反向防火墙。
tracerout 192.168.56.201 失败 ,原因看下面


--------------------------理解RELATE
vm1
# iptables -P INPUT DROP
# iptables -F
# iptables -A INPUT -p all -m state --state RELATED -j ACCEPT
tracerout 192.168.56.201 成功。由第一个包产生的其他回包都属于RELATE状态。


--------------------------理解NEW
vm1
OUTPUT默认策略为DROP。其他策略为ACCEPT
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT DROP
# iptables -F
ping 192.168.56.201
ssh 192.168.56.201
全部失败
# iptables -A OUTPUT -p all -m state --state ESTABLISHED,NEW -j ACCEPT


--------------------------理解INVALID
他需要特殊的第一条黑客工具产生,所以这里面紧急下面的用法。
通常应用在INPUT表的第一条。
# iptables -A INPUT -p all -m state --state INVALID -j DROP


--------------------------SNAT-内网访问外网
-------外网 --------------------网关防火墙-------------------内网PC1 192.168.56.202
10.0.100 eth0 eth1
10.0.1.200 192.168.56.200
内网:yum install elinks lynx -y
网关防火墙
# iptables -t nat -A POSTROUTING -s 192.168.56.202 -o eth0 -j SNAT --to-source 10.0.1.200
外网:httpd
# tailf /var/log/httpd/access_log


--------------------------DNAT-对外发布端口
外网:yum install elinks lynx -y
网关防火墙:
# iptables -t nat -A PREROUTING -i eth0 -d 10.0.1.200 -p tcp --dport 2345 -j DNAT --to-destination 192.168.56.202:80
内网:httpd
# tailf /var/log/httpd/access_log
内核模块存放位置
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/ipv4/netfilter/ //ipv4支持
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/ipv6/netfilter/ //ipv6支持
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/netfilter/ //同时支持
lsmod 查看当前的模块

 

iptables(2)

标签:拨号连接   转换   post   6.2   表示   ping   防火   内网   x86_64   

原文地址:https://www.cnblogs.com/luoyan01/p/9734261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!