Linux Local External Network Issue: Two Servers, One Database, One Host HTTP Server Connection

Abstract: Resolve Linux HTTP server to database connectivity failures by verifying network reachability, firewall rules, and service binding configurations.

Created: 2026-09-22 by

Connecting an HTTP server to a database on a separate Linux host within a local external network requires verifying IP reachability, firewall rules, and service binding configurations. This guide outlines the diagnostic steps to resolve connectivity failures between these two distinct servers.

Verifying Network Reachability

The first step in troubleshooting any inter-server communication issue is to confirm that the two machines can physically see each other on the network layer. Since both servers reside in a local external network, they should be able to ping one another using their respective IP addresses. If the ping fails, the issue lies with the underlying network infrastructure rather than the application services. Start by identifying the IP address of your database server. You can use the ip addr show command or check your network configuration files to ensure you have the correct IPv4 address. It is crucial to distinguish between private internal IPs and public-facing IPs if your setup involves NAT or complex routing. Once you have the database server's IP, attempt to ping it from the HTTP server terminal:
ping -c 4 <database_server_ip>
If you receive replies, the network path is open. If the request times out, check for intermediate firewalls, incorrect subnet masks, or routing table errors. For a more detailed view of your network interfaces and their status, refer to our article on How do Ubuntu-server network interfaces work?. This will help you verify that the interface is UP and has the correct IP assigned.

Checking Firewall Rules

Even if ping succeeds, application-level ports may still be blocked by host-based firewalls. Linux systems typically use ufw (Uncomplicated Firewall) or iptables to manage incoming and outgoing traffic. The database server must allow inbound connections on its specific port (commonly 3306 for MySQL/MariaDB or 5432 for PostgreSQL) from the HTTP server's IP address. To check the current status of UFW on the database server, run:
sudo ufw status verbose
If the firewall is active, ensure there is a rule allowing traffic from the HTTP server's IP. You can add a rule specifically for the HTTP server to enhance security, rather than opening the port to the entire world:
sudo ufw allow from <http_server_ip> to any port <db_port>
After adding the rule, reload the firewall or restart the service depending on your distribution. If you are using iptables, you may need to inspect the INPUT chain directly. Remember that some cloud providers also have security groups or network ACLs at the virtualization layer that must permit traffic between instances. Always verify both the OS-level firewall and the cloud provider's network controls.

Validating Service Binding Configuration

A common mistake is assuming that a database service listens on all network interfaces when it is actually bound only to localhost. Database software often defaults to bind-address = 127.0.0.1 for security reasons. This setting prevents any external connection, even if the firewall allows it. You must edit the database configuration file to change this binding address. For MySQL/MariaDB, this is typically found in /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf. Look for the bind-address directive and change it to 0.0.0.0 to listen on all interfaces, or specify the specific LAN IP of the server. After making changes, restart the database service:
sudo systemctl restart mysql
For PostgreSQL, check the postgresql.conf file for listen_addresses and ensure it includes the server's IP or *. Additionally, verify the pg_hba.conf file to ensure it permits connections from the HTTP server's IP address with the appropriate authentication method. Without these changes, the database will reject connections from the HTTP server regardless of network availability.

Testing the Connection

Once network reachability, firewall rules, and service bindings are confirmed, test the actual connection from the HTTP server. You can use tools like telnet, nc (netcat), or the database client itself to verify connectivity. Using netcat is a quick way to test if the port is open:
nc -zv <database_server_ip> <db_port>
A successful connection will return a message indicating the port is open. If it fails, re-examine the previous steps. Ensure that the database user has permissions to connect from the remote host. In MySQL, you might need to create a user account that allows access from the HTTP server's IP:
CREATE USER 'user'@'<http_server_ip>' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'user'@'<http_server_ip>';
FLUSH PRIVILEGES;
This granular permission setup ensures that only the necessary server can interact with the database, maintaining a secure architecture.

Conclusion

Resolving connectivity issues between an HTTP server and a database server on a local external network involves a systematic approach. By verifying IP reachability, configuring firewalls correctly, adjusting service binding settings, and testing the connection, you can isolate and fix the problem. Always prioritize security by restricting access to specific IPs rather than opening ports broadly.

Frequently Asked Questions

Why does ping work but the database connection fails?

Ping operates at the ICMP network layer, while database connections use TCP on specific ports. A successful ping confirms basic network connectivity, but the database port may still be blocked by a firewall or the service may not be listening on the expected interface.

How do I find the database configuration file on Ubuntu?

On Ubuntu, MySQL configuration files are usually located in /etc/mysql/, specifically in mariadb.conf.d/ or mysql.conf.d/. Use the find /etc -name "*.cnf" command to locate all configuration files if you are unsure of the exact path.

Can I use SSH tunneling instead of direct database access?

Yes, SSH tunneling is a secure alternative to direct database exposure. You can forward a local port on the HTTP server to the database port on the DB server using ssh -L. This avoids modifying firewall rules or exposing the database port to the network.

What if my cloud provider blocks port 3306 by default?

Most cloud providers include security groups or network ACLs that restrict inbound traffic. You must log into your cloud console and manually add an inbound rule for the specific port (e.g., 3306) allowing traffic from the HTTP server's IP address.

How do I check which ports a service is listening on?

You can use the ss -tuln or netstat -tuln command on the database server. This will list all listening sockets, showing the protocol, local address, and port number, helping you verify if the service is bound to the correct IP and port.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More