View previous topic :: View next topic |
Author |
Message |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Wed Apr 18, 2007 10:04 pm Post subject: [IPTABLES] Routage de ports capricieux [SOLVED] |
|
|
Bonjour à vous qui venez à mon secours !
Voilà je vous expose mon soucis :
Je possède malheureusement une Livebox Sagem...
Mon réseau : 192.168.1.0
Livebox = 192.168.1.1
Serveur routage = 192.168.1.2
Serveur HTTP = 192.168.1.5
Le but final est que ce soit le Serveur qui gère mes règles de routage et non pas la Livebox Sagem qui est très limitée de ce côté...
Le but est que tout requête venant sur le port 80 internet parvienne au serveur HTTP sur .5 le tout passant par .2 (ne me dites pas de le configurer sur la Livebox j'ai bien dit que cela est très limité sur cette dernière).
J'ai donc pour le moment routé mon port 80 TCP vers .2, il reçoit très bien la trame : OK
Maintenant, je désire rediriger cette trame via iptables vers .5 (logique me direz-vous). Hé bien c'est là que ça cloche...
Les trames sont bien reçues par .2 mais pas du tout par .5 !
Problème de règles iptables, problème de configuration noyau, NAT, ... ???
Voici un extrait de ma config noyau (2.6.20) :
Code: | #
# IP: Virtual Server Configuration
#
# CONFIG_IP_VS is not set
# CONFIG_IPV6 is not set
# CONFIG_INET6_XFRM_TUNNEL is not set
# CONFIG_INET6_TUNNEL is not set
# CONFIG_NETWORK_SECMARK is not set
CONFIG_NETFILTER=y
CONFIG_NETFILTER_DEBUG=y
# CONFIG_BRIDGE_NETFILTER is not set
#
# Core Netfilter Configuration
#
CONFIG_NETFILTER_NETLINK=y
CONFIG_NETFILTER_NETLINK_QUEUE=y
CONFIG_NETFILTER_NETLINK_LOG=y
CONFIG_NF_CONNTRACK_ENABLED=y
CONFIG_NF_CONNTRACK_SUPPORT=y
# CONFIG_IP_NF_CONNTRACK_SUPPORT is not set
CONFIG_NF_CONNTRACK=y
CONFIG_NF_CT_ACCT=y
CONFIG_NF_CONNTRACK_MARK=y
CONFIG_NF_CONNTRACK_EVENTS=y
# CONFIG_NF_CT_PROTO_SCTP is not set
# CONFIG_NF_CONNTRACK_AMANDA is not set
CONFIG_NF_CONNTRACK_FTP=m
# CONFIG_NF_CONNTRACK_H323 is not set
CONFIG_NF_CONNTRACK_IRC=m
# CONFIG_NF_CONNTRACK_NETBIOS_NS is not set
# CONFIG_NF_CONNTRACK_PPTP is not set
# CONFIG_NF_CONNTRACK_SIP is not set
CONFIG_NF_CONNTRACK_TFTP=m
CONFIG_NF_CT_NETLINK=y
CONFIG_NETFILTER_XTABLES=y
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
# CONFIG_NETFILTER_XT_TARGET_MARK is not set
# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
# CONFIG_NETFILTER_XT_TARGET_NFLOG is not set
# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
CONFIG_NETFILTER_XT_MATCH_CONNBYTES=y
CONFIG_NETFILTER_XT_MATCH_CONNMARK=y
CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
# CONFIG_NETFILTER_XT_MATCH_DSCP is not set
# CONFIG_NETFILTER_XT_MATCH_ESP is not set
CONFIG_NETFILTER_XT_MATCH_HELPER=y
# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
# CONFIG_NETFILTER_XT_MATCH_LIMIT is not set
# CONFIG_NETFILTER_XT_MATCH_MAC is not set
# CONFIG_NETFILTER_XT_MATCH_MARK is not set
# CONFIG_NETFILTER_XT_MATCH_POLICY is not set
# CONFIG_NETFILTER_XT_MATCH_MULTIPORT is not set
# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
# CONFIG_NETFILTER_XT_MATCH_REALM is not set
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
CONFIG_NETFILTER_XT_MATCH_STATE=y
# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
# CONFIG_NETFILTER_XT_MATCH_HASHLIMIT is not set
#
# IP: Netfilter Configuration
#
CONFIG_NF_CONNTRACK_IPV4=y
CONFIG_NF_CONNTRACK_PROC_COMPAT=y
# CONFIG_IP_NF_QUEUE is not set
CONFIG_IP_NF_IPTABLES=y
CONFIG_IP_NF_MATCH_IPRANGE=m
CONFIG_IP_NF_MATCH_TOS=m
CONFIG_IP_NF_MATCH_RECENT=m
CONFIG_IP_NF_MATCH_ECN=m
CONFIG_IP_NF_MATCH_AH=m
CONFIG_IP_NF_MATCH_TTL=m
CONFIG_IP_NF_MATCH_OWNER=m
CONFIG_IP_NF_MATCH_ADDRTYPE=m
CONFIG_IP_NF_FILTER=y
CONFIG_IP_NF_TARGET_REJECT=y
CONFIG_IP_NF_TARGET_LOG=y
CONFIG_IP_NF_TARGET_ULOG=y
CONFIG_IP_NF_TARGET_TCPMSS=m
CONFIG_NF_NAT=y
CONFIG_NF_NAT_NEEDED=y
CONFIG_IP_NF_TARGET_MASQUERADE=y
CONFIG_IP_NF_TARGET_REDIRECT=m
CONFIG_IP_NF_TARGET_NETMAP=m
CONFIG_IP_NF_TARGET_SAME=m
# CONFIG_NF_NAT_SNMP_BASIC is not set
CONFIG_NF_NAT_FTP=m
CONFIG_NF_NAT_IRC=m
CONFIG_NF_NAT_TFTP=m
# CONFIG_NF_NAT_AMANDA is not set
# CONFIG_NF_NAT_PPTP is not set
# CONFIG_NF_NAT_H323 is not set
# CONFIG_NF_NAT_SIP is not set
# CONFIG_IP_NF_MANGLE is not set
# CONFIG_IP_NF_RAW is not set
# CONFIG_IP_NF_ARPTABLES is not set |
Et mes règles iptables, j'avait déjà cette config lorsque j'était en 56k et elle fonctionnait très bien :
Code: | #!/bin/sh
# /etc/network/if-pre-up.d/iptables-start
# Script qui démarre les règles de filtrage "iptables"
# Formation Debian GNU/Linux par Alexis de Lattre
# http://formation-debian.via.ecp.fr/
# REMISE à ZERO des règles de filtrage
iptables -F
iptables -t nat -F
# DEBUT des "politiques par défaut"
# Je veux que les connexions entrantes soient bloquées par défaut
iptables -P INPUT DROP
# Je veux que les connexions destinées à être forwardées
# soient acceptées par défaut
iptables -P FORWARD ACCEPT
# Je veux que les connexions sortantes soient acceptées par défaut
iptables -P OUTPUT ACCEPT
# FIN des "politiques par défaut"
# DEBUT des règles de filtrage
# Pas de filtrage sur l'interface de "loopback"
iptables -A INPUT -i lo -j ACCEPT
# J'accepte le protocole ICMP (i.e. le "ping")
iptables -A INPUT -p icmp -j ACCEPT
# J'accepte le protocole IGMP (pour le multicast)
iptables -A INPUT -p igmp -j ACCEPT
# J'accepte les packets entrants relatifs à des connexions déjà établies
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Décommentez les deux lignes suivantes pour que le serveur FTP éventuel
# soit joignable de l'extérieur
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# Décommentez la ligne suivante pour que le serveur SSH éventuel
# soit joignable de l'extérieur
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# La règle par défaut pour la chaine INPUT devient "REJECT"
# (il n'est pas possible de mettre REJECT comme politique par défaut)
iptables -A INPUT -j REJECT
# FIN des règles de filtrage
# DEBUT des règles de "port forwarding"
# Décommentez la ligne suivante pour que les requêtes TCP reçues sur
# le port 80 de l'interface eth0 soient forwardées à la machine dont
# l'IP est 192.168.0.3 sur son port 80 (la réponse à la requête sera
# forwardée au client)
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.5:80
# FIN des règles de "port forwarding"
/etc/init.d/iptables save
/etc/init.d/iptables restart |
Un grand merci d'avance à tout ceux qui pourront m'apporter un coup de main !
Last edited by dough29 on Thu Apr 19, 2007 9:40 am; edited 1 time in total |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
truc Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/128604942846f4cd99d01cb.jpg)
Joined: 25 Jul 2005 Posts: 3199
|
Posted: Wed Apr 18, 2007 10:31 pm Post subject: |
|
|
j'dis ça comme ça j'n'en suis pas certains mais il ne te manquerait ça par hasard? Code: | iptables -A INPUT -p tcp --dport 80 -j ACCEPT |
_________________ The End of the Internet! |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Wed Apr 18, 2007 10:37 pm Post subject: |
|
|
Merci à toi pour ton intérêt.
Il me semblerai qu'il ne sert pas d'accepter le port si il est destiné à être routé, le fait de la router dirait qu'il est évidement accepté.
J'ai quand même testé les deux situations, même résultat .2 reçoit bien les trames mais ensuite rien à signaler sur .5
Si ça peu aider, # iptables -L :
Code: | Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere
ACCEPT igmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data
ACCEPT tcp -- anywhere anywhere tcp dpt:ftp
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
CryoGen Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/1442840809462c9e9cb938c.jpg)
Joined: 11 Feb 2004 Posts: 1426 Location: Bamako - Mali - Afrique
|
Posted: Wed Apr 18, 2007 11:01 pm Post subject: |
|
|
essai
Code: | iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.5 |
![Smile :)](images/smiles/icon_smile.gif) _________________ - CryoGen` on #gentoofr@irc.freenode.net
- ~amd64 / KDE4
- I'm the bone of my sword... |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Wed Apr 18, 2007 11:03 pm Post subject: |
|
|
Rien de plus ni de moins ![Rolling Eyes :roll:](images/smiles/icon_rolleyes.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 7:41 am Post subject: |
|
|
J'ai procédé à quelques tests depuis.
Premièrement, cette règle de routage devrait aussi bien fonctionner en local non ?
J'ai tenté de contacter .2:80 avec FireFox depuis une machine cliente du réseau et rien...
Sinon, je viens de tester les mêmes règles iptables sur une machine Debian et même soucis: aucun routage du port.
J'avoue que je suis pas mal pommé dans tout ça alors que cette config fonctionnait très bien à l'époque où j'avais ma connexion RTC.
Encore merci pour votre intérêt à ce soucis ! |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
_droop_ l33t
![l33t l33t](/images/ranks/rank_rect_4.gif)
Joined: 30 May 2004 Posts: 957
|
Posted: Thu Apr 19, 2007 7:58 am Post subject: |
|
|
Bonjour,
As tu activé le forward dans le noyau ?
Code: | echo 1 > /proc/sys/net/ipv4/ip_forward |
(modifier /etc/sysctl.conf pour rendre cette modification permanente)
Il faut aussi que tu utilises la règle que Cryogen a donné...
Tu peux récapituler les règles que tu utilises pour le routage du port 80 ?
Bon courage. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
MaKKrO Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/12930895184393ed4b449ad.jpg)
Joined: 04 Oct 2005 Posts: 265 Location: Paris - FRANCE
|
Posted: Thu Apr 19, 2007 8:05 am Post subject: |
|
|
Tu es sur du eth0 ???
Ca a peut l'air c** mais ca peut arriver !
Autrement essai peut etre un
Code: |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.5:80
|
_________________ Loisirs = Gentoo / Taff = Gentoo / Pourtant Taff != Loisirs |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 8:14 am Post subject: |
|
|
Punaise j'y avait pas pensé à ça
Bon ca avance légèrement, j'obtient ceci dans le TCPdump:
Code: | 10:13:12.030175 IP 192.168.1.122.2212 > 192.168.1.2.http: S 1377588991:1377588991(0) win 65535 <mss 1460,nop,nop,sackOK>
10:13:12.030236 IP 192.168.1.122.2212 > 192.168.1.5.http: S 1377588991:1377588991(0) win 65535 <mss 1460,nop,nop,sackOK>
10:13:13.436756 IP 192.168.1.122.2211 > 192.168.1.2.http: S 2961295141:2961295141(0) win 65535 <mss 1460,nop,nop,sackOK>
10:13:13.436799 IP 192.168.1.122.2211 > 192.168.1.5.http: S 2961295141:2961295141(0) win 65535 <mss 1460,nop,nop,sackOK>
10:13:15.047062 IP 192.168.1.122.2212 > 192.168.1.2.http: S 1377588991:1377588991(0) win 65535 <mss 1460,nop,nop,sackOK>
10:13:15.047105 IP 192.168.1.122.2212 > 192.168.1.5.http: S 1377588991:1377588991(0) win 65535 <mss 1460,nop,nop,sackOK> |
Aussi,
# iptables -t nat -v -L :
Code: | Chain PREROUTING (policy ACCEPT 25 packets, 2249 bytes)
pkts bytes target prot opt in out source destination
8 384 DNAT tcp -- eth0 any anywhere anywhere tcp dpt:http to:192.168.1.5:80
Chain POSTROUTING (policy ACCEPT 19 packets, 1032 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 5 packets, 360 bytes)
pkts bytes target prot opt in out source destination |
Aussi, sur le serveur HTTP:
Code: | 10:12:41.364099 IP 192.168.1.5.32768 > 192.168.1.1.domain: 46088+[|domain]
10:12:41.434422 IP 192.168.1.1.domain > 192.168.1.5.32768: 46088 NXDomain*[|domain]
10:12:44.421159 IP 192.168.1.122.2223 > 192.168.1.5.http: S 1287283480:1287283480(0) win 65535 <mss 1460,nop,nop,sackOK>
10:12:44.421199 IP 192.168.1.5.http > 192.168.1.122.2223: S 3638998540:3638998540(0) ack 1287283481 win 5840 <mss 1460,nop,nop,sackOK> |
Mais là, rien ne s'affiche dans le navigateur ![Sad :(](images/smiles/icon_sad.gif)
Last edited by dough29 on Thu Apr 19, 2007 8:34 am; edited 1 time in total |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 8:16 am Post subject: |
|
|
Oui eth0, ça pas de soucis
Merci à toi ![Smile :)](images/smiles/icon_smile.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
MaKKrO Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/12930895184393ed4b449ad.jpg)
Joined: 04 Oct 2005 Posts: 265 Location: Paris - FRANCE
|
Posted: Thu Apr 19, 2007 8:32 am Post subject: |
|
|
Mais alors pourquoi le 192.168.1.14:80 et non .5 dans tes regles iptables ??? _________________ Loisirs = Gentoo / Taff = Gentoo / Pourtant Taff != Loisirs |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 8:36 am Post subject: |
|
|
.14 c'était la Debian, même résultat sur le serveur .5
Je pense à un truc, le navigateur recoit de ACK de .5, il devrait pas le recevoir de .2 plutôt ? |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 9:52 am Post subject: |
|
|
Bon ben j'ai trouvé le soucis en voulant reconfigurer toutes mes IP
/etc/conf.d/net
Code: | config_eth0=( "192.168.1.5 netmask 255.255.255.0 brd 192.168.0.255" ) |
Ca risquait pas de marcher très bien...
Merci aussi à _droop_ sans qui j'aurai zappé le sysctl
Voilà , ca tourne comme je le souhaitait, merci à tous pour votre aide ![Very Happy :D](images/smiles/icon_biggrin.gif) |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
dough29 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 12 Dec 2004 Posts: 57
|
Posted: Thu Apr 19, 2007 9:54 am Post subject: |
|
|
Pour ceux intéressée, voici mes règles iptables
Code: | #!/bin/sh
iptables -F
iptables -t nat -F
iptables -P INPUT DROP
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -p igmp -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.14:80
/etc/init.d/iptables save
/etc/init.d/iptables restart |
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
loopx Advocate
![Advocate Advocate](/images/ranks/rank-G-1-advocate.gif)
![](images/avatars/gallery/Southpark/avatar17.gif)
Joined: 01 Apr 2005 Posts: 2787 Location: Belgium / Liège
|
Posted: Thu Apr 19, 2007 2:53 pm Post subject: |
|
|
pourquoi un restart en fin de script ![Question :?:](images/smiles/icon_question.gif) _________________ Mon MediaWiki perso : http://pix-mania.dyndns.org |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
zyprexa Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/123943749942ee7c1bd73bf.jpg)
Joined: 26 Dec 2004 Posts: 180
|
Posted: Thu Apr 19, 2007 3:37 pm Post subject: |
|
|
Les puristes d'iptables te diront qu'il ne faut pas oublier d'initialiser le comportement par défaut de toutes les chaînes(exemple ici).
Un bon moyen pour trouver la règle kivabien est d'un côté d'observer les logs d'iptables (ptite cible ulog en fin de chaîne) et de bidouiller directement les règles : action - réaction on voit illico si ce qu'on fait change quelque chose. (tcpdump pourquoi faire ?)
(Ca a été salutaire pour moi)
et qu'en est-il de ceci ?
Code: | echo 1 > /proc/sys/net/ipv4/ip_forward |
Je te suggère la lecture de cette excellente doc sur iptables qui est un modèle du genre.
edit : après la guerre j'avais mal lu désolé ![Embarassed :oops:](images/smiles/icon_redface.gif) _________________ enjoy |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|