Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # rc.local-iptables.sh
- #
- # typical usage:
- # sudo /etc/rc.local-iptables.sh 95.31.39.132 10.216.1.187
- #if [ $# -ne 2 ]; then
- # echo "usage: rc.local-iptables.sh <PPP_IP> <REMOTE_PPP_IP>"
- # exit 1
- #fi
- #PPP_IP="$1"
- #REMOTE_PPP_IP="$2"
- #PPP_IP="95.31.39.132"
- #PPP_IP="95.165.96.9"
- PPP_IP="192.168.1.64"
- #PPP_IP="192.168.4.64"
- REMOTE_PPP_IP="10.216.1.187"
- iptables=/sbin/iptables
- ifconfig=/sbin/ifconfig
- ip=/sbin/ip
- cat=/bin/cat
- grep=/bin/grep
- head=/usr/bin/head
- tail=/usr/bin/tail
- awk=/usr/bin/awk
- sed=/bin/sed
- route=/sbin/route
- #BEELINE_IP="`$cat /var/lib/dhcp/dhclient.eth0.leases | $grep 'option routers' | $tail -1 | awk '{print $3}' | $sed 's/;//'`"
- BEELINE_IP="`$ifconfig eth0 | $head -n 2 | $tail -1 | $awk '{print $2;}' | $sed 's/addr://'`"
- #BEELINE_IP="$PPP_IP"
- echo "BEELINE_IP=\"${BEELINE_IP}\""
- LOCAL_NET="172.29.2.0/24"
- LOCAL_NET2="172.29.3.0/24"
- LOCAL_NET3="10.0.2.0/24"
- LOCAL_NS="172.29.2.3"
- sysctl net.netfilter.nf_conntrack_acct=1
- map_port_tcp()
- {
- NAME="$1"
- SRCPORT="$2"
- DSTPORT="$3"
- if [[ ! "$1" =~ /^[0-9.]+$/ ]]; then
- NAME=`host $1 $LOCAL_NS | awk '{print \$4}' | tail -n 1`
- fi
- if [ "$DSTPORT" != "" ]; then
- DSTPORT=":$DSTPORT"
- fi
- echo "map_port_tcp $SRCPORT => $NAME$DSTPORT"
- $iptables -A INPUT -p tcp -m multiport --dports $SRCPORT -j ACCEPT
- $iptables -t nat -A PREROUTING -p tcp -m multiport --dports $SRCPORT -j DNAT --to $NAME$DSTPORT
- }
- map_port_udp()
- {
- NAME="$1"
- SRCPORT="$2"
- DSTPORT="$3"
- if [[ ! "$1" =~ /^[0-9.]+$/ ]]; then
- NAME=`host $1 $LOCAL_NS | awk '{print \$4}' | tail -n 1`
- fi
- if [ "$DSTPORT" != "" ]; then
- DSTPORT=":$DSTPORT"
- fi
- echo "map_port_udp $SRCPORT => $NAME$DSTPORT"
- $iptables -A INPUT -p udp -m multiport --dports $SRCPORT -j ACCEPT
- $iptables -t nat -A PREROUTING -p udp -m multiport --dports $SRCPORT -j DNAT --to $NAME$DSTPORT
- }
- map_port()
- {
- map_port_tcp $@
- map_port_udp $@
- }
- echo -n "0" > /proc/sys/net/ipv4/ip_forward
- $iptables -F
- $iptables -t nat -F
- $iptables -t mangle -F
- $iptables -A INPUT -i wlan0 -j ACCEPT
- $iptables -A INPUT -i eth1 -j ACCEPT
- $ip route add $LOCAL_NET2 via 172.29.2.5
- $ip route add $LOCAL_NET3 via 172.29.2.5
- #ip firewall address-list \
- #add address=bt.t-ru.org comment=bt list=RuTracker \
- #add address=bt2.t-ru.org comment=bt2 list=RuTracker \
- #add address=bt3.t-ru.org comment=bt3 list=RuTracker \
- #add address=bt4.t-ru.org comment=bt4 list=RuTracker
- #ip firewall nat add chain=dstnat action=dst-nat to-addresses=px1.blockme.site to-ports=3128 protocol=tcp src-address=172.29.2.3 dst-address-list=RuTracker dst-port=80 log=no log-prefix=""
- #$iptables -A FORWARD -s 172.29.2.248 -j DROP
- #$iptables -A FORWARD -d 172.29.2.248 -j DROP
- #$iptables -A FORWARD -s 172.29.2.241 -j DROP
- #$iptables -A FORWARD -d 172.29.2.241 -j DROP
- #$iptables -A FORWARD -s 172.29.2.242 -j DROP
- #$iptables -A FORWARD -d 172.29.2.242 -j DROP
- #$iptables -A INPUT -p tcp -i ppp0 -d 178.248.233.4 --dport 80 -j DROP
- $iptables -A INPUT -i eth0 -p tcp --dport 139 -j DROP
- $iptables -A INPUT -i eth0 -p tcp --dport 445 -j DROP
- $iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
- $iptables -A INPUT -i eth0 -p udp --dport 443 -j ACCEPT
- $iptables -A OUTPUT -i eth0 -p tcp --sport 443 -j ACCEPT
- $iptables -A OUTPUT -i eth0 -p udp --sport 443 -j ACCEPT
- $iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
- #$iptables -A INPUT -i eth0 -p udp --dport 80 -j ACCEPT
- #$iptables -A INPUT -i eth1 -s 172.29.2.12 -p tcp --dport 139 -j DROP
- #$iptables -A INPUT -i eth1 -s 172.29.2.12 -p tcp --dport 445 -j DROP
- $iptables -A INPUT -s $LOCAL_NET2 -j ACCEPT
- $iptables -A INPUT -d $LOCAL_NET2 -j ACCEPT
- $iptables -A OUTPUT -s $LOCAL_NET2 -j ACCEPT
- $iptables -A OUTPUT -d $LOCAL_NET2 -j ACCEPT
- #$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.3 -p tcp --dport 3389 -j ACCEPT
- #$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.3 -p tcp --dport 3390 -j ACCEPT
- #$iptables -A INPUT -s 172.29.4.0/24 -d $LOCAL_NET -j ACCEPT
- #$iptables -A INPUT -p tcp --destination-port 6882 -j ACCEPT
- #$iptables -A OUTPUT -p tcp --destination-port 6882 -j ACCEPT
- #$iptables -A INPUT -p tcp --destination-port 6882 -j ACCEPT
- #$iptables -A OUTPUT -p tcp --destination-port 6882 -j ACCEPT
- $iptables -A INPUT -p udp --destination-port 16881 -j ACCEPT
- $iptables -A OUTPUT -p udp --destination-port 16881 -j ACCEPT
- $iptables -A INPUT -p udp --source-port 6881 -j ACCEPT
- $iptables -A OUTPUT -p udp --source-port 6881 -j ACCEPT
- $iptables -A INPUT -p udp --source-port 6882 -j ACCEPT
- $iptables -A OUTPUT -p udp --source-port 6882 -j ACCEPT
- $iptables -A INPUT -p udp --source-port 6883 -j ACCEPT
- $iptables -A OUTPUT -p udp --source-port 6883 -j ACCEPT
- #$iptables -A INPUT -p udp --destination-port 1701 -j ACCEPT
- #$iptables -A INPUT -p tcp --destination-port 1701 -j ACCEPT
- #$iptables -A INPUT -p tcp --destination-port 8080 -j ACCEPT
- #$iptables -A INPUT -p udp --destination-port 8080 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 80 -j ACCEPT
- #$iptables -A INPUT -p udp --destination-port 80 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 443 -j ACCEPT
- #$iptables -A INPUT -p udp --destination-port 443 -j ACCEPT
- $iptables -A OUTPUT -p tcp --source-port 443 -j ACCEPT
- #$iptables -A OUTPUT -p udp --source-port 443 -j ACCEPT
- #$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.2/32 -j DROP
- #$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.5/32 -j DROP
- ###$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.1/32 -j DROP
- #$iptables -A INPUT -s 172.29.4.0/24 -d 172.29.2.3/32 -j DROP
- # ban for Helenko
- #$iptables -A INPUT -s 172.29.2.23 -d 172.29.2.3 -j DROP
- #$iptables -A INPUT -s 172.29.2.3 -d 172.29.2.23 -j DROP
- #$iptables -A INPUT -s 172.29.2.35 -d 172.29.2.3 -j DROP
- #$iptables -A INPUT -s 172.29.2.3 -d 172.29.2.35 -j DROP
- # ban for Mama
- #echo ban maman
- #$iptables -A INPUT -s 172.29.2.128 -j DROP
- #$iptables -A INPUT -s 172.29.2.3 -d 172.29.2.128 -j DROP
- #echo maman ban
- #$iptables -A INPUT -s 172.29.2.3 -j DROP
- #$iptables -A INPUT -m iprange --src-range 172.29.2.15-172.29.2.224 -j DROP
- #$iptables -A INPUT -i eth0 -j ACCEPT
- #$iptables -A INPUT -i eth0 -s 10.197.77.43 -p tcp --destination-port 23125 -j ACCEPT
- if [ "$1" = "ban" ]; then
- for i in `seq 15 254`; do
- # if [[ ( "$i" = "15" ) || ( "$i" = "40" ) || ( "$i" = "48" ) || ( "$i" = "43" ) || ( "$i" = "45" ) ]]; then
- # continue
- # fi
- echo banning 172.29.2.$i
- $iptables -A INPUT -s 172.29.2.$i -j DROP
- $iptables -A FORWARD -s 172.29.2.$i -j DROP
- $iptables -A INPUT -s 172.29.2.3 -d 172.29.2.$i -j DROP
- done
- fi
- # $@%#### woman.ru ####%@$
- $iptables -A FORWARD -s 172.29.2.2 -p tcp -m string --string "vk.com" --algo kmp -j DROP
- #@$iptables -A FORWARD -d 172.29.2.5 -p tcp -m string --string "woman.ru" --algo kmp -j ACCEPT
- $iptables -A FORWARD -p tcp -m string --string "blackhole.beeline.ru" --algo kmp -j DROP
- $iptables -A FORWARD -s blackhole.beeline.ru -j DROP
- $iptables -A FORWARD -d blackhole.beeline.ru -j DROP
- $iptables -A FORWARD -s dsp-rambler.ru -j DROP
- $iptables -A FORWARD -d dsp-rambler.ru -j DROP
- $iptables -A FORWARD -s rt.bongacams11.com -j DROP
- # $iptables -A INPUT -i eth0 -s 10.197.77.43 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 6962 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 6982 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 6899 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 23880 -j ACCEPT
- $iptables -A INPUT -i lo -j ACCEPT
- $iptables -A INPUT -p tcp --syn -m limit --limit 5/h -i eth1 -j ACCEPT
- $iptables -A INPUT -p tcp --dport 110 -j ACCEPT
- $iptables -A INPUT -p tcp --sport 110 -j ACCEPT
- $iptables -A INPUT -p tcp --dport 143 -j ACCEPT
- echo handling icmp packets...
- $iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -d $PPP_IP -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
- $iptables -A OUTPUT -p icmp --icmp-type 0 -s $PPP_IP -d 0/0 -m state --state ESTABLISHED,RELATED -j ACCEPT
- echo finish handling icmp packets
- #$iptables -t nat -A PREROUTING -p tcp --dport 23125 -j REDIRECT --to-ports 22
- #$iptables -t nat -A PREROUTING -p tcp -i eth1 -d $PPP_IP --dport 23125 -j DNAT --to-destination 172.29.2.5:22
- ##$iptables -A FORWARD -s 172.29.4.0/24 -d 172.29.0.0/16 -j ACCEPT
- ##$iptables -A FORWARD -d 172.29.4.0/24 -s 172.29.0.0/16 -j ACCEPT
- #$iptables -A INPUT -i tun+ -j ACCEPT
- #$iptables -A FORWARD -i tun0 -s 172.29.4.0/24 -j ACCEPT
- $iptables -A FORWARD -p tcp -i eth1 -d 172.29.2.5 --dport 22 -j ACCEPT
- $iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
- #$iptables -t nat -A POSTROUTING -s $LOCAL_NET -j SNAT --to 10.216.1.126
- $iptables -A INPUT -p tcp --destination-port 6667 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 6668 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 6669 -j ACCEPT
- #$iptables -A INPUT -p tcp --destination-port 80 -j ACCEPT
- $iptables -A INPUT -p tcp --destination-port 8443 -j ACCEPT
- #map_port joybook.metanet 23128 22
- #map_port uembox.metanet 23128 3389
- #map_port uembox.metanet 5938 5938
- map_port metamini.metanet 2010:2020
- #map_port joybook.metanet 2010:2020
- #map_port metabook.metanet 22575 22575
- #map_port metabook.metanet 22381 22381
- map_port metabook.metanet 23122 22
- map_port blackbox.metanet 23123 22
- map_port blackbox.metanet 25 25
- #map_port metabook.metanet 143 143
- #map_port metabook.metanet 993 993
- #map_port blackbox.metanet 80 80
- #map_port blackbox.metanet 443 443
- map_port blackbox.metanet 6883 6883
- map_port blackbox.metanet 6882 6882
- map_port metamini.metanet 23125 22
- #map_port socfpga.metanet 23124 22
- #map_port blackbox.metanet 2226 22
- #map_port_tcp metabook.metanet 28888 3389
- #map_port_tcp metamini.metanet 28889 3389
- #map_port blackbox.metanet 6881 6881
- map_port metabook.metanet 7881 7881
- map_port metabook.metanet 8881 8881
- $iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
- $iptables -A INPUT -p udp --dport 500 -j ACCEPT
- $iptables -A INPUT -p udp --dport 4500 -j ACCEPT
- $iptables -A INPUT -p esp -j ACCEPT
- $iptables -A INPUT -p ah -j ACCEPT
- map_port ubuntu.metanet 500 500
- map_port ubuntu.metanet 4500 4500
- map_port ubuntu.metanet 1701 1701
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o eth0 -m policy --dir out --pol ipsec -j ACCEPT
- $iptables -t nat -A POSTROUTING -m policy --pol ipsec --dir out -j ACCEPT
- $iptables -t nat -A PREROUTING -i eth1 -p udp -d 194.186.172.221 --dport 500 -j DNAT --to-destination 172.29.2.14
- $iptables -t nat -A PREROUTING -i eth1 -p udp -d 194.186.172.221 --dport 4500 -j DNAT --to-destination 172.29.2.14
- $iptables -A FORWARD -p udp -d 172.29.2.14 --dport 500 -j ACCEPT
- $iptables -A FORWARD -p udp -d 172.29.2.14 --dport 4500 -j ACCEPT
- $iptables -t nat -A POSTROUTING -p udp -s 172.29.2.14 --sport 500 -j SNAT --to-source 194.186.172.221
- $iptables -t nat -A POSTROUTING -p udp -s 172.29.2.14 --sport 4500 -j SNAT --to-source 194.186.172.221
- #iptables -t nat -A POSTROUTING --destination 10.0.0.1/32 -j SNAT --to-source 10.0.0.160
- #$iptables -t nat -A INPUT -p udp -s 172.29.2.14 -d 194.186.172.221 -j SNAT --to-source 95.165.96.9
- #$iptables -t nat -A POSTROUTING -s 172.29.2.14 -d 194.186.172.221 --protocol TCP -j SNAT --to-source 95.165.96.9
- #map_port metabook.metanet 6882 6882
- #map_port metamini.metanet 6885 6885
- #map_port metabook.metanet 56055 56055
- #map_port joybook.metanet 23880 1194
- #map_port joybook.metanet 33890 3389
- #map_port metamini.metanet 8080 80
- for arg in "$@"; do
- case "${arg}" in
- "--sip")
- map_port w7.metanet 4443 4443
- # map_port w7.metanet 443 443
- map_port w7.metanet 3478 3478
- map_port w7.metanet 444 444
- map_port w7.metanet 67 67
- map_port w7.metanet 68 68
- map_port w7.metanet 5061 5061
- map_port w7.metanet 6891:6901
- map_port w7.metanet 6902:65535
- map_port w7.metanet 3478 3478
- map_port w7.metanet 50000:59999
- ;;
- *)
- esac
- done
- #map_port w7.metanet 3451 3451
- #map_port w7.metanet 8080 8080
- #map_port w7.metanet 5070 5070
- #map_port w7.metanet 5071 5071
- #map_port w7.metanet 5072 5072
- #map_port w7.metanet 5073 5073
- #map_port w7.metanet 5075 5075
- #map_port w7.metanet 5076 5076
- #map_port w7.metanet 5080 5080
- #map_port w7.metanet 5061 5061
- #map_port w7.metanet 5269 5269
- #map_port w7.metanet 5061 5061
- #map_port w7.metanet 443 443
- #map_port w7.metanet 80 80
- $iptables -A INPUT -p tcp --destination-port 56055 -j ACCEPT
- $iptables -A INPUT -p udp --destination-port 56055 -j ACCEPT
- $iptables -A INPUT -p udp --destination-port 6882 -j ACCEPT
- $iptables -A INPUT -p udp --destination-port 6885 -j ACCEPT
- $iptables -A OUTPUT -p udp --source-port 6882 -j ACCEPT
- #$iptables -t mangle -A PREROUTING -p tcp -d $PPP_IP -m multiport --dports 23880 -j MARK --or-mark 0x12226
- #$iptables -t mangle -A PREROUTING -p tcp -d $BEELINE_IP -m multiport --dports 23880 -j MARK --or-mark 0x12226
- $iptables -t mangle -A PREROUTING -p tcp -d $BEELINE_IP -m multiport --dports 23123 -j MARK --or-mark 0x12225
- $iptables -t mangle -A PREROUTING -p tcp -d $PPP_IP -m multiport --dports 23123 -j MARK --or-mark 0x12225
- $iptables -t mangle -A PREROUTING -p tcp -d $PPP_IP -m multiport --dports 23125 -j MARK --or-mark 0x12225
- $iptables -t mangle -A PREROUTING -p tcp -d $PPP_IP -m multiport --dports 4422 -j MARK --or-mark 0x12225
- $iptables -t filter -A INPUT -m mark --mark 0x10000/0x10000 -j ACCEPT
- $iptables -t nat -A PREROUTING -p tcp -m mark --mark 0x12225 -j REDIRECT --to-ports 22
- #$iptables -t nat -A PREROUTING -p tcp -m mark --mark 0x12226 -j REDIRECT --to-ports 1194
- #$iptables -A INPUT -i ppp+ -j LOG
- #$iptables -A INPUT -i eth0 -j LOG
- #$iptables -A FORWARD -i ppp+ -j LOG
- #$iptables -A FORWARD -i eth0 -j LOG
- $iptables -A INPUT -i eth1 -s $LOCAL_NET -j ACCEPT
- $iptables -A INPUT -i eth1 -s $LOCAL_NET2 -j ACCEPT
- $iptables -A INPUT -i eth1 -s $LOCAL_NET3 -j ACCEPT
- $iptables -A INPUT -i ppp+ -m state --state NEW -j DROP
- $iptables -A INPUT -i eth0 -m state --state NEW -j DROP
- $iptables -t mangle -A FORWARD -p tcp -s $LOCAL_NET -o ppp+ --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
- $iptables -t mangle -A FORWARD -p tcp -s $LOCAL_NET2 -o ppp+ --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
- #$iptables -t mangle -A FORWARD -p tcp -s $LOCAL_NET -o ppp+ --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 600
- if [[ `false` ]]; then
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o ppp+ -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -o ppp+ -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET3 -o ppp+ -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o wlan+ -j MASQUERADE
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -o wlan+ -j MASQUERADE
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET3 -o wlan+ -j MASQUERADE
- else
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o eth0 -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -o eth0 -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET3 -o eth0 -j SNAT --to $PPP_IP
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o wlan+ -j MASQUERADE
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -o wlan+ -j MASQUERADE
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET3 -o wlan+ -j MASQUERADE
- fi
- #$iptables -t nat -A POSTROUTING -s $LOCAL_NET -j SNAT --to 172.29.4.1
- #$iptables -t nat -A POSTROUTING -s $LOCAL_NET -o tun0 -j SNAT --to 172.29.4.1
- $iptables -t nat -A POSTROUTING -d $LOCAL_NET3 -j ACCEPT
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET3 -j ACCEPT
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -d $LOCAL_NET2 -j ACCEPT
- #$iptables -t nat -A POSTROUTING -s $LOCAL_NET -d $LOCAL_NET2 -j SNAT --to 172.29.4.1
- $iptables -t nat -A POSTROUTING -d $LOCAL_NET -j ACCEPT
- $iptables -t nat -A POSTROUTING -d $LOCAL_NET2 -j ACCEPT
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -j ACCEPT
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET -o eth0 -j SNAT --to ${BEELINE_IP}
- $iptables -t nat -A POSTROUTING -s $LOCAL_NET2 -o eth0 -j SNAT --to ${BEELINE_IP}
- #$iptables -t nat -A POSTROUTING -s $LOCAL_NET -o eth0 -j SNAT --to 10.216.1.126
- echo -n "1" > /proc/sys/net/ipv4/ip_forward
- echo -n "1" > /proc/sys/net/ipv4/ip_dynaddr
- #$ip route add 172.29.4.0/24 via 172.29.2.14
- #$ip route add 172.29.2.101/32 via 172.29.2.2
- #$route add default gw $REMOTE_PPP_IP
- #$route add default gw 172.29.4.1 dev wlan0 metric 1
- #$ip route add 172.29.4.0/24 via 172.29.2.2
- $iptables -I INPUT -p tcp --sport 443 --tcp-flags RST RST -j DROP
- echo 128 > /proc/sys/net/ipv4/ip_default_ttl
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment