cubic83
Goto Top

Firewall mit IPTables

Hallo,

ich habe ein Problem mit meiner Firewall. Der Server hat 2 Netzwerkkarten und ist auf der einen Seite direkt an das DSL Modem angeschlossen und an der anderen Seite an ein Switch fürs LAN. Ich möchte nun das ich aus dem LAN auf einen POP3 Server im Internet zugreifen kann.

Das geht ja normalerweise mit iptables -A FORWARD. Das klappt aber in meinem Fall leider nicht und ich finde einfach den Fehler nicht. Ich weiss auch leider nicht wo ich den Fehler suchen soll. Liegt das Problem eventuell in dem Netzwerkaufbau - 2 x /8ter Netz?

Details:

eth0 (10.0.0.1o/8) -> LAN
eth1 (10.0.0.9/8) -> Zum DSL Modem (=10.0.0.1)

Routenkonfiguration mittels route:

#routes.sh:
#***********

route add -host 10.0.0.1 dev eth1
route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
route add default gw 10.0.0.1

Firewallscript:

#firewall.sh:
#************

#!/bin/bash

modprobe ip_tables
modprobe ip_conntrack
modprobe ip_conntrack_irc
modprobe ip_conntrack_ftp

iptables -F

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

#Connection-Tracking aktivieren
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#PORT 995 (POP3 - SSL) 
iptables -A FORWARD -m state --state NEW -p tcp --dport 995 -j ACCEPT
iptables -A FORWARD -m state --state NEW -p udp --dport 995 -j ACCEPT

# ICMP Echo-Request (ping) zulassen und beantworten
iptables -A INPUT -m state --state NEW -p icmp --icmp-type echo-request -j ACCEPT

# Forwarding/Routing
echo "Aktiviere IP-Routing"  
echo 1 > /proc/sys/net/ipv4/ip_forward 2> /dev/null

# SYN-Cookies
echo 1 > /proc/sys/net/ipv4/tcp_syncookies 2> /dev/null

# Stop Source-Routing
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_source_route 2> /dev/null; done

# Stop Redirecting
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_redirects 2> /dev/null; done

# Reverse-Path-Filter
for i in /proc/sys/net/ipv4/conf/*; do echo 2 > $i/rp_filter 2> /dev/null; done

# BOOTP-Relaying ausschalten
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/bootp_relay 2> /dev/null; done

# Proxy-ARP ausschalten
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/proxy_arp 2> /dev/null; done

# Ungltige ICMP-Antworten ignorieren
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses 2> /dev/null

# ICMP Echo-Broadcasts ignorieren
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 2> /dev/null

# Max. 500/Sekunde (5/Jiffie) senden
echo 5 > /proc/sys/net/ipv4/icmp_ratelimit

# Speicherallozierung und -timing für IP-De/-Fragmentierung
echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
echo 30 > /proc/sys/net/ipv4/ipfrag_time

# TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

# Maximal 3 Antworten auf ein TCP-SYN
echo 3 > /proc/sys/net/ipv4/tcp_retries1


Der Übersichtlichkeitshalber habe ich jetzt die Standardregeln weggelassen. Die Ausgabe von Route und iptables -L zeigt an:

#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.1        *               255.255.255.255 UH    0      0        0 eth1
10.0.0.0        *               255.0.0.0       U     0      0        0 eth0
default         10.0.0.1        0.0.0.0         UG    0      0        0 eth1

# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     0    --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:webcache 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:https 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:10022 
ACCEPT     icmp --  anywhere             anywhere            state NEW icmp echo-request 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:domain 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:domain 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ipp 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:ipp 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:nameserver 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:42 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:netbios-ns 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:netbios-dgm 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:netbios-ssn 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:microsoft-ds 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:netbios-ns 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:netbios-dgm 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:netbios-ssn 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:microsoft-ds 

Chain FORWARD (policy DROP)
target     prot opt source               destination         
ACCEPT     0    --  anywhere             anywhere            state NEW,RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:pop3s 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:pop3s 

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     0    --  anywhere             anywhere            
ACCEPT     0    --  anywhere             anywhere            state NEW,RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:nameserver 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:42                   

Vielen Dank
Steve

Content-Key: 73776

Url: https://administrator.de/contentid/73776

Ausgedruckt am: 28.03.2024 um 11:03 Uhr

Mitglied: Guenni
Guenni 17.11.2007 um 16:23:38 Uhr
Goto Top
@Cubic83

Hi,


deine NW-Karten müssen in unterschiedlichen Netzen sein, z.b:

eth0: 10.0.0.10/16 --> LAN
eth1: 10.1.0.9/16 --> DSL, wobei das DSL-Modem im gleichen Netz ist,
wie diese NW-Karte.

Die NW-Karte eth1 bekommt als Gatewayadresse die IP des Modems,
die NW-Karte eth0 bekommt kein Gateway.

Routen müssen keine gesetzt werden, da durch die zwei Karten dem
Kernel die Routen bekannt sind.

Desweiteren muß NAT für die NW-Karte zum DSL aktiviert werden, da
sonst keine Adressübersetzung statt findet:

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

Gruß
Günni
Mitglied: Cubic83
Cubic83 18.11.2007 um 09:43:39 Uhr
Goto Top
Hallo,

ich habe das jetzt ausprobiert und das hat auf Anhieb funktionniert. 2 getrennte Netze hätte ich so schnell nicht ausprobiert.

Vielen Dank!

mfG