Skip to main content

More Info:

Port obfuscation is as an additional layer of defense against non-targeted attacks. In order to leverage this, your Amazon RDS databases instances should not use their default ports (MySQL/Aurora port 3306, SQL Server port 1433, PostgreSQL port 5432)

Risk Level

Low

Address

Security

Compliance Standards

PCIDSS

Remediation

How to ensure RDS Database Instances do not use default ports.

Using AWS Console

  1. Identify the Amazon RDS database instances for which you want to ensure that default ports are not used. (In the Cloudanix Console, navigate to “Misconfig” page and look for Affected Assets for “RDS Database Instances Should Not Use Default Ports” Policy.)
  2. Determine the default ports associated with the database engine you are using. Here are some common default ports:
    • MySQL: 3306
    • PostgreSQL: 5432
    • Oracle Database: 1521
    • SQL Server: 1433
  3. Open the AWS Management Console and navigate to the Amazon RDS service.
  4. Click on the name of the RDS instance for which you want to modify the port.
  5. In the instance details page, click on the “Configuration” tab.
  6. Under the “Connectivity & security” section, locate the “Endpoint & port” information.
  7. Click on the “Modify” button next to the “Endpoint & port” information.
  8. In the “Modify DB instance” window, locate the “Port” field.
  9. Change the value in the “Port” field to a non-default port that you want to use for the RDS instance. Ensure that the new port is not already used by any other service or application.
  10. Click on the “Apply immediately” checkbox to apply the changes immediately. If you don’t select this option, the changes will be applied during the next maintenance window for the RDS instance.
  11. Click on the “Modify DB instance” button to save the changes and modify the port.
  12. Repeat these steps for each Amazon RDS database instance that you want to ensure is not using the default port.

Triage and Remediation

Remediation

Using Console

Below are the console-based steps to move an RDS instance off its default port (e.g., 3306 for MySQL, 5432 for PostgreSQL, 1433 for SQL Server, 1521 for Oracle):

1. Plan the New Port

  1. Choose a non-default, unused port in the allowed range for your engine:
    • MySQL/MariaDB/PostgreSQL: 1150–65535 (except ports reserved by AWS)
    • SQL Server: 1150–65535
    • Oracle: 1150–65535
  2. Ensure your network/security team approves the port.

2. Update the RDS Instance Port

  1. Sign in to the AWS Management Console.
  2. Open RDS service.
  3. In the left menu, select Databases.
  4. Click the DB instance you want to change.
  5. Click Modify (top-right).
  6. In the Connectivity or Additional configuration section (varies by engine), find Port.
  7. Change it from the default (e.g., 3306/5432/1433/1521) to your chosen custom port.
  8. At the bottom:
    • Under Scheduling of modifications, choose:
      • Apply immediately (causes a brief downtime)
        or
      • Apply during the next scheduled maintenance window (less disruptive but delayed).
  9. Click Continue, review changes, then click Modify DB instance.
The instance will go into modifying then available status once complete.

3. Update the Security Group Rules

  1. Still in the RDS instance details page, in the Connectivity & security tab, find Security group rules.
  2. Click the linked VPC security group name to open it in the EC2 console.
  3. On the Inbound rules tab:
    • Edit the rule that allowed the old port (e.g., 3306).
    • Either:
      • Change the Port range to the new port, or
      • Add a new rule for the new port and remove the old port rule afterward.
    • Keep the same Source (CIDR, security group, etc.) so the same clients can still connect.
  4. Save the inbound rule changes.
If required, update Outbound rules similarly, though usually outbound is already open.

4. Update Application Configurations

  1. Find all applications, scripts, and tools that connect to this RDS instance.
  2. Update their DB connection strings:
    • Change the port value to the new port.
    • Hostname (endpoint) stays the same; only the port changes (unless you also changed anything else).
  3. Redeploy or restart applications if needed so they use the new configuration.

5. Validate Connectivity

  1. Use a DB client (e.g., psql, mysql, SQL Server Management Studio, etc.) and specify the new port:
    • Example (MySQL):
  2. Confirm that applications can successfully connect and operate.
  3. Once confirmed, verify that the old port is:
    • No longer open in security groups.
    • No longer referenced in any configs or scripts.

6. (Optional) Enforce via Baseline/Standards

  • Document the required non-default port in your internal standards.
  • Use AWS Config or a security tool to:
    • Detect RDS instances using default ports.
    • Alert or block non-compliant deployments.
Below are concise, CLI-focused steps to move RDS off default ports.

1. Identify RDS instances using default ports

Common default ports (AWS RDS engines):
  • MySQL / MariaDB / Aurora MySQL: 3306
  • PostgreSQL / Aurora PostgreSQL: 5432
  • Oracle: 1521
  • SQL Server: 1433
List all DB instances with their ports:
(Optional) Filter by a specific default port, e.g. MySQL’s 3306:

2. Choose a non-default port

Pick a port that:
  • Is not in use by other services in your environment.
  • Is allowed by your organization’s security policy. Example: 13306 for MySQL, 15432 for PostgreSQL, etc.

3. Update security groups before changing the port

Find the security groups used by the instance:
For each security group, add an inbound rule for the new port (example: 13306/TCP, CIDR 10.0.0.0/16):
After cutover, you can remove the old-port rule.

4. Change the RDS instance port

Changing --db-port causes a reboot/outage. Schedule a maintenance window.
If you prefer to apply during the next maintenance window, omit --apply-immediately.Check status until it’s available:
Confirm new port:

5. For Aurora (cluster) setups

For Aurora, you typically change each instance:
Repeat for all instances in the cluster.
Verify via:

6. Update application configurations

Update application connection strings to use the new port:
  • JDBC: jdbc:mysql://host:13306/dbname
  • psql: psql -h host -p 15432 -d dbname -U user
  • Any connection libraries: adjust port field.
Test connectivity from your app environment.

7. Remove old port from security groups

Once apps successfully use the new port, remove the old-port inbound rules:
Repeat for all affected SGs.
Below is one way to do this programmatically using Python and boto3:

1. Decide which ports are “default” and what to change them to

Common default ports (per engine):
You also must pick non-default target ports (coordinate with your app & security teams first):
Adjust the target ports to your standards and ensure corresponding security group rules and client configs will be updated.

2. Python script to find and remediate RDS instances on default ports


3. Operational steps to follow

  1. Test in non-production first.
  2. Ensure security groups allow the new port:
    • Add inbound rules for the new port before changing RDS.
    • Optionally remove old port after app migration.
  3. Update application connection strings:
    • Most drivers accept host:port or a separate port parameter.
    • Coordinate a maintenance window if ApplyImmediately=False is used or if app restart is required.
  4. Monitor after change:
    • Check RDS instance status until it becomes available.
    • Test app connectivity and logs.
If you want, I can adapt the script to:
  • Only target specific tags/instances.
  • Write changes to a “dry-run” report instead of modifying.
Changing the port on an existing aws_db_instance forces replacement of the database instance, which causes downtime and requires updating all clients to use the new port.For verification, terraform plan should show the port argument on the aws_db_instance (and matching security group rules) changing from the default (for example, ~ port: "5432" => "5433") and planning to replace the instance if it already exists.

Additional Reading: