• [^] # Re: Chemin aller, chemin retour

    Posté par . En réponse au message Redirection tu port 2222 vers le port 22 d'une machine virtuelle. Évalué à 2.

    OK, j'ai finalement réussi, merci a tous pour m'avoir guide, pour information voici les règles iptables:

    sudo iptables -nL -v --line-numbers -t filter
    Chain INPUT (policy ACCEPT 629 packets, 75947 bytes)
    num pkts bytes target prot opt in out source destination 
    1 463 30877 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:53
    2 0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
    3 0 0 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:67
    4 0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
    5 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2222
    Chain FORWARD (policy ACCEPT 2 packets, 120 bytes)
    num pkts bytes target prot opt in out source destination 
    1 589K 2304M ACCEPT all -- * virbr0 0.0.0.0/0 192.168.122.0/24 state RELATED,ESTABLISHED
    2 404K 24M ACCEPT all -- virbr0 * 192.168.122.0/24 0.0.0.0/0 
    3 0 0 ACCEPT all -- virbr0 virbr0 0.0.0.0/0 0.0.0.0/0 
    Chain OUTPUT (policy ACCEPT 20 packets, 3545 bytes)
    num pkts bytes target prot opt in out source destination
    
    
    sudo iptables -nL -v --line-numbers -t nat
    Chain PREROUTING (policy ACCEPT 8392 packets, 1020K bytes)
    num pkts bytes target prot opt in out source destination 
    1 4 240 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2222 to:192.168.122.203:22
    Chain INPUT (policy ACCEPT 2194 packets, 261K bytes)
    num pkts bytes target prot opt in out source destination 
    Chain OUTPUT (policy ACCEPT 6 packets, 400 bytes)
    num pkts bytes target prot opt in out source destination 
    Chain POSTROUTING (policy ACCEPT 3 packets, 220 bytes)
    num pkts bytes target prot opt in out source destination 
    1 151 9060 MASQUERADE tcp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
    2 730 55480 MASQUERADE udp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
    3 3 252 MASQUERADE all -- * * 192.168.122.0/24 !192.168.122.0/24 
    4 5 300 SNAT tcp -- * * 0.0.0.0/0 192.168.122.203 tcp dpt:22 to:192.168.122.1
    
    

    J'ai donc rajoute les règles suivantes:

    sudo iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
    sudo iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.168.122.203:22
    sudo iptables -t nat -A POSTROUTING -p tcp --dport 22 -d 192.168.122.203 -j SNAT --to 192.168.122.1
    
    

    Et j'ai supprime les règles 4 et 5 de la chaîne FORWARD de la table filter

    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    (...) 
    4 7 420 REJECT all -- * virbr0 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
    5 0 0 REJECT all -- virbr0 * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
    
    

    Je pense pouvoir faire plus finement maintenant (en bloquant le trafic sauf pour le serveur virtuel hébergeant le serveur SSH).

    ssh user@xxx.xxx.xxx.xxx -p 2222
    user@xxx.xxx.xxx.xxx's password: 
    Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-34-virtual x86_64)
    
    

    Merci encore a tous!