View Full Version : iptables regola mi aiutate?
texerasmo
13-10-2006, 16:19
scusate ...
vorrei che tutte le richieste 192.168.0.140:80 andassero sulla 192.168.0.141:80
in questa regola la sintassi è sbagliata.Dove scrivo cavolate?
/sbin/iptables -F
/sbin/iptables -F -t nat
/sbin/iptables -X
/sbin/iptables -Z
iptables -A PREROUTING -t nat -p tcp -d 192.168.0.140 --dport 80 -j DNAT --to 192.168.0.141:80
Brownout
13-10-2006, 19:43
vorrei che tutte le richieste 192.168.0.140:80 andassero sulla 192.168.0.141:80
in questa regola la sintassi è sbagliata.Dove scrivo cavolate?
/sbin/iptables -F
/sbin/iptables -F -t nat
/sbin/iptables -X
/sbin/iptables -Z
iptables -A PREROUTING -t nat -p tcp -d 192.168.0.140 --dport 80 -j DNAT --to 192.168.0.141:80
Domanda stupida ma doverosa: la macchina sulla quale vuoi mettere questa regola e' un router e/o 192.168.0.140?
Seconda cosa, non e' che la default policy della FORWARD e' DROP e non hai la corrispondente regola che autorizzi quel traffico?
texerasmo
16-10-2006, 10:13
Grazie per la risposta.
entrambe le macchine sono linux
Allora il mio scenario è così composto.
sulla macchina 140 arrivano le rchieste del sitto www.pippo.com ma poichè apache è off devono essere rindirizzate sulla 141.
ok?
texerasmo
16-10-2006, 17:34
up
questa regola si trova sulla macchina 192.168.0.140
ho provato ache così
iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 -j DNAT --to-destination 192.168.0.141:80
la regola è formalmente corretta, il routing a livello kernel è abilitato?
texerasmo
17-10-2006, 10:01
come lo verifico?
lsmod?
Module Size Used by
iptable_mangle 2753 0
iptable_nat 23173 1
ip_conntrack 40949 1 iptable_nat
iptable_filter 2753 0
ip_tables 16833 3 iptable_mangle,iptable_nat,iptable_filter
parport_pc 24705 1
lp 12077 0
parport 37129 2 parport_pc,lp
autofs4 23237 0
i2c_dev 11329 0
i2c_core 22081 1 i2c_dev
sunrpc 157093 1
button 6481 0
battery 8901 0
ac 4805 0
md5 4033 1
ipv6 232705 10
uhci_hcd 31065 0
snd_ens1371 24936 2
snd_rawmidi 26597 1 snd_ens1371
snd_seq_device 8137 1 snd_rawmidi
snd_pcm_oss 49017 0
snd_mixer_oss 17985 2 snd_pcm_oss
snd_pcm 96841 2 snd_ens1371,snd_pcm_oss
snd_timer 29893 1 snd_pcm
snd_page_alloc 9673 1 snd_pcm
snd_ac97_codec 63889 1 snd_ens1371
snd 54949 10 snd_ens1371,snd_rawmidi,snd_seq_device,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_ac97_codec
soundcore 9889 2 snd
pcnet32 30409 0
mii 4673 1 pcnet32
floppy 58481 0
dm_snapshot 17029 0
dm_zero 2369 0
dm_mirror 22957 2
ext3 116809 2
jbd 71257 1 ext3
dm_mod 54741 6 dm_snapshot,dm_zero,dm_mirror
mptscsih 36909 0
mptbase 45409 1 mptscsih
sd_mod 17217 3
scsi_mod 121421 2 mptscsih,sd_mod
Psycotic
17-10-2006, 10:35
non dimenticartio di attivare il forward
echo 1 > /proc/sys/net/ipv4/ip_forward
texerasmo
17-10-2006, 10:46
Questa è la mi siatuazione
[root@rl4A ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.0.0/24 192.168.0.143 tcp dpt:http
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.0.0/24 192.168.0.143 tcp dpt:http
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@rl4A ~]# iptables -t nat -L -nv
Chain PREROUTING (policy ACCEPT 1344 packets, 243K bytes)
pkts bytes target prot opt in out source destination
6 288 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.0.143:80
Chain POSTROUTING (policy ACCEPT 59 packets, 16947 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 56 packets, 16803 bytes)
pkts bytes target prot opt in out source destination
Devo attivare altro?
le modifiche hanno effetto immediato vero?
continua a non funzionare.
Cmq il test che faccio è questo
ho settato il mio file di host in questo modo
192.168.0.149 www.pippo.it
apro il broswer e digito www.pippo.it mi apsetto di vedere il sito.
Il sito in realtà gira su 192.168.0.143.
192.168.0.140 è un'ip di classe privata.. quindi le richieste da internet arrivano immagino ad un router con ip pubblico (che corrisponde a un nome dns) che le gira verso quell'ip.
non conviene quindi andare ad agire su quel router ?
texerasmo
17-10-2006, 11:06
no
in realtà le macchine 192.168.0.143 e 192.168.0.149 sono due macchine linux che sitrovano sulla stessa lan.
ma la richiesta verso il webserver viene fatta dalla rete interna ?
a quel punto non è + semplice cambiare il record nel dns ?
per continuare invece sulla via iptables ti consiglio di mettere tcpdump in ascolto e vedere mittente e destinatario dei pacchetti sia sulla macchina che "gira" le connessioni sia sul webserver.
texerasmo
17-10-2006, 11:27
ma la richiesta verso il webserver viene fatta dalla rete interna ?
si
a quel punto non è + semplice cambiare il record nel dns?
si sto facendo un test
tcpdump che query devo fare ?
texerasmo
17-10-2006, 11:38
[root@rl4A ~]# tcpdump net 192.168.0.140
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
20:01:40.910571 IP 192.168.0.140.1435 > 192.168.0.149.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:40.924666 IP 192.168.0.140.1435 > 192.168.0.143.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:40.910759 IP 192.168.0.143.http > 192.168.0.140.1435: S 1268193167:1268193167(0) ack 3594954687 win 5840 <mss 1460,nop,nop,sackOK>
20:01:40.911023 IP 192.168.0.140.1435 > 192.168.0.143.http: R 3594954687:3594954687(0) win 0
20:01:43.991240 IP 192.168.0.140.1435 > 192.168.0.149.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:43.992348 IP 192.168.0.140.1435 > 192.168.0.143.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:43.992522 IP 192.168.0.143.http > 192.168.0.140.1435: S 1271335790:1271335790(0) ack 3594954687 win 5840 <mss 1460,nop,nop,sackOK>
io farei sia sul webserver(192.168.0.149) che sulla macchina che "gira" la connessione(192.168.0.143)
tcpdump -i eth0 -n
e poi proverei da un'altro pc a fare la richiesta al webserver digitando l'ip
texerasmo
17-10-2006, 12:34
facendo così
tcpdump net 192.168.0.140
vedo che le chiamate vengono inoltrate alla 143.
Ma è apache(143) che non capisce che quelle richieste devono essere interpretate.
craedo
ho fatto una prova...
sono presenti questi moduli
iptable_nat 6980 1
ip_nat 16524 1 iptable_nat
ip_conntrack 48320 2 iptable_nat,ip_nat
nfnetlink 6552 2 ip_nat,ip_conntrack
iptable_filter 3072 0
ip_tables 12932 2 iptable_nat,iptable_filter
x_tables 13252 3 xt_tcpudp,iptable_nat,ip_tables
ho messo questa regola
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.23
ed effettivamente non avviene quello che vuoi fare tu.
tra l'altro il dump del traffico mi lascia molto perplesso:
non vedo pacchetti provenienti dal pc che fa la richiesta col browser.
Effettivamente da quello che mi pare di capire .. pc che fa il "redirect" riceve pacchetti tcp dal webserver ma a sua volta nn sa che farsene invece che girarli a chi ne ha fatto richiesta (non dovrebbe occuparsene IP_CONNTRACK ???)
ok .. mi sono fatto spiegare il funzionamento di quest'accrocchio
il client contatta il pc "redirector" che DNATta il pacchetto e lo gira al webserver... ma l'IP sorgente è ancora quello del client
quindi il webserver risponde al client.. ma dato che il client non ha aperto nessuna connessione con il webserver il pacchetto viene droppato!!!!!!!
è necessario quindi fare anche una regola di SNAT
oppure usare la direttiva REDIRECT
man iptables :read:
REDIRECT
This target is only valid in the nat table, in the PREROUTING and OUT-
PUT chains, and user-defined chains which are only called from those
chains. It alters the destination IP address to send the packet to the
machine itself (locally-generated packets are mapped to the 127.0.0.1
address). It takes one option:
--to-ports port[-port]
This specifies a destination port or range of ports to use:
without this, the destination port is never altered. This is
only valid if the rule also specifies -p tcp or -p udp.
texerasmo
17-10-2006, 13:57
Queste righe....
140 è ip che fa la richiesta.
149 è ip che risponde per prima ed ha il compito di inoltrare
140 fa un chietsa al 143.http
143 è ip a cui è stata gia inoltarta la richiesta
ma questa cosa non capisco cos'è
S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
0:01:43.991240 IP 192.168.0.140.1435 > 192.168.0.149.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:43.992348 IP 192.168.0.140.1435 > 192.168.0.143.http: S 3594954686:3594954686(0) win 65535 <mss 1460,nop,nop,sackOK>
20:01:43.992522 IP 192.168.0.143.http > 192.168.0.140.1435:
che mi consigliate di fare?
scusa... ho postato la modifica quando tu avevi già risposto...
texerasmo
17-10-2006, 14:03
scusa non ho capito
è necessario quindi fare anche una regola di SNAT???
oppure usare la direttiva REDIRECT???
sempre sulla macchina 149?
scusa non ho capito
è necessario quindi fare anche una regola di SNAT???
oppure usare la direttiva REDIRECT???
o fai una "doppia regola" DNAT e SNAT oppure usi REDIRECT
sempre sulla macchina 149?
si
texerasmo
17-10-2006, 14:44
un cosa del genere?
sulla stessa macchina probabilmente si fa così
mentre se deve su un altra macchina?
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8080
texerasmo
17-10-2006, 14:47
Perche così mi da errore
iptables -t nat -A OUTPUT -p tcp --dport 80 -i eth0 -j REDIRECT --to-destination 192.168.0.143:80
texerasmo
18-10-2006, 10:05
Ragazzi mi sorge un dubbio che questa cosa non si può fare..
ho fatto un
traceroute www.test.de
questo è il risultato.
traceroute to www.test.de (192.168.0.149), 30 hops max, 38 byte packets
1 192.168.0.149 (192.168.0.149) 1.134 ms 0.258 ms 0.238 ms
La mia domanda è www.test.de nel dns è settatto 192.168.0.149 ma la macchina 149 dovrebbe ridirigere le chiamare alla 143.
Dal risultato del traceroute questo non avviene.
Questo cosa sta a significare?
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.