I have two VM, one is a database mariaDB server(10.0.0.1). How can I allow address from my internal network to connect to this DB?
To allow connections from your internal network to your MariaDB server (located at IP address 10.0.0.1), you need to follow these steps:
Edit the MariaDB Configuration File:
Open the MariaDB configuration file, typically located at /etc/mysql/my.cnf
or /etc/my.cnf
. You may also find it in /etc/mysql/mariadb.conf.d/50-server.cnf
depending on your installation.
sudo nano /etc/mysql/my.cnf
Bind Address:
Look for the line that starts with bind-address
. By default, it may be set to 127.0.0.1
, which means it only accepts local connections. Change it to 0.0.0.0
to allow connections from any IP address, or specify your internal network range.
bind-address = 0.0.0.0
Alternatively, if you want to restrict access to a specific subnet (e.g., 10.0.0.0/24), you can use firewall rules instead.
Save and Exit: Save the changes and exit the text editor.
Log into MariaDB: Use the following command to log into the MariaDB server:
mysql -u root -p
Create a User:
Create a user that can connect from your internal network. Replace username
, password
, and 10.0.0.%
with your desired username, password, and the appropriate IP range.
CREATE USER 'username'@'10.0.0.%' IDENTIFIED BY 'password';
Grant Privileges: Grant the necessary privileges to the user:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'10.0.0.%' WITH GRANT OPTION;
Flush Privileges: Make sure to flush the privileges to apply the changes:
FLUSH PRIVILEGES;
Exit MariaDB:
EXIT;
If you have a firewall running (like ufw
or iptables
), you need to allow traffic on the MariaDB port (default is 3306).
Using UFW: If you are using UFW, you can allow access with the following command:
sudo ufw allow from 10.0.0.0/24 to any port 3306
Using iptables:
If you are using iptables
, you can add a rule like this:
sudo iptables -A INPUT -p tcp -s 10.0.0.0/24 --dport 3306 -j ACCEPT
After making these changes, restart the MariaDB service to apply the configuration:
sudo systemctl restart mariadb
From a machine in your internal network, try to connect to the MariaDB server using the credentials you created:
mysql -u username -p -h 10.0.0.1
If everything is set up correctly, you should be able to connect to the MariaDB server from your internal network.
/var/log/mysql/
or /var/log/mariadb/
).