<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Waseem Bashir</title>
    <description>The latest articles on DEV Community by Waseem Bashir (@waseem_portgate).</description>
    <link>https://dev.to/waseem_portgate</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4282701%2F41f5545b-d64a-44f1-bd88-25723981fa24.png</url>
      <title>DEV Community: Waseem Bashir</title>
      <link>https://dev.to/waseem_portgate</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/waseem_portgate"/>
    <language>en</language>
    <item>
      <title>Is your database open to the internet? A 5-minute port check for any Linux VPS</title>
      <dc:creator>Waseem Bashir</dc:creator>
      <pubDate>Fri, 04 Dec 2026 11:47:53 +0000</pubDate>
      <link>https://dev.to/waseem_portgate/is-your-database-open-to-the-internet-a-5-minute-port-check-for-any-linux-vps-1g50</link>
      <guid>https://dev.to/waseem_portgate/is-your-database-open-to-the-internet-a-5-minute-port-check-for-any-linux-vps-1g50</guid>
      <description>&lt;p&gt;Most servers that get broken into aren't hit with anything clever. Someone ran a scanner across the internet, found a database that answered, and walked in. Redis, MongoDB, Elasticsearch and Postgres instances get found this way every day, usually within hours of going online.&lt;/p&gt;

&lt;p&gt;The good news is that checking your own server takes about five minutes. Here's how I do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. List everything that is listening
&lt;/h2&gt;

&lt;p&gt;On the server, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo ss -tlnp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll get one line per listening TCP socket, with the address it is bound to and the process that owns it. The column to look at is &lt;strong&gt;Local Address:Port&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You see&lt;/th&gt;
&lt;th&gt;It means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;127.0.0.1:6379&lt;/code&gt; or &lt;code&gt;[::1]:6379&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Only this server can connect. Good.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;10.x.x.x&lt;/code&gt;, &lt;code&gt;172.16-31.x.x&lt;/code&gt;, &lt;code&gt;192.168.x.x&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A private network. Usually fine.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;0.0.0.0:6379&lt;/code&gt;, &lt;code&gt;[::]:6379&lt;/code&gt; or &lt;code&gt;*:6379&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Every interface, including the public one.&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Anything on &lt;code&gt;0.0.0.0&lt;/code&gt; or &lt;code&gt;[::]&lt;/code&gt; that isn't meant for the public (in other words, anything other than SSH, 80 and 443 on most web servers) is worth a second look.&lt;/p&gt;

&lt;p&gt;If you also run UDP services, add &lt;code&gt;-u&lt;/code&gt;: &lt;code&gt;sudo ss -tulnp&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Watch out for Docker
&lt;/h2&gt;

&lt;p&gt;If you use Docker, you'll often see &lt;code&gt;docker-proxy&lt;/code&gt; in that list. A Compose file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;redis:7&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"6379:6379"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;publishes Redis on &lt;strong&gt;every&lt;/strong&gt; interface of the host. And on most Linux setups Docker writes its own iptables rules, which are evaluated before UFW's, so &lt;code&gt;ufw deny 6379&lt;/code&gt; does nothing to stop it. This catches a lot of people who did everything else right.&lt;/p&gt;

&lt;p&gt;The fix is to bind the published port to localhost:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1:6379:6379"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Better still, if only your other containers need Redis, remove &lt;code&gt;ports:&lt;/code&gt; entirely and let them reach it by service name on the Compose network.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Check from the outside
&lt;/h2&gt;

&lt;p&gt;What the server thinks is listening and what the internet can actually reach aren't always the same thing (cloud firewalls, security groups, NAT). So test from a different machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nmap -Pn -p 22,80,443,3306,5432,6379,9200,11434,27017 YOUR.SERVER.IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, for a single port without nmap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nc -zv YOUR.SERVER.IP 6379
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;open&lt;/code&gt; from outside means anyone can try it. &lt;code&gt;filtered&lt;/code&gt; or &lt;code&gt;closed&lt;/code&gt; is what you want for anything that isn't a public service.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Fix the common ones
&lt;/h2&gt;

&lt;p&gt;Most databases already default to localhost these days. They end up public because a tutorial or a Docker run command changed that. Here's where to look:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Redis (6379):&lt;/strong&gt; in &lt;code&gt;redis.conf&lt;/code&gt;, keep &lt;code&gt;bind 127.0.0.1 -::1&lt;/code&gt; and &lt;code&gt;protected-mode yes&lt;/code&gt;, and set a password with &lt;code&gt;requirepass&lt;/code&gt;. An open Redis can be used to write files to disk, which is a well-known route from "database" to "shell on your server". Full walkthrough: &lt;a href="https://portgate.dev/ports/6379-redis" rel="noopener noreferrer"&gt;Port 6379 Redis guide&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL (5432):&lt;/strong&gt; &lt;code&gt;listen_addresses = 'localhost'&lt;/code&gt; in &lt;code&gt;postgresql.conf&lt;/code&gt;, and no &lt;code&gt;0.0.0.0/0&lt;/code&gt; lines in &lt;code&gt;pg_hba.conf&lt;/code&gt;. &lt;a href="https://portgate.dev/ports/5432-postgresql" rel="noopener noreferrer"&gt;Port 5432 guide&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MySQL / MariaDB (3306):&lt;/strong&gt; &lt;code&gt;bind-address = 127.0.0.1&lt;/code&gt; in the server config. &lt;a href="https://portgate.dev/ports/3306-mysql" rel="noopener noreferrer"&gt;Port 3306 guide&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MongoDB (27017):&lt;/strong&gt; &lt;code&gt;net.bindIp: 127.0.0.1&lt;/code&gt; in &lt;code&gt;mongod.conf&lt;/code&gt;, and turn on authorization. Open MongoDB servers are routinely copied and wiped by ransom bots. &lt;a href="https://portgate.dev/ports/27017-mongodb" rel="noopener noreferrer"&gt;Port 27017 guide&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elasticsearch (9200):&lt;/strong&gt; &lt;code&gt;network.host: 127.0.0.1&lt;/code&gt;, with security enabled. &lt;a href="https://portgate.dev/ports/9200-elasticsearch" rel="noopener noreferrer"&gt;Port 9200 guide&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After any change, restart the service and run &lt;code&gt;sudo ss -tlnp&lt;/code&gt; again to confirm the address moved to &lt;code&gt;127.0.0.1&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Need remote access? Use a tunnel, not a public port
&lt;/h2&gt;

&lt;p&gt;If you need to reach a database from your laptop, you don't need to open it to the world. An SSH tunnel does the job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh -L 5432:127.0.0.1:5432 you@YOUR.SERVER.IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then connect your client to &lt;code&gt;localhost:5432&lt;/code&gt;. When you close the SSH session, the tunnel closes too. For a team, a private network such as WireGuard or Tailscale is the next step up.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Make it a habit, not a one-off
&lt;/h2&gt;

&lt;p&gt;The trouble with ports is that they change. Someone adds a container, a package update rewrites a config, a teammate copies a &lt;code&gt;docker run&lt;/code&gt; line from a blog post. The check you did today says nothing about next month.&lt;/p&gt;

&lt;p&gt;A few low-effort ways to keep on top of it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;sudo ss -tlnp&lt;/code&gt; after every deploy that touches Docker or system packages.&lt;/li&gt;
&lt;li&gt;Lint Compose files before they ship. I made a free &lt;a href="https://portgate.dev/tools/docker-compose-linter" rel="noopener noreferrer"&gt;Docker Compose security linter&lt;/a&gt; that flags ports published on all interfaces, privileged containers and mounted Docker sockets.&lt;/li&gt;
&lt;li&gt;Keep a short list of the ports each server is &lt;em&gt;supposed&lt;/em&gt; to have open, and compare against it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full disclosure: I build &lt;a href="https://portgate.dev" rel="noopener noreferrer"&gt;PortGate&lt;/a&gt;, which automates that last step. A small agent reports the server's public ports every five minutes, compares them with a baseline you approve and alerts you, with the fix command, when something new appears. It's free for one server. But everything above works fine by hand, and it's worth doing today either way.&lt;/p&gt;

&lt;p&gt;If you've been caught out by one of these, I'd like to hear which one in the comments.&lt;/p&gt;

</description>
      <category>security</category>
      <category>linux</category>
      <category>devops</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
