- 论坛徽章:
- 0
|
为什么请下以下iptables 脚本公网为什么不能通过公网IP(X.X.X.X)访问到内网的192.168.0.80:80的web页面
eth0 是对内
内网ip是 192。168。0。0/24
--------
都接在一个交换机上
----------
eth1 是对外
-----------------
#!/bin/bash
# var
my_forward_tcp=22,53,80,25,110,143,3128,8080,443
my_forward_udp=25,53,110,143
my_local_ports_tcp=21,20,53,39980,25,110,80,3128,137,139,445
my_local2_ports_tcp=8080
my_local_ports_udp=53,137,138
#my_SNAT=192.168.0.0/24
#my_DNAT=172.16.0.2:80
#ftp open zhuizong 1024+
modprobe ip_nat_ftp
#modprobe ip_conntrack_ftp ports=2121
# clear all rules
iptables -F
iptables -X
#iptables -Z (baoliu)
iptables -t nat -F
iptables -t nat -X
#iptables -t nat -Z(baoliu)
# Default rules
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
# SNAT rules
iptables -t nat -A PREROUTING -p tcp -d X.X.X.X --dport 80 -j DNAT --to-destination 192.168.0.80:80
#iptables -t nat -A PREROUTING -s 192.168.0.0/24 -p tcp --dport 80 -j REDIRECT --to 3128
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -m iprange ! --dst-range 192.168.0.1 -p tcp --dport 80 -j REDIRECT --to 3128
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source X.X.X.X
# FORWARD rules
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -I INPUT -p tcp --dport 8080 -j LOG --log-prefix "XXX" --log-tcp-options --log-ip-options
iptables -A OUTPUT -p tcp --dport 22 -m tos --tos 8 -j DROP
iptables -A INPUT -p icmp -m length --length 100:200 -m limit --limit 30/minute -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp -m multiport --dports $my_local_ports_tcp -j ACCEPT
iptables -A INPUT -m state --state NEW -p udp -m multiport --dports $my_local_ports_udp -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp -m multiport --dports $my_local2_ports_tcp -j ACCEPT
# FORWARD rules
#iptables -I FORWARD -p icmp -m iprange --src-range 192.168.0.2-192.168.0.254 --dst-range 192.168.0.2-192.168.0.254 -j DROP
#iptables -A FORWARD -p tcp -m iprange --dst-range 192.168.0.2-192.168.0.254 --syn -j DROP
iptables -A FORWARD -p icmp -m length --length 100:200 -m limit --limit 30/minute -j ACCEPT
iptables -A FORWARD -p tcp --dport 5000 -j ACCEPT
iptables -A FORWARD -p udp --dport 5000 -j ACCEPT
iptables -A FORWARD -p tcp --dport 8000 -j ACCEPT
iptables -A FORWARD -p udp --dport 8000 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -p tcp -m multiport --dports $my_forward_tcp -j ACCEPT
iptables -A FORWARD -m state --state NEW -p udp -m multiport --dports $my_forward_udp -j ACCEPT
#iptables -I FORWARD -m state --state NEW -p icmp -j ACCEPT |
|