Accediendo a mySQL desde dos puertos: Problemas con iptables

Accediendo a mySQL desde dos puertos: Problemas con iptables

Estoy intentando hacer que mi servidor mySQL (que se ejecuta en Ubuntu) escuche en el puerto 3306y110, porque me gustaría acceder a él desde una red con muy pocos puertos abiertos.

Hasta ahora he encontradoesta respuestadiciéndome que haga

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 110 -j REDIRECT --to-port 3306

pero todo lo que tengo es:

# mysql -h mydomain.com -P 3306 -u username --password=xyz
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 68863
Server version: 5.0.75-0ubuntu10.5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

# mysql -h mydomain.com -P 110 -u username --password=xyz
ERROR 2003 (HY000): Can't connect to MySQL server on 'mydomain.com' (111)

No soy un experto en iptables, por lo que no estoy seguro de dónde buscar el problema. Estoy buscando en Google desde hace bastante tiempo, pero todavía no he encontrado nada que me ayude.

Esto es lo que me dice iptable:

# iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 32M packets, 1674M bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REDIRECT   tcp  --  eth0   *       0.0.0.0/0            0.0.0.0/0           tcp dpt:110 redir ports 3306 

Chain POSTROUTING (policy ACCEPT 855K packets, 55M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 837K packets, 54M bytes)
 pkts bytes target     prot opt in     out     source               destination   


# iptables -L -n -v
Chain INPUT (policy DROP 7 packets, 340 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 107K 5390K LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `INPUT INVALID ' 
 131K 6614K DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x05/0x05 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x11/0x01 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x18/0x08 
    0     0 MY_DROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x30/0x20 
6948K   12G ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
 151M   34G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
  32M 1666M ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
 1833  106K ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443 
  603 29392 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25 
    1    60 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:465 
   24  1180 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:110 
    1    60 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:995 
 7919  400K ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:143 
    1    60 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:993 
    0     0 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:119 
    1    60 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:53 
    7   517 ACCEPT     udp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:53 
 1110 65364 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:21 
 139K 8313K ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
10176  499K ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 
    2    80 ACCEPT     udp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:123 
    0     0 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:6060 
    4   176 ACCEPT     tcp  --  venet0 *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:6667 
20987 1179K MY_REJECT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 2159  284K LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `OUTPUT INVALID ' 
 2630  304K DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
6948K   12G ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0           
 181M   34G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW,RELATED,ESTABLISHED 
    0     0 MY_REJECT  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain MY_DROP (7 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `PORTSCAN DROP ' 
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain MY_REJECT (2 references)
 pkts bytes target     prot opt in     out     source               destination         
13806  652K LOG        tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `REJECT TCP ' 
18171  830K REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with tcp-reset 
  912  242K LOG        udp  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `REJECT UDP ' 
  912  242K REJECT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 
 1904  107K LOG        icmp --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `DROP ICMP ' 
 1904  107K DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 2/sec burst 5 LOG flags 0 level 4 prefix `REJECT OTHER ' 
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-proto-unreachable

¿Hay alguien que pueda darme una pista sobre dónde buscar el problema?

¡Gracias!

Respuesta1

El servidor midominio.com solo acepta conexiones TCP entrantes en el puerto 110 cuando entran en la interfaz venet0. Dado que su regla NAT de iptables se aplica solo al tráfico que ingresa a la interfaz eth0, puede:

  • el tráfico ingresa a la interfaz venet0y ha elegido la interfaz incorrecta para la regla NAT, o
  • el tráfico ingresa a la interfaz eth0y, por lo tanto, nunca llega a la regla NAT porque iptables lo está bloqueando.

Si puede contarnos más sobre la configuración de la interfaz en midominio.com ( ifconfig -atal vez), debería ser posible decir cuál de estas afirmaciones es verdadera.

información relacionada