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
Log in to your Oracle Cloud Infrastructure dashboard.
Navigate to Networking > Virtual Cloud Networks (VCN) > Security Lists associated with your instance.
Add an ingress rule to allow traffic on the desired port (e.g., 3002).
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:
Log in to the Server: Use SSH to connect to your instance.
ssh <your-user>@<your-instance-ip>
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
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:
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.