Hi
ich hab mich mal mit den Iptables versucht und wollte mal wissen, was ihr davon haltet.
Der script basiert auf dem Tutorial von iptables-tutorial.frozentux.net wurde etwas abgespeckt und für meine Bedürfnisse angepasst (IRC, ICQ und jabber sollen irgentwann nochmal folgen, genau so, wie eine IP zu einem Windows Rechner im Netzwerk der vollen uneingeschränkten Zugriff haben darf.)
Ich übernehme keine Garanie, falls den Script jemand bei sich zu Hause mal testet
Das ist jetzt alles ein bisschen improvisiert und der Versuch nur firefox den Internetzugriff zu erlauben ist auch kläglich gescheitert. Aber was denkt ihr davon? Ist das ein passabler einstieg für einen Linux Noob?
MFG
KoRny
ich hab mich mal mit den Iptables versucht und wollte mal wissen, was ihr davon haltet.
Der script basiert auf dem Tutorial von iptables-tutorial.frozentux.net wurde etwas abgespeckt und für meine Bedürfnisse angepasst (IRC, ICQ und jabber sollen irgentwann nochmal folgen, genau so, wie eine IP zu einem Windows Rechner im Netzwerk der vollen uneingeschränkten Zugriff haben darf.)
Ich übernehme keine Garanie, falls den Script jemand bei sich zu Hause mal testet
Code:
#!/bin/sh
###########################################################################
#
# 1. Configuration options.
#
echo "======START======"
INET_IFACE="eth0"
LAN_IP="192.168.*.*"
ROUTER="192.168.*.*"
LAN_IP_RANGE="192.168.*.*/16"
LAN_IFACE="eth1"
LO_IFACE="lo"
LO_IP="127.0.0.1"
IPTABLES="/usr/sbin/iptables"
USER="username"
BROWSER="firefox"
#PID_BROWSER=`ps aux |grep $BROWSER |head -n 5 |cut -b 10-14`
#SID_BROWSER=`ps -eo sid,args |grep $BROWSER |head -n 1 |cut -b 1-5`
#echo "firefox pid: "
#echo $PID_BROWSER
#echo " "
#echo "firefox sid:"
#echo $SID_BROWSER
##
##Alte Config löschen
##
iptables -F INPUT
iptables -P INPUT DROP
iptables -F FORWARD
iptables -P FORWARD DROP
iptables -F OUTPUT
iptables -P OUTPUT DROP
iptables -F icmp_packets
iptables -F udp_packets
iptables -F bad_tcp_packets
iptables -F allowed
iptables -F tcp_packets
iptables -X allowed
iptables -X bad_tcp_packets
iptables -X icmp_packets
iptables -X tcp_packets
iptables -X udp_packets
###########################################################################
#
# 2. Module loading.
#
#
# Needed to initially load modules
#
/sbin/depmod -a
#
# 2.1 Required modules
#
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_MASQUERADE
#
# 2.2 Non-Required modules
#-s $LAN_IP
/sbin/modprobe ipt_owner
#/sbin/modprobe ipt_REJECT
#/sbin/modprobe ip_conntrack_ftp
#/sbin/modprobe ip_conntrack_irc
#/sbin/modprobe ip_nat_ftp
#/sbin/modprobe ip_nat_irc
/bin/echo "0" > /proc/sys/net/ipv4/ip_forward
# Diese Option benötigt nur ein Router, ein Host
# mit mehreren Netzwerk-Interfaces. Dies sollte
# also bei Ihnen per Default ausgeschlatet sein.
#
#pings deaktivieren
/bin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
#broadcats pings deaktivieren
/bin/echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Deaktivierung von "source routed packets"
/bin/echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
#max connections
#/bin/echo "32760" > /proc/sys/net/ipv4/ip_conntrack_max
# 3.2 Non-Required proc configuration
#echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
#echo "1" > /proc/sys/net/ipv4/conf/all/proxy_arp
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -N bad_tcp_packets
$IPTABLES -N allowed
$IPTABLES -N tcp_packets
$IPTABLES -N udp_packets
$IPTABLES -N icmp_packets
#log leeren
#echo "" > /var/log/firewall
$IPTABLES -A tcp_packets -p TCP -j ACCEPT
$IPTABLES -A udp_packets -p UDP -j ACCEPT
$IPTABLES -A OUTPUT -m owner --uid-owner root -j LOG --log-prefix "========= Root Inet Zugriff: "
$IPTABLES -A OUTPUT -m owner --uid-owner root -j DROP
$IPTABLES -A OUTPUT -m owner ! --uid-owner $USER -j LOG --log-prefix "other user than $USER: "
$IPTABLES -A OUTPUT -m owner --cmd-owner firefox-sh -j LOG
$IPTABLES -A OUTPUT -p TCP -s $LAN_IP --dport 80 -j tcp_packets
$IPTABLES -A OUTPUT -p UDP -s $LAN_IP -d $ROUTER --dport 53 -j udp_packets
$IPTABLES -A INPUT -p TCP -d $LAN_IP --sport 80 -j tcp_packets
$IPTABLES -A INPUT -p UDP -s $ROUTER -d $LAN_IP --sport 53 -j udp_packets
$IPTABLES -A OUTPUT -p TCP -s $LO_IP -d $LO_IP -j ACCEPT
$IPTABLES -A INPUT -p TCP -s $LO_IP -d $LO_IP -j ACCEPT
#$IPTABLES -A INPUT -p TCP -j tcp_packets # -i $INET_IFACE
#$IPTABLES -A OUTPUT -p TCP -j tcp_packets
#$IPTABLES -A INPUT -p UDP -i $INET_IFACE -j udp_packets
#$IPTABLES -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
echo "=====ENDE====="
MFG
KoRny