iptables blokkeert http verkeer vanaf wan

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Rowdy.nl
  • Registratie: Juni 2003
  • Laatst online: 11-09 13:21

Rowdy.nl

Koekje d'r bij?

Topicstarter
Ik ben bezig met het vervangen van m'n oude servert door een mooi nieuw exemplaar, maar ik heb iets fout zitten in m'n iptables config. Het probleem is dat ik geen http/ftp verkeer van buitenaf kan ontvangen. Vanaf de LAN doet alles het prima, en als ik iptables stop kan ik ook vanaf extern de sites benaderen.

Op m'n oude bak werkte ook alles zonder problemen, echter weet ik niet exact welke rules ik daar gedraaid heb jaren terug. Als ik de rules list kom ik iig op een kortere tabel uit.

Ik heb al zitten zoeken en heb na aanleiding daarvan regels 42 t/m 48 toegevoegd, maar ik kan nog steeds niet connecten. :/

Volgens mij ben ik rondjes aan het rennen en zit de fout ergens hoger, gooi ik teveel dicht of zo?
Kan een guru mij helpen? :)

Hieronder een script, iptables.sh wat ik gemaakt heb om het eea te automagiseren, en de iptables list van m'n nieuwe en oude bak.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Flush all 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

# Easy 
export LAN=lan
export WAN=wan

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

# Allow access to our ssh server from the WAN
iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT

# Drop TCP / UDP packets to privileged ports
iptables -A INPUT -i ${WAN} -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT -p udp -m udp --sport 123 --dport 123 -j ACCEPT
iptables -A INPUT -p TCP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP
iptables -A INPUT -p UDP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP

# Finally we add the rules for NAT
iptables -I FORWARD -i ${LAN} -d 10.1.0.0/255.255.0.0 -j DROP
iptables -A FORWARD -i ${LAN} -s 10.1.0.0/255.255.0.0 -j ACCEPT
iptables -A FORWARD -i ${WAN} -d 10.1.0.0/255.255.0.0 -j ACCEPT
iptables -t nat -A POSTROUTING -o ${WAN} -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

# NTP allowanced
iptables -A INPUT -i wan -m state --state RELATED,ESTABLISHED -j ACCEPT

# FTP (passive) ports
iptables -A INPUT -p tcp --dport 20:21 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 49152:65534 --syn -j ACCEPT

# (SSL) http traffic
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# ICMP/Ping
iptables -A INPUT -p icmp -j ACCEPT

# All traffic from localhost
iptables -A INPUT -s 127.0.0.1 -j ACCEPT

# Save and restart
/etc/init.d/iptables save
/etc/init.d/iptables restart


Iptables list op nieuwe bak
nieuwebak ~ # iptables -L -vn
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
   99 11446 ACCEPT     all  --  lan    *       0.0.0.0/0            0.0.0.0/0
    0     0 REJECT     udp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           udp dpt:67 reject-with icmp-port-unreachable
    0     0 REJECT     udp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           udp dpt:53 reject-with icmp-port-unreachable
  817 51192 ACCEPT     tcp  --  wan    *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22
  926 1267K ACCEPT     all  --  wan    *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:123 dpt:123
   25  1420 DROP       tcp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           tcp dpts:0:1023
  812  280K DROP       udp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           udp dpts:0:1023
    0     0 ACCEPT     all  --  wan    *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 ACCEPT     tcp  --  wan    *       0.0.0.0/0            0.0.0.0/0           tcp dpts:20:21
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpts:49152:65534 flags:0x17/0x02
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:80

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  lan    *       0.0.0.0/0            10.1.0.0/16
   86  7181 ACCEPT     all  --  lan    *       10.1.0.0/16          0.0.0.0/0
   84 11313 ACCEPT     all  --  wan    *       0.0.0.0/0            10.1.0.0/16

Chain OUTPUT (policy ACCEPT 1612 packets, 234K bytes)
 pkts bytes target     prot opt in     out     source               destination


Iptables list op oude bak
oudebak ~ # iptables -L -vn
Chain INPUT (policy ACCEPT 72M packets, 30G bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:448
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:53696
    9   360 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:1411
    0     0 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:89
   84 11845 ACCEPT     tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:2525

Chain FORWARD (policy ACCEPT 778 packets, 342K bytes)
 pkts bytes target     prot opt in     out     source               destination
 247M   17G ACCEPT     all  --  eth1   *       192.168.0.0/16       0.0.0.0/0
 465M  670G ACCEPT     all  --  eth0   *       0.0.0.0/0            192.168.0.0/16

Chain OUTPUT (policy ACCEPT 77M packets, 47G bytes)
 pkts bytes target     prot opt in     out     source               destination

Rowdy.nl - X++ by day. C# by night. I drink coffee in the morning and beer in the evening.


Acties:
  • 0 Henk 'm!

  • GlowMouse
  • Registratie: November 2002
  • Niet online
code:
1
2
   25  1420 DROP       tcp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           tcp dpts:0:1023
  812  280K DROP       udp  --  !lan   *       0.0.0.0/0            0.0.0.0/0           udp dpts:0:1023

die twee regels blokkeren blijkbaar verkeer voordat je aan de vier regels eronder toekomt

[ Voor 17% gewijzigd door GlowMouse op 09-06-2010 11:35 ]


Acties:
  • 0 Henk 'm!

  • Rowdy.nl
  • Registratie: Juni 2003
  • Laatst online: 11-09 13:21

Rowdy.nl

Koekje d'r bij?

Topicstarter
Dat zijn regels 26 en 27 dus,
code:
1
2
iptables -A INPUT -p TCP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP
iptables -A INPUT -p UDP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP

maar zet ik die niet weer open dan met regels 42 t/m 48
code:
1
2
3
4
5
6
7
# FTP (passive) ports
iptables -A INPUT -p tcp --dport 20:21 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 49152:65534 --syn -j ACCEPT

# (SSL) http traffic
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT


Comment ik 26/27 uit en rerun ik het script werkt het wel, maar nu heb ik dus poort 0:1023 open staan.
Wat wel vreemd is dat SSH (poort 23 meen ik) wél werkte in de oude situatie?

Edit:
Crap, de volgorde omgooien maakt dus uit, onderstaande werkt dus als een tiet; eerst accepteren en dan de rest sluiten... Glowmouse, thnx voor het kleine zetje wat ik nodig had... :P

Nieuw script (voor degenen die het interessant vinden):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Flush all 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

# Easy 
export LAN=lan
export WAN=wan

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

# Accept SSH from WAN
iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT

# Accept NTP  from WAN
iptables -A INPUT -i wan -m state --state RELATED,ESTABLISHED -j ACCEPT

# Accept FTP (passive) ports  from WAN
iptables -A INPUT -p tcp --dport 20:21 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 49152:65534 --syn -j ACCEPT

# Accept (SSL) http traffic from WAN
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# Accept ICMP/Ping from WAN
iptables -A INPUT -p icmp -j ACCEPT

# Accept All traffic from localhost
iptables -A INPUT -s 127.0.0.1 -j ACCEPT

# Drop TCP / UDP packets to privileged ports
iptables -A INPUT -i ${WAN} -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t filter -A INPUT -p udp -m udp --sport 123 --dport 123 -j ACCEPT
iptables -A INPUT -p TCP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP
iptables -A INPUT -p UDP ! -i ${LAN} -d 0/0 --dport 0:1023 -j DROP

# Finally we add the rules for NAT
iptables -I FORWARD -i ${LAN} -d 10.1.0.0/255.255.0.0 -j DROP
iptables -A FORWARD -i ${LAN} -s 10.1.0.0/255.255.0.0 -j ACCEPT
iptables -A FORWARD -i ${WAN} -d 10.1.0.0/255.255.0.0 -j ACCEPT
iptables -t nat -A POSTROUTING -o ${WAN} -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

# Save and restart
/etc/init.d/iptables save
/etc/init.d/iptables restart

[ Voor 62% gewijzigd door Rowdy.nl op 09-06-2010 12:05 ]

Rowdy.nl - X++ by day. C# by night. I drink coffee in the morning and beer in the evening.


Acties:
  • 0 Henk 'm!

  • GlowMouse
  • Registratie: November 2002
  • Niet online
De regels worden van boven naar beneden doorlopen, en zodra een regel matcht wordt de rest niet meer bekeken.

Acties:
  • 0 Henk 'm!

  • lordgandalf
  • Registratie: Februari 2002
  • Laatst online: 05-09 17:55
waarom alleen verkeer dropen van privileged ports ik heb standaard de policiy voor input op drop staan.
alles word gedroped behalve wat ik toesta

Steam: Profile / Socialclub: Profile / Uplay: minedwarf / Origin: lordgandalf3