9

I cannot access my db remotely, The only thing i found out is the port 3306 is open for 127.0.0.1, I want it open globally. The error i receives on accessing db is No connection could be made because the target machine actively refused it.

I have ubuntu 16.04, Installed mariaDB, The bind-address = 0.0.0.0.

When i hit sudo netstat -plnt it returns :

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      21013/mysqld
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1172/sshd
tcp6       0      0 :::8080                 :::*                    LISTEN      13710/apache2
tcp6       0      0 :::80                   :::*                    LISTEN      13710/apache2
tcp6       0      0 :::22                   :::*                    LISTEN      1172/sshd
tcp6       0      0 :::443                  :::*                    LISTEN      13710/apache2

There is no 0 0.0.0.0:3306.

How can i allow 0 0.0.0.0:3306.

sudo ufw status returns :

Apache Full                ALLOW       Anywhere
22                         ALLOW       Anywhere
3306                       ALLOW       161.202.20.0/24
3306 on eth1               ALLOW       Anywhere
3306                       ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)
3306 (v6) on eth1          ALLOW       Anywhere (v6)
3306 (v6)                  ALLOW       Anywhere (v6)

On accessing the DB remotely i receives No connection could be made because the target machine actively refused it..

  • This seems to be about configuring the listening interface, rather than opening the port: where did you set bind-address = 0.0.0.0? – steeldriver May 4 '17 at 11:13
  • 1
    The address 0.0.0.0 is a non routable meta address so your question "How can i allow 0 0.0.0.0:3306?" makes no sense. – Rinzwind May 4 '17 at 11:17
  • Okay, The bind-address=0.0.0.0 is in /etc/mysql/mariadb.conf.d/50-server.conf. @steeldriver – Comrade May 4 '17 at 11:20
  • @Rinzwind My point was that on sudo netstat -plnt should return 0.0.0.0:3306. – Comrade May 4 '17 at 11:22
  • 3
    I think that the right way to do it is to comment out the bind-address line (rather than trying to explicitly set it to 0.0.0.0) – steeldriver May 4 '17 at 11:33
16

To allow a port

sudo ufw allow 3306

if its ufw is not installed is probably iptables

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  • how do you undo the iptables command ? – maxbellec Apr 20 '20 at 8:48
  • 1
    @maxbellec list rules by line number sudo iptables -L --line-numbers and then specify the rule number sudo iptables -Z INPUT 1 – Eduard Florinescu Apr 20 '20 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.