Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # LAN interface
- LAN_IF="eth0"
- # WAN interface
- WAN_IF="eth1"
- # IP WAN interface
- WAN_IP="110.120.130.205"
- # gateway
- WAN_GW="110.120.130.254"
- # LAN netmask
- LAN_NET="10.0.0.0/24"
- # WAN netmask
- WAN_NET="110.120.130.0/24"
- ####################
- # Очистить все правила
- iptables -P INPUT ACCEPT
- iptables -P FORWARD ACCEPT
- iptables -P OUTPUT ACCEPT
- iptables -t nat -P PREROUTING ACCEPT
- iptables -t nat -P POSTROUTING ACCEPT
- iptables -t nat -P OUTPUT ACCEPT
- iptables -t mangle -P PREROUTING ACCEPT
- iptables -t mangle -P OUTPUT ACCEPT
- iptables -F
- iptables -t nat -F
- iptables -t mangle -F
- iptables -X
- iptables -t nat -X
- iptables -t mangle -X
- ### Правила по умолчанию
- iptables -P INPUT DROP
- iptables -P FORWARD DROP
- iptables -P OUTPUT ACCEPT
- # Разрешаем localhost и локалку
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A INPUT -i $LAN_IF -j ACCEPT
- iptables -A OUTPUT -o lo -j ACCEPT
- iptables -A OUTPUT -o $LAN_IF -j ACCEPT
- # Разрешаем установленные подключения
- iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
- iptables -A OUTPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
- iptables -A FORWARD -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
- # Отбрасываем неопознанные пакеты
- iptables -A INPUT -m state --state INVALID -j DROP
- iptables -A FORWARD -m state --state INVALID -j DROP
- # Отбрасываем нулевые пакеты
- iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
- # Закрываемся от syn-flood атак
- iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
- iptables -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
- # Разрешаем все исходящие подключения сервера
- iptables -A OUTPUT -o $WAN_IF -j ACCEPT
- # Закрываем доступ снаружи в локалку
- iptables -A FORWARD -i $WAN_IF -o $LAN_IF -j REJECT
- # Фильтруем по mac-адресу
- #iptables -I FORWARD -m mac --mac-source 94:DE:80:A1:1D:BF -j DROP
- #iptables -I FORWARD -m mac --mac-source 00:02:44:1f:d1:78 -j DROP
- #iptables -I FORWARD -m mac --mac-source 00:50:22:B4:E7:B2 -j DROP
- #iptables -I FORWARD -m mac --mac-source * -j DROP
- ### ПОРТЫ
- # Открываем доступ к SSH
- iptables -A INPUT -p tcp --dport 44022 -j ACCEPT
- # Открываем доступ к RDP rinetd
- iptables -A INPUT -p tcp --dport 55555 -j ACCEPT
- # Открываем доступ к RDP iptables
- iptables -A INPUT -p tcp --dport 3389 -j ACCEPT
- # Открываем доступ к web серверу
- iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
- # p2p синхронизация
- iptables -A INPUT -p tcp -m tcp --dport 4444 -j ACCEPT
- iptables -A INPUT -i $WAN_IF -p tcp --dport 22000 -j ACCEPT
- # Синхронизация времени
- iptables -A INPUT -p tcp -i $LAN_IF --dport 123 -j ACCEPT
- iptables -A INPUT -p udp -i $LAN_IF --dport 123 -j ACCEPT
- # Разрешить запросы к кэширующему DNS серверу только из локальной сети
- iptables -A INPUT -p TCP -s $LAN_NET --dport 53 -j ACCEPT
- iptables -A INPUT -p UDP -s $LAN_NET --dport 53 -j ACCEPT
- # Разрешаем пинги
- iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
- iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
- iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
- iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
- # Разрешаем доступ из локалки наружу
- iptables -A FORWARD -i $LAN_IF -o $WAN_IF -j ACCEPT
- ### ПРОБРОС ПОРТВ
- # Пробросить порт на локальный веб сервер на нестандартный порт
- #iptables -t nat -A PREROUTING -p TCP -d $WAN_IP --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
- #iptables -t nat -A PREROUTING -p tcp -m tcp -d $WAN_IP --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
- #iptables -t nat -A POSTROUTING -p tcp -m tcp -d 10.0.0.10 --sport 3389 -j SNAT --to-source $WAN_IP:3389
- iptables -t nat -A PREROUTING -d $WAN_IP -p tcp --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
- iptables -t filter -A FORWARD -m state --state NEW -p tcp --dport 3389 -j ACCEPT
- ### SQUID
- # Переадресация 80 и 443 портов на прозрачный сквид
- iptables -t nat -A PREROUTING -p tcp -m tcp -s 10.0.0.0/24 --dport 443 -j REDIRECT --to-ports 3443
- iptables -t nat -A PREROUTING -p tcp -m multiport -s 10.0.0.0/24 --dports 80,81,82,88,1080,3127,3128,7900,8000,8080,8081,8088,8123,8888,9090 -j REDIRECT --to-ports 3080
- ### NAT
- # Включить NAT для локальной подсети
- iptables -t nat -A POSTROUTING -s $LAN_NET -o $WAN_IF -j SNAT --to-source $WAN_IP
- #iptables -t nat -F POSTROUTING
- #iptables -t nat -A POSTROUTING -s $LAN_NET -o $WAN_IF -j MASQUERADE
- ### Сохраняем правила
- /sbin/iptables-save > /etc/iptables.rules
- iptables-restore < /etc/iptables.rules
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement