iptables verwirrung

Seite 1 von 1 - Forum: Linux and other OS auf overclockers.at

URL: https://www.overclockers.at/linux/iptables_verwirrung_200335/page_1 - zur Vollversion wechseln!


Marcellus schrieb am 05.10.2008 um 19:05

Ich wollte mir eine gentoo box hinstellen, die meinen router kurzzeitig vertreten soll. Dazu hab ich dieses howto verwendet. Allerdings gibts im testbetrieb Probleme.

Ich hab die iptables rules in eine Datei zusammengeschrieben, dass sie leichter wiederausführbar werden, weil ich gedacht hab, dass ich die rules uu öfters flushen muss.

Also noch einmal vom Aufbau her: Der rechner soll ein Nat aufbauen, wobei:
eth1 ist der lokale nic,
eth0 ist der globale nic,
ath2 ist ein wlan über das ich gern zugang per ssh hätte

Code:
#!/bin/bash

#First we flush our current rules
 iptables -F
 iptables -t nat -F

#Setup default policies to handle unmatched traffic
 iptables -P INPUT ACCEPT
 iptables -P OUTPUT ACCEPT
 iptables -P FORWARD DROP

#Then we lock our services so they only work from the LAN
 iptables -I INPUT 1 -i eth1 -j ACCEPT
 iptables -I INPUT 1 -i lo -j ACCEPT
# iptables -A INPUT -p UDP --dport bootps -i ! eth1 -j REJECT
# iptables -A INPUT -p UDP --dport domain -i ! eth1 -j REJECT

#(Optional) Allow access to our ssh server from the eth0
 iptables -A INPUT -p TCP --dport ssh -i eth0 -j REJECT          <MARKIERT>
 iptables -A INPUT -p TCP --dport ssh -i ath2 -j ACCEPT         <MARKIERT>

#Drop TCP / UDP packets to privileged ports
 iptables -A INPUT -p TCP -i eth0 -d 0/0 --dport 0:1023 -j DROP
 iptables -A INPUT -p UDP -i eth0 -d 0/0 --dport 0:1023 -j DROP

#Finally we add the rules for NAT
 iptables -I FORWARD -i eth1 -d 192.168.0.0/255.255.0.0 -j DROP
 iptables -I FORWARD -i ath2 -d 192.168.0.0/255.255.0.0 -j DROP
 iptables -A FORWARD -i eth1 -s 192.168.0.0/255.255.0.0 -j ACCEPT
 iptables -A FORWARD -i ath2 -s 192.168.0.0/255.255.0.0 -j ACCEPT
 iptables -A FORWARD -i eth0 -d 192.168.0.0/255.255.0.0 -j ACCEPT
 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

#Tell the kernel that ip forwarding is OK
 echo 1 > /proc/sys/net/ipv4/ip_forward
 for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done

Jetzt zum eigentlichen Problem. Ich komme über kein Interface per ssh rein. Die zwei Markierten Zeilen scheinen nicht das zu machen, was sie sollen. Wenn ich die beiden allerdings mit:
Code:
iptables -A INPUT -p TCP --dport ssh -i eth0 -j ACCEPT
ersetze komm ich über jedes Interface über ssh rein. Die iptables help hat mir bis jetzt auch nicht weitergeholfen

Die Ausgabe von iptables -L -v ist
Code:
Chain INPUT (policy ACCEPT 66 packets, 9372 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 ACCEPT     all  --  eth1   any     anywhere             anywhere
    3   220 REJECT     tcp  --  eth0   any     anywhere             anywhere            tcp dpt:ssh reject-with icmp-port-unreachable
    0     0 ACCEPT     tcp  --  ath2   any     anywhere             anywhere            tcp dpt:ssh
    0     0 DROP       tcp  --  eth0   any     anywhere             anywhere            tcp dpts:0:1023
   15  1542 DROP       udp  --  eth0   any     anywhere             anywhere            udp dpts:0:1023

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  ath2   any     anywhere             192.168.0.0/16
    0     0 DROP       all  --  eth1   any     anywhere             192.168.0.0/16
    0     0 ACCEPT     all  --  eth1   any     192.168.0.0/16       anywhere
    0     0 ACCEPT     all  --  ath2   any     192.168.0.0/16       anywhere
    0     0 ACCEPT     all  --  eth0   any     anywhere             192.168.0.0/16

Chain OUTPUT (policy ACCEPT 93 packets, 10752 bytes)
 pkts bytes target     prot opt in     out     source               destination

tia


COLOSSUS schrieb am 05.10.2008 um 19:27

Sowas via Paketfilter zu regeln ist eigentlich auch der falsche Ansatz: Besser, du konfigurierst OpenSSH (sshd) so, dass dieser nur auf den gewünschten Interfaces verfuegbar wird.


Marcellus schrieb am 05.10.2008 um 20:36

Was mich daran irritiert ist, dass diese rules eigentlich jeden zugriff vom internet auf den Rechner verhindern sollten.

Sshd auf Listenaddresses zu beschränken funktioniert einwandfrei :).

Es interessiert mich aber doch noch wieso das nicht hingehaut hat. Da ich davon ausgehe, dass iptables mehr ahnung von iptables hat als ich frag ich mich wie die Rules richtig ausgesehen hätten.

Vielen Dank colo


jives schrieb am 05.10.2008 um 22:14

Das ist wirklich interessant, ich hätte auch geglaubt dass das so gehen sollte...


davebastard schrieb am 05.10.2008 um 22:19

ich habs jetzt nicht näher angesehen aber du könntest dass was du willst mit fwbuilder erstellen und dann schauen welche rules er draus gemacht hat.


COLOSSUS schrieb am 06.10.2008 um 08:41

Meiner Ansicht nach muss das Problem auf einer anderen Ebene liegen. Warst du zu dem Zeitpunkt in mehreren Netzwerken, und ist es dadurch evtl. moeglich, dass deine Pakete zum Host, auf dem der zu sichernde sshd laeuft, eine andere route genommen haben? Wenn das nicht der Fall sein kann, seh' ich es auch nicht...
Trotzdem - ich wuerde mal alle in Frage kommenden REJECT/DROP targets mit einer identischen Rule mit LOG-target prefixen, dann siehst du wenigstens, was dir (und mit "--log-prefix" auch wodurch) weggeschmissen wird.




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025