16

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..

EODCraft Staff
  • 873
  • 1
  • 9
  • 27
Comrade
  • 215
  • 1
  • 4
  • 16
  • 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 04 '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 04 '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 04 '17 at 11:20
  • @Rinzwind My point was that on `sudo netstat -plnt` should return `0.0.0.0:3306`. – Comrade May 04 '17 at 11:22
  • Perhaps clarify your question as to what exactly you are trying to do and we can assist you better. – EODCraft Staff May 04 '17 at 11:24
  • @eodcraftstaff 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.` – Comrade May 04 '17 at 11:27
  • 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 04 '17 at 11:33
  • @steeldriver still not working, Please help me out – Comrade May 04 '17 at 11:46
  • You state that the "No connection could be made because the target machine actively refused it.". Have you checked your database permissions to verify that the user can login from any computer on the network? For my home network, I use `192.168.1%` for the user to access the database. See https://dev.mysql.com/doc/refman/5.7/en/account-names.html and https://stackoverflow.com/questions/11742963/how-to-grant-remote-access-to-mysql-for-a-whole-subnet and https://stackoverflow.com/questions/6239131/how-to-grant-remote-access-permissions-to-mysql-server-for-user – Steve R. May 28 '17 at 02:05

1 Answers1

25

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
Eduard Florinescu
  • 7,707
  • 9
  • 46
  • 51