[spoileriptables.sh]
Код: Выделить всё
#!/bin/sh
PROXY_PORT=3128
MYHOST='192.168.0.1' # Server Address
LAN='192.168.0.0/24' # Internal Network Address
WAN='212.112.x.x' #External Network Address AkNET
WAN2='89.237.x.x' #KTNET
EX_ETH=eth0
EX2_ETH=eth3
IN_ETH=eth1
# Load ip_conntrack_ftp #
modprobe ip_conntrack_ftp
modprobe iptable_nat
### iptables command path ###
IPTABLES='/usr/sbin/iptables'
### Stop IP forward ###
echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward
# Initialize all the chains by removing all the rules tied to them
$IPTABLES --flush
$IPTABLES -t nat --flush
$IPTABLES -t mangle --flush
# Delete user defined chains
$IPTABLES --delete-chain
$IPTABLES -t nat --delete-chain
$IPTABLES -t mangle --delete-chain
$IPTABLES -t filter -F > /dev/null 2>&1
$IPTABLES -t filter -X > /dev/null 2>&1
$IPTABLES -t nat -F > /dev/null 2>&1
$IPTABLES -t nat -X > /dev/null 2>&1
$IPTABLES -t mangle -F > /dev/null 2>&1
$IPTABLES -t mangle -X > /dev/null 2>&1
$IPTABLES -t filter -P INPUT ACCEPT > /dev/null 2>&1
$IPTABLES -t filter -P OUTPUT ACCEPT > /dev/null 2>&1
$IPTABLES -t filter -P FORWARD ACCEPT > /dev/null 2>&1
$IPTABLES -t nat -P PREROUTING ACCEPT > /dev/null 2>&1
$IPTABLES -t nat -P POSTROUTING ACCEPT > /dev/null 2>&1
$IPTABLES -t nat -P OUTPUT ACCEPT > /dev/null 2>&1
$IPTABLES -t mangle -P POSTROUTING ACCEPT > /dev/null 2>&1
$IPTABLES -t mangle -P OUTPUT ACCEPT > /dev/null 2>&1
$IPTABLES -t mangle -P PREROUTING ACCEPT > /dev/null 2>&1
$IPTABLES -t mangle -P INPUT ACCEPT > /dev/null 2>&1
$IPTABLES -t mangle -P FORWARD ACCEPT > /dev/null 2>&1
## Drop all rules in default ### INPUT DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
## Accept any to loopback address ###
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
### Accept DNS from LAN ###
$IPTABLES -A INPUT -p udp --dport 53 -j ACCEPT
$IPTABLES -A OUTPUT -p udp --sport 53 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
## Allow DNS to access external network ###
$IPTABLES -A OUTPUT -p udp --dport 53 -j ACCEPT
$IPTABLES -A INPUT -p udp --sport 53 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
## Allow LAN to access NTP request ###
$IPTABLES -A INPUT -p udp -s $LAN --dport 123 -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d $LAN --sport 123 -j ACCEPT
### Allow SNMP
$IPTABLES -A INPUT -p tcp --dport 3401 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --sport 3401 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 3401 -j ACCEPT
$IPTABLES -A OUTPUT -p udp --sport 3401 -j ACCEPT
### Allow NTP server to access external NTP servers ###
$IPTABLES -A OUTPUT -d $NTP1 -p udp --dport 123 -j ACCEPT
$IPTABLES -A INPUT -s $NTP1 -p udp --sport 123 -j ACCEPT
#### Allow PPTP connection
$IPTABLES -A INPUT -p gre -j ACCEPT
$IPTABLES -A OUTPUT -p gre -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 47 -j ACCEPT
$IPTABLES -A INPUT -p tcp --dport 1723 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --sport 1723 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --sport 47 -j ACCEPT
### Accept file sharing (NetBIOS) within LAN ###
$IPTABLES -A INPUT -p udp -s $LAN --dport 137:139 -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d $LAN --sport 137:139 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 137:139 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW -d $LAN --dport 137:139 -j ACCEPT
$IPTABLES -A OUTPUT -p udp -d $LAN --sport 32772 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 32772 -j ACCEPT
### Accept SWAT(SWAT:901) from LAN ###
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 901 -j ACCEPT
### Accept Proxy (PROXY:3128) from LAN ###
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 3128 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 9443 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 1812 -j ACCEPT
### Accept SSH (22) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --sport 22 -j ACCEPT
### Accept netams (20001) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 20001 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW -d $LAN --sport 20001 -j ACCEPT
### Accept RDP (3389) from LAN ###
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --sport 3389 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW -d $LAN --dport 3389 -j ACCEPT
### Accept WWW (HTTP:80,HTTPS:443) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
### Accept WEBMIN (HTTPS:10080)
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 10080 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW -d $LAN --sport 10080 -j ACCEPT
### Allow access to external WWW servers(HTTP:80,HTTPS:443) ###
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8443 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8443 -j ACCEPT
### Accept FTP (Active/Passive) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 21 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 4000:4029 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 4000:4029 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --sport 20 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 21 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 20 -j ACCEPT
### Accept p2p networks ###
#$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 6880:6889 -j ACCEPT
#$IPTABLES -A INPUT -p udp -m state --state NEW --sport 6880:6889 -j ACCEPT
#$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 6880:6889 -j ACCEPT
#$IPTABLES -A OUTPUT -p udp -m state --state NEW --dport 6880:6889 -j ACCEPT
### ICQ ###
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 5190 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 5190 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 2042 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 2042 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 5222 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 5222 -j ACCEPT
### Wurth ###
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8090 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 8090 -j ACCEPT
### BTA-bank ###
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 1979 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW --sport 1979 -j ACCEPT
### Accept MTA (SMT?:25/465) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT
### Allow access to external MTA (SMTP:25,POP3:110) ###
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --sport 110 -j ACCEPT
### Accept MTA (POP3:110,IMAP:143) ###
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 110 -j ACCEPT
$IPTABLES -A INPUT -p tcp -m state --state NEW -s $LAN --dport 143 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW -d $LAN --sport 143 -j ACCEPT
### Accept DHCP request only from LAN ###
$IPTABLES -A INPUT -p udp -m state --state NEW --dport 67:68 --sport 67:68 -j ACCEPT
$IPTABLES -A OUTPUT -p udp -m state --state NEW --dport 67:68 --sport 67:68 -j ACCEPT
$IPTABLES -A FORWARD -p udp -m state --state NEW --dport 67:68 --sport 67:68 -j ACCEPT
### REJECT Ident(113) (DROP is slower than Reject) ###
$IPTABLES -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset
### PING ###
$IPTABLES -A INPUT -p icmp -j ACCEPT
$IPTABLES -A OUTPUT -p icmp -j ACCEPT
$IPTABLES -A OUTPUT -p icmp -j ACCEPT
$IPTABLES -A INPUT -p icmp -j ACCEPT
### Accept established packet ###
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
### Transparent Proxy ###
$IPTABLES -t nat -A PREROUTING -p tcp -i $IN_ETH --dport 80 -j REDIRECT --to-port $PROXY_PORT
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp+ --dport 80 -j REDIRECT --to-port $PROXY_PORT
$IPTABLES -t nat -A PREROUTING -i $EX_ETH -p tcp --dport 3389 -j DNAT --to-destination 192.168.0.2:3389
$IPTABLES -t nat -A POSTROUTING -p tcp --dport 3389 -d 192.168.0.2 -j SNAT --to $WAN
### NAT for etc
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.2 -p tcp -m multiport --dports 20,21,5222,6880:6889 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.66 -p tcp -m multiport --dports 20,21,25,110,995,2042,1979,5190,5191,6880:6889,8080 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.70 -p tcp -m multiport --dports 20,21 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.25 -p tcp -m multiport --dports 9050:9060 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.23 -p tcp -m multiport --dports 1979 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -s 192.168.0.11 -p tcp -m multiport --dports 1979 -j MASQUERADE
$IPTABLES -A FORWARD -p gre -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -p gre -m state --state ESTABLISHED,RELATED -j ACCEPT
в итоге имеем геморрой что не проходит traceroute даже непосредственно с гетвея...
выдает вот такой мусор:
[spoilerответ tracerout`a]
Код: Выделить всё
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется
send failed: Операция не позволяется