Выместите на мне всю злость в эту пятницу, укажите все ошибки и недочеты! В перерывах подскажите пожалуйста, почему проброс 3389 с внешки не работает? Я точно забыл какую-то деталь, но не пойму что. И можно ли удобней организовать управление вланами? Мне нужно чтобы из vlan_2 в lan (и обратно) был доступен 123, а из lan в vlan_2 можно было достучаться по 3389, 16135. Остальное закрыть.
Из vlan_3 должен быть доступен хост из сети LAN - 10.0.0.212 и только он, остальное закрыть.
Я от всего этого с ума уже схожу, помоги, дорогой ЛОР. Внешние адреса и маки изменены. Лучше чем code=bash для читаемости ничего не придумал.
# IPTABLES FIREWALL
#
SYSCTL="/sbin/sysctl -w"
IPT="/sbin/iptables"
IPTS="/sbin/iptables-save"
IPTR="/sbin/iptables-restore"
WAN_IF="ppp0"
WAN_IP="xx.xx.xx.xx"
LAN_IF="eth0"
LAN_IP="10.0.0.1"
LAN_NET="10.0.0.1/21"
LAN_BCAST="10.0.7.255"
VLAN_2_IF="eth0.2"
VLAN_2_NET="192.168.0.1/24"
VLAN_3_IF="eth0.3"
VLAN_3_NET="192.0.0.1/24"
WHITE_NET="88.88.88.0/27"
NAS_IF="eth2"
NAS_NET="192.168.10.10/24"
LO_IF="lo"
LO_IP="127.0.0.1"
DNS_SRV_01="10.0.0.27"
DNS_SRV_02="10.0.0.28"
if [ "$1" = "save" ]
then
echo -n "Saving firewall to /etc/sysconfig/iptables ... "
$IPTS > /etc/sysconfig/iptables
echo "done"
exit 0
elif [ "$1" = "restore" ]
then
echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
$IPTR < /etc/sysconfig/iptables
echo "done"
exit 0
fi
/sbin/modprobe 8021q
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ipt_conntrack
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_MASQUERADE
/sbin/modprobe ipt_owner
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_REDIRECT
/sbin/modprobe ipt_mark
/sbin/modprobe ipt_tcpmss
/sbin/modprobe ipt_multiport
/sbin/modprobe ipt_state
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe ip_conntrack_pptp
/sbin/modprobe ip_nat_pptp
if [ "$SYSCTL" = "" ]
then
echo "1" > /proc/sys/net/ipv4/ip_forward
else
$SYSCTL net.ipv4.ip_forward="1"
fi
if [ "$SYSCTL" = "" ]
then
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
else
$SYSCTL net.ipv4.tcp_syncookies="1"
fi
if [ "$SYSCTL" = "" ]
then
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
else
$SYSCTL net.ipv4.icmp_echo_ignore_broadcasts="1"
fi
if [ "$SYSCTL" = "" ]
then
echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
else
$SYSCTL net.ipv4.conf.all.accept_source_route="0"
fi
if [ "$SYSCTL" = "" ]
then
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
else
$SYSCTL net.ipv4.conf.all.accept_redirects="0"
fi
if [ "$SYSCTL" = "" ]
then
echo "1" > /proc/sys/net/ipv4/conf/all/secure_redirects
else
$SYSCTL net.ipv4.conf.all.secure_redirects="1"
fi
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
$IPT -t mangle -P PREROUTING ACCEPT
$IPT -t mangle -P OUTPUT ACCEPT
$IPT -F
$IPT -t nat -F
$IPT -t mangle -F
$IPT -X
$IPT -t nat -X
$IPT -t mangle -X
if [ "$1" = "stop" ]
then
echo "Firewall completely flushed! Now running with no firewall."
exit 0
fi
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT ACCEPT
$IPT -N bad_packets
$IPT -N bad_tcp_packets
$IPT -N icmp_packets
$IPT -N upd_input
$IPT -N tcp_input
$IPT -N tcp_ports_forward_allowed
$IPT -N udp_ports_forward_allowed
$IPT -N mac_forward_allowed
$IPT -N white_forward_allowed
$IPT -N published_service
#
$IPT -A bad_packets -p ALL -i $WAN_IF -s $LAN_NET -j DROP
$IPT -A bad_packets -p ALL -m conntrack --ctstate INVALID -j DROP
$IPT -A bad_packets -p TCP -j bad_tcp_packets
$IPT -A bad_packets -p ALL -j RETURN
#
$IPT -A bad_tcp_packets -p TCP -i $LAN_IF -j RETURN
$IPT -A bad_tcp_packets -p TCP ! --syn -m conntrack --ctstate NEW -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags ALL NONE -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags ALL ALL -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags ALL FIN,URG,PSH -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags SYN,RST SYN,RST -j DROP
$IPT -A bad_tcp_packets -p TCP --tcp-flags SYN,FIN SYN,FIN -j DROP
$IPT -A bad_tcp_packets -p TCP -j RETURN
#
$IPT -A icmp_packets --fragment -p ICMP -j DROP
$IPT -A icmp_packets -p ICMP -j RETURN
#
$IPT -A upd_input -p UDP -s 0/0 --dport 137 -j DROP
$IPT -A upd_input -p UDP -s 0/0 --dport 138 -j DROP
$IPT -A upd_input -p UDP -j RETURN
#
$IPT -A tcp_input -p TCP -s 0/0 --dport 80 -j ACCEPT
$IPT -A tcp_input -p TCP -s 0/0 --dport 25 -j ACCEPT
$IPT -A tcp_input -p TCP -s 0/0 --dport 110 -j ACCEPT
$IPT -A tcp_input -p TCP -s 0/0 --dport 143 -j ACCEPT
$IPT -A tcp_input -p TCP -s 0/0 --dport 8523 -j ACCEPT
$IPT -A tcp_input -p TCP -j RETURN
#
$IPT -A tcp_ports_forward_allowed -p TCP --dport 25 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP --dport 587 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP --dport 110 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP --dport 143 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP --dport 995 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP -s $DNS_SRV_01 --dport 53 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP -s $DNS_SRV_02 --dport 53 -j ACCEPT
$IPT -A tcp_ports_forward_allowed -p TCP -j RETURN
#
$IPT -A udp_ports_forward_allowed -p UDP --dport 4433 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP --dport 4440 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP --dport 7500 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP --dport 500 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP --dport 4500 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP -s $DNS_SRV_01 --dport 53 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP -s $DNS_SRV_02 --dport 53 -j ACCEPT
$IPT -A udp_ports_forward_allowed -p UDP -j RETURN
#
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT
$IPT -A mac_forward_allowed -p ALL -j RETURN
#
$IPT -A white_forward_allowed -p ALL -s 88.88.88.1 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -d 88.88.88.2 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -s 88.88.88.3 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -d 88.88.88.4 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -s 88.88.88.5 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -d 88.88.88.6 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -s 88.88.88.7 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -d 88.88.88.8 -j ACCEPT
$IPT -A white_forward_allowed -p ALL -j RETURN
#
$IPT -A published_service -p TCP --dport 3389 --destination 10.0.0.66 -j ACCEPT
$IPT -A published_service -j RETURN
$IPT -A INPUT -p ALL -i $LO_IF -j ACCEPT
$IPT -A INPUT -p ALL -j bad_packets
$IPT -A INPUT -p ALL -i $LAN_IF -s $LAN_NET -j ACCEPT
$IPT -A INPUT -p ALL -i $LAN_IF -d $LAN_BCAST -j ACCEPT
$IPT -A INPUT -p TCP -i $WAN_IF -j tcp_input
$IPT -A INPUT -p UDP -i $WAN_IF -j upd_input
$IPT -A INPUT -p ICMP -i $WAN_IF -j icmp_packets
$IPT -A INPUT -p ALL -i $WAN_IF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -p ALL -j bad_packets
$IPT -A FORWARD -i $LAN_IF -p icmp -j ACCEPT
$IPT -A FORWARD -p TCP -i $LAN_IF -s $LAN_NET -j tcp_ports_forward_allowed
$IPT -A FORWARD -p UDP -i $LAN_IF -s $LAN_NET -j udp_ports_forward_allowed
$IPT -A FORWARD -p ALL -i $LAN_IF -s $LAN_NET -j mac_forward_allowed
$IPT -A FORWARD -s $WHITE_NET -o $WAN_IF -j white_forward_allowed
$IPT -A FORWARD -i $WAN_IF -d $WHITE_NET -j white_forward_allowed
$IPT -A FORWARD -i $WAN_IF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -p ALL -i $WAN_IF -j published_service
$IPT -A FORWARD -p ALL -i $VLAN_2_IF -o $LAN_IF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPT -A FORWARD -p UDP -i $LAN_IF -o $VLAN_2_IF --dport 123 -j ACCEPT
$IPT -A FORWARD -p TCP -i $LAN_IF -o $VLAN_2_IF --dport 3389 -j ACCEPT
$IPT -A FORWARD -p TCP -i $LAN_IF -o $VLAN_2_IF --dport 16135 -j ACCEPT
$IPT -A FORWARD -p UDP -i $VLAN_2_IF -o $LAN_IF --dport 123 -j ACCEPT
$IPT -A FORWARD -p ALL -i $VLAN_3_IF -d 10.0.0.212 -j ACCEPT
$IPT -A FORWARD -p ALL -i $LAN_IF -s 10.0.0.212 -o $VLAN_3_IF -d $VLAN_3_NET -j ACCEPT
$IPT -A OUTPUT -p icmp -m conntrack --ctstate INVALID -j DROP
$IPT -t nat -A PREROUTING -p tcp -i $WAN_IF --dport 3389 -j DNAT --to-destination 10.0.0.66
$IPT -t nat -A POSTROUTING -o $WAN_IF -j SNAT --to-source $WAN_IP
echo "Done!"