YAIS (Yet Another IPFW Script)
Добавлено: 2013-11-13 10:09:21
Их уже тьма тьмущая, но вопросов от этого меньше не становится.
Так что может кому и пригодится.
L2TP, таблицы, ядреный нат, прозрачный сквид, openvpn
Так что может кому и пригодится.
L2TP, таблицы, ядреный нат, прозрачный сквид, openvpn
Код: Выделить всё
#!/bin/sh
# Firewall command
fwcmd='/sbin/ipfw -q'
# Network interfaces
int_if="bge0" # Internal
ext_if="re0" # External (ISP network)
l2tp_if="ng0" # L2TP/PPTP (Internet)
vpn_if="tun0" # OpenVPN
# L2TP/PPTP IP address
l2tp_ip=`ifconfig ${l2tp_if} | awk '$1=="inet"{print $2}'`
# Netbios ports
netbios="81,137,138,139"
# Tables
nonroute="table(0)" # Nonroutable networks
squid="table(1)" # Squid users
# Flush all rules and tables
${fwcmd} flush
${fwcmd} table all flush
# Populate tables
for file in /etc/ipfw_*; do
table=`echo ${file} | awk -F '_' '{print $2}'`
for ip in `grep "^[0-9]" ${file}`; do
case ${table} in
nonroute)
${fwcmd} table 0 add ${ip};;
squid)
${fwcmd} table 1 add ${ip};;
esac
done
done
# Allow all on loopback
${fwcmd} add allow ip from any to any via lo0
# Transparent squid
${fwcmd} add fwd 127.0.0.1,3129 tcp from ${squid} to not me 80 in recv ${int_if}
# Allow all on local and OpenVPN networks
${fwcmd} add allow all from any to any via ${int_if}
${fwcmd} add allow all from any to any via ${vpn_if}
# Deny nonroutable networks and netbios incoming traffic on internet interface
${fwcmd} add deny ip from any to ${nonroute} in recv ${l2tp_if}
${fwcmd} add deny ip from ${nonroute} to any in recv ${l2tp_if}
${fwcmd} add deny ip from any ${netbios} to any in recv ${l2tp_if}
# Deny fragmented and broadcasted icmp packets
${fwcmd} add deny icmp from any to any frag
${fwcmd} add deny icmp from any to 255.255.255.255 via ${l2tp_if}
# NAT on external interface (ISP network)
${fwcmd} nat 1 config log if ${ext_if} reset same_ports deny_in
${fwcmd} add nat 1 ip from any to any via ${ext_if}
# NAT on L2TP/PPTP interface (Internet)
${fwcmd} nat 2 config log if ${l2tp_if} reset same_ports deny_in\
redirect_port udp ${l2tp_ip}:1194 1194\ # Local OpenVPN server
redirect_port tcp ${l2tp_ip}:80 80\ # Local Web server
${fwcmd} add nat 2 ip from any to any via ${l2tp_if}
# Default deny
${fwcmd} add deny log all from any to any