Step-by-Step Guide to Opening a Port on Oracle Cloud Instance

Step-by-Step Guide to Opening a Port on Oracle Cloud Instance

When working with Oracle Cloud Infrastructure, you may encounter a scenario where you need to open a specific port on your instance to allow external access. However, opening the port from the security group alone might not work. This is because Oracle adds an extra layer of security by requiring you to not only enable the port from the OCI dashboard but also configure iptables on the instance itself.

In this guide, we will demonstrate how to open port 3002 as an example. You can replace 3002 with your desired port number.


Step 1: Enable the Port from Oracle Dashboard

  1. Log in to your Oracle Cloud Infrastructure dashboard.

  2. Navigate to Networking > Virtual Cloud Networks (VCN) > Security Lists associated with your instance.

  3. Add an ingress rule to allow traffic on the desired port (e.g., 3002).

  4. Save the changes.


Step 2: Configure iptables on the Server

After enabling the port in the Oracle dashboard, you need to allow it at the instance level using iptables. Follow the steps below:

  1. Log in to the Server: Use SSH to connect to your instance.

     ssh <your-user>@<your-instance-ip>
    
  2. Add a Rule to Open the Port: Run the following command, replacing 3002 with your desired port number:

     sudo iptables -I INPUT -m state --state NEW -p tcp --dport 3002 -j ACCEPT
    
  3. Verify the Rule: Confirm that the rule has been added by listing the iptables rules:

     sudo iptables -L INPUT --line-numbers
    

    You should see a rule that looks like this:

  4. Save the iptables Rules: To ensure that the rule persists across server reboots, install iptables-persistent and save the configuration:

     sudo apt install iptables-persistent
     sudo netfilter-persistent save
     sudo netfilter-persistent reload
    

    This saves the current rules and reloads them whenever the server restarts.


By following these steps you’ve successfully opened a port on your Oracle Cloud instance.
Repeat the steps for any additional ports as required by your application.

For more, refer to the official Oracle Cloud Infrastructure documentation.