En este ejemplo veremos como redireccionar el puerto 2525 para enviar todas sus conexiones al programa o servicio que se encuentre escuchando en el puerto 25
iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
4403K 231M DOCKER all -- * * 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER all -- * * 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * !docker0 172.17.0.0/16 0.0.0.0/0
0 0 MASQUERADE tcp -- * * 172.17.0.2 172.17.0.2 tcp dpt:3306
Chain DOCKER (2 references)
pkts bytes target prot opt in out source destination
0 0 RETURN all -- docker0 * 0.0.0.0/0 0.0.0.0/0
0 0 DNAT tcp -- !docker0 * 0.0.0.0/0 127.0.0.1 tcp dpt:3306 to:172.17.0.2:3306
iptables -t nat -A PREROUTING -p tcp --dport 2525 -j REDIRECT --to-port 25
Deberá salir la nueva regla
iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
4403K 231M DOCKER all -- * * 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
0 0 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2525 redir ports 25
...
...
telnet <dominio-ipaddr> <nPuerto>
telnet postal5.saitnube.com 2525
Trying 85.239.247.66...
Connected to postal5.saitnube.com.
Escape character is '^]'.
220 postal5.saitnube.com ESMTP Postal/KVKOLBGZ
HELO
250 postal5.saitnube.com
EHLO
250-My capabilities are
250 AUTH CRAM-MD5 PLAIN LOGIN
QUIT
221 Closing Connection
Connection closed by foreign host.