ipchains omzetten naar iptables

Pagina: 1
Acties:
  • 101 views sinds 30-01-2008
  • Reageer

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Ik draai nu al een half jaar ofzo Red Hat 7.1, maar het is me nog steeds niet gelukt om poorten door te sturen... Met 6.2 en 7.0 gaat dit perfect met ipmasqadm, maar in 7.1 lukt dit gewoon niet. Ik heb al meerder keren hier vragen over gesteld, maar het is eigenlijk nooit gelukt.
Ik heb daarom maar besloten om over te stappen op iptables, aangezien het hiermee wel in 1 keer werkt! Nu maakt RedHat 7.1 alleen standaard een mooie firewall aan (met het programma 'lokkit'). En dat is dus in ipchains-'formaat'. Hieronder even de rules zoals ik m heb ingesteld (0-1024 dicht, behalve ftp, mail en pop voor eth0; voor eth1 volledige toegang. vooral dit laatste is erg belangrijk! ik wil nl. vanuit het netwerk kunnen ssh-en):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    IW   /etc/sysconfig/ipchains    Row 1    Col 1    8:09  Ctrl-K H for help
# Firewall configuration written by lokkit
# Manual customization of this file is not recommended.
# Note: ifup-post will punch the current nameservers through the
#    firewall; such entries will *not* be listed here.
:input ACCEPT
:forward ACCEPT
:output ACCEPT
-A input -s 0/0 -d 0/0 25 -p tcp -y -j ACCEPT
-A input -s 0/0 -d 0/0 80 -p tcp -y -j ACCEPT
-A input -s 0/0 -d 0/0 21 -p tcp -y -j ACCEPT
-A input -s 0/0 -d 0/0 -i lo -j ACCEPT
-A input -s 0/0 -d 0/0 -i eth1 -j ACCEPT
-A input -p tcp -s 0/0 -d 0/0 0:1023 -y -j REJECT
-A input -p tcp -s 0/0 -d 0/0 2049 -y -j REJECT
-A input -p udp -s 0/0 -d 0/0 0:1023 -j REJECT
-A input -p udp -s 0/0 -d 0/0 2049 -j REJECT
-A input -p tcp -s 0/0 -d 0/0 6000:6009 -y -j REJECT
-A input -p tcp -s 0/0 -d 0/0 7100 -y -j REJECT

Nu is mijn vraag, hoe moet dit worden als ik overstap op iptables? Ik wordt namelijk erg duizelig van die HOWTO's :+ (heb me ook nooit in een ipchains-howto verdiept overigens)



[update]
Ik heb nu dit al op wat door te sturen:
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
#!/bin/sh
# quick hack: ipchains unloaden
rmmod ipchains

# NAT module laden
modprobe iptable_nat

# FTP module laden
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp

# In de NAT tabel (-t nat), een rule toevoegen (-A) na het routen
# (POSTROUTING) voor alle uitgaande paketten vanaf eth0 (-o eth0),
# die zegt MASQUERADE de verbinding (-j MASQUERADE).
iptables -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Ip forwarding aanzetten
echo 1 > /proc/sys/net/ipv4/ip_forward

# ICQ forwarding op poort 5000 - 5019
iptables -A PREROUTING -t nat -p tcp -d 213.93.20.7 --dport 5000:5019 -j DNAT --to 192.168.0.2:5000-5019


# RedAlert aanzetten
iptables -A PREROUTING -t nat -p tcp -d 213.93.20.7 --dport 8675 -j DNAT --to 192.168.0.2:8675
iptables -A PREROUTING -t nat -p udp -d 213.93.20.7 --dport 8675 -j DNAT --to 192.168.0.2:8675
iptables -A PREROUTING -t nat -p udp -d 213.93.20.7 --dport 5009 -j DNAT --to 192.168.0.2:5009

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Questor heeft me al een flink eind op weg geholpen, we hebben nu dit firewall script gemaakt:
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
#!/bin/sh
# quick hack: ipchains unloaden
/etc/rc.d/init.d/ipchains stop
rmmod ipchains

# NAT module laden
modprobe iptable_nat

# FTP module laden
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp

# In de NAT tabel (-t nat), een rule toevoegen (-A) na het routen
# (POSTROUTING) voor alle uitgaande paketten vanaf eth0 (-o eth0),
# die zegt MASQUERADE de verbinding (-j MASQUERADE).
iptables -F
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Ip forwarding aanzetten
echo 1 > /proc/sys/net/ipv4/ip_forward

# ICQ forwarding op poort 5000 - 5019
iptables -A PREROUTING -t nat -p tcp -d 213.93.20.7 --dport 5000:5019 -j DNAT --to 192.168.0.2:5000-5019

# RedAlert aanzetten
iptables -A PREROUTING -t nat -p tcp -d 213.93.20.7 --dport 8675 -j DNAT --to 192.168.0.2:8675
iptables -A PREROUTING -t nat -p udp -d 213.93.20.7 --dport 8675 -j DNAT --to 192.168.0.2:8675
iptables -A PREROUTING -t nat -p udp -d 213.93.20.7 --dport 5009 -j DNAT --to 192.168.0.2:5009

# de firewall zelf
iptables -A INPUT -i eth1 -j INETIN 
iptables -A FORWARD -s 192.168.0.0/255.255.255.0 -j ACCEPT 
iptables -A OUTPUT -o eth1 -j INETOUT 
iptables -A INETIN -p icmp -m icmp ! --icmp-type 8 -j ACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 20 -j TCPACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 21 -j TCPACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 25 -j TCPACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 80 -j TCPACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 1024:65536 -j TCPACCEPT 
iptables -A INETIN -p tcp -m tcp --dport 2049 -j LDROP
iptables -A INETIN -p tcp -m tcp --dport 6000:6009 -j LDROP
iptables -A INETIN -p tcp -m tcp --dport 7100 -j LDROP
iptables -A INETIN -p udp -m udp --dport 1081:10000 -j UDPACCEPT 
iptables -A INETIN -m state --state RELATED,ESTABLISHED -j ACCEPT 
iptables -A INETIN -j LDROP 
iptables -A INETOUT -j ACCEPT

ipchains moet dus eerst uit omdat redhat die aanzet...

Maar ik krijg nu deze foutmelding(en):
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
cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `INETOUT':/lib/iptables/libipt_INETOUT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables: No chain/target/match by that name
iptables v1.2.1a: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: invalid TCP port/service `65536' specified
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.1a: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.

etc,etc...

Wat te doen?? :?

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Dit is trouwens de lsmod -output:
code:
1
2
3
4
5
6
7
8
9
10
11
12
[root@a143084 /root]# lsmod
Module          Size  Used by
ipt_MASQUERADE      1680   1  (autoclean)
iptable_filter      2240   0  (autoclean) (unused)
ip_conntrack_ftp      2448   0  (unused)
ip_nat_ftp        3792   0  (unused)
iptable_nat     15968   1  [ipt_MASQUERADE ip_nat_ftp]
ip_conntrack         15824   2  [ipt_MASQUERADE ip_conntrack_ftp ip_nat_ftp iptable_nat]
ip_tables         11488   5  [ipt_MASQUERADE iptable_filter iptable_nat]
autofs           11136   1  (autoclean)
8139too         16480   1  (autoclean)
3c59x           25312   1  (autoclean)

  • RooT
  • Registratie: April 2001
  • Laatst online: 05-05 13:55
dit is ff geen antwoord op je vraag maar wel op het gezeik dat je met RH 7.1 geen porten kan forwarden, dat komt omdat ipmasq niet meer samen gaat met de nieuwe kernel, wil je toch met ipmasq nog forwarden dan moet je of gewoon een oudere kernel pakken of je moet iptables pakken zoals jij doet :)

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Op donderdag 23 augustus 2001 22:27 schreef RooT het volgende:
dit is ff geen antwoord op je vraag maar wel op het gezeik dat je met RH 7.1 geen porten kan forwarden, dat komt omdat ipmasq niet meer samen gaat met de nieuwe kernel, wil je toch met ipmasq nog forwarden dan moet je of gewoon een oudere kernel pakken of je moet iptables pakken zoals jij doet :)
Vandaar al dat gezeur met ipmasqadm... Maar goed. Die portforwarding werkt dus goed, maar de 'echte' firewall dus nog niet... Iemand??

  • odysseus
  • Registratie: Augustus 2000
  • Laatst online: 09:05

odysseus

Debian GNU/Linux Sid

Je moet eerst een nieuwe regel toevoegen voor je hem gebruikt:
code:
1
iptables -N MY_CHAIN_NAME

Leven is het meervoud van lef | In order to make an apple pie from scratch, you must first create the universe.


  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Op donderdag 23 augustus 2001 23:27 schreef odysseus het volgende:
Je moet eerst een nieuwe regel toevoegen voor je hem gebruikt:
code:
1
iptables -N MY_CHAIN_NAME
en hoe moet dat er dan uit komen te zien? :?

Verwijderd

voor je regel met INETIN en INETOUT plaats je

iptables -N INETIN
iptables -N INETOUT
hiermee creer je deze nieuwe chains waar je regels aan wilt toevoegen

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Ik ben weer even bezig geweest, alleen het lukt nog steeds niet. Ik heb die regels opgenomen.

zie: ftp://62.163.143.111/pub/linux/firewall

Maar als ik m uitvoer, dan krijg ik dit:
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
[root@a143084 /root]# ./firewall
iptables v1.2.2: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `TCPACCEPT':/lib/iptables/libipt_TCPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: invalid TCP port/service `65536' specified
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `UDPACCEPT':/lib/iptables/libipt_UDPACCEPT.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.2: Couldn't load target `LDROP':/lib/iptables/libipt_LDROP.so: cannot open shared object file: No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
[root@a143084 /root]#

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Wie helpt mij even?

Verwijderd

Beetje een vaag scriptje als je het mij vraagt.
Het klopt niet echt wat er staat.
Je maakt eigen chains aan. Waaronder INETIN en INETOUT.
Het is dus de bedoeling dat je die chains een speciale behandeling geeft.
Bijvoorbeeld je wil dat jumps naar die chain bijvoorbeeld gedenied worden en voordat dat gebeurt moet het in de logs verschijnen.
Je krijgt dan dus bijvoorbeeld zoiets:
code:
1
2
3
iptables -N deny-extif
iptables -A deny-extif -j LOG --log-level 7 --log-prefix "###IP denied: "
iptables -A deny-extif -j REJECT

Vervolgens is het dus de bedoeling dat je daar in INPUT/OUTPUT/FORWARD chains etc naartoe jumped als er aan een bepaalde conditie is voldaan.

Ofwel deny-extif zal dan achter de -j switch moeten staan.
Bijvoorbeeld om poort 20 in de INPUT chain die behandeling te geven voor nieuwe en ongeldige verbindingen:
code:
1
iptables -A INPUT -p tcp -m state --state NEW,INVALID --dport 20 -j deny-extif

Wat jij nu deed is allerlei referenties maken naar een chain TCPACCEPT terwijl deze chain niet eens gedefinieerd is ergens. Dat kan sowieso niet!! Vandaar ook de bovenstaande foutmeldingen. Hij denkt nu blijkbaar dat het een builtin chain is, terwijl het gewoon een eigen gemaakte chain behoort te zijn ;)

  • frapex
  • Registratie: Januari 2001
  • Laatst online: 19-08 21:04

frapex

got r00t

Je libraries liggen overhoop

download de tarball van iptables & installeer die. succes

Asus A7N8X-X, AMD XP2400+, 2.5GB Infineon+Samsung DDR333, Radeon x1600 Pro, 2x Fujitsu MAP3735NC 10Krpm SCSI 73GB, Seagate Medalist 17.2GB, LiteOn DVD 16x48x, LiteOn 48x12x48, Promise UDMA100/TX2, Adaptec 2110S Ultra3, 2x EIZO FlexScan (F931 & F930)


Verwijderd

Op woensdag 29 augustus 2001 23:13 schreef frapex het volgende:
Je libraries liggen overhoop

download de tarball van iptables & installeer die. succes
Euhm, mag jij mij uitleggen waarom ik die betreffende lib ook niet heb en het bij mij wel werkt.
Verder wel heel toevallig dat hij referenties maakt achter de -j switch die toevallig dezelfde naam heeft als de zogenaamd missende lib he ;)
Lees mijn verhaaltje even a.u.b. :)

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
Ik heb m nu herschreven (zie vorige link, is nieuwe versie).
Als ik m uitvoer: geen foutmelding :)

Alleen: hij werkt niet :( Tenminste dat geloof ik. Poort 139 staat denk ik nog open. Hoe moet ik nou poorten dicht zetten?

Verwijderd

"man iptables", netfilter.samba.org :?

Gewoon de policy op REJECT zetten en vervolgens de openingen erin maken via ACCEPT regels.
Zie -p switch in INPUT/OUTPUT/FORWARD chains.

Oh ja. "iptables -L" en "iptables -L -t nat" zijn ook wel handig om te weten ;)

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
ftp://62.163.143.111/pub/linux/firewall

Hij werkt nu bijna zoals ik het wil. Hij blokkeert nu goed. Iets te goed, want het interne netwerk (eth1) moet _wel_ toegang tot poort 139 en 901 hebben. Is dat een beetje makkelijk in te bouwen?

(heb voor die ene vraag geen zin me in die manpage te storten)

Verwijderd

Ik ben gek dat ik het antwoord geef eigenlijk.
Voor een firewall moet je goed weten wat je aan het doen bent.
Linux betekent lezen. Heel veel lezen. Waarom denk je dat ik nog nooit een vraag op GoT gesteld heb?

/me stopt nu het belerende "vader" verhaaltje ;)

Je hebt op de INPUT chain de zogenaamde -i switch waarbij je aan kan geven voor welke interface het geldt.
Voor de OUTPUT chain is dat de -o switch.
Ofwel "-i eth0" betekent dat de rule waarin het staat alleen voor interface eth0 geldt.

  • banaan-X
  • Registratie: Februari 2001
  • Niet online
:+

(ik wist wel dat je dat ging zeggen...; maar je hoort nu weer een tijdje niets van me. :) )

Hij werkt dus nu precies zoals ik wilde: Bedankt! :)

Verwijderd

Op donderdag 30 augustus 2001 08:44 schreef banaan-X het volgende:
:+

(ik wist wel dat je dat ging zeggen...; maar je hoort nu weer een tijdje niets van me. :) )
:X ;)
Gehehe...Ben voorspelbaar :P
Hij werkt dus nu precies zoals ik wilde: Bedankt! :)
Gelukkig :)
Altijd leuk als dingen het uiteindelijk doen zoals jij het wil hebben :)
Pagina: 1