Springuptech
← Back to Insights

When Ports 80/443 Won't Open on an Oracle Cloud Free Server — The Two Firewall Layers: Security Lists and Ubuntu iptables

Why a web server on an Oracle Cloud (OCI) free instance is unreachable from outside, and how to fix it. Covers the two firewall layers — VCN security list / network security group ingress rules and the iptables rules shipped with the Ubuntu image — why the allow rule must come before the REJECT rule, saving with netfilter-persistent, a symptom-based diagnosis order, and putting Tomcat behind Nginx.

Jaeyong RohPublished 11 min read

Oracle Cloud (OCI) Always Free instances are a good choice for personal projects and small web services. But after creating an instance, installing Nginx or Tomcat and opening the public IP in a browser, many people get a timeout or a refused connection. Running curl http://localhost on the server works fine — it only fails from outside.

The cause is almost always that there are two firewall layers. One is the rule set on the OCI network (VCN); the other is the iptables rule set inside the instance's operating system. If you are used to other clouds, it is easy to add one rule in the console and assume you are done. This article walks through, for the Ubuntu image, how to open each layer, how to confirm it is really open, and how to then run Nginx and Tomcat on top.

Understand the structure first: two gates a packet passes through

A request from an outside browser is checked in this order before it reaches the web server process.

Order Gate Where it is configured What the client sees when blocked
1 VCN security list or network security group (NSG) OCI console Timeout with no response
2 The instance OS firewall (iptables on Ubuntu) Server terminal No route to host or a timeout
3 The web server process Nginx, Tomcat configuration Connection refused

The two gates know nothing about each other. If you open port 80 in the console but the server's iptables blocks it, you still cannot connect; if you open it on the server but the VCN blocks it, the packet never even reaches the server. You must open both.

For reference, the security list of a VCN created with OCI's defaults usually has ingress rules allowing only SSH (TCP 22) and some ICMP. That is why SSH works from day one while web ports do not.

Step 1: Add ingress rules in the OCI console

From the instance details page, go to its subnet, then open the security list attached to that subnet. (Menu path: Networking → Virtual Cloud Networks → your VCN → Subnet → Security Lists.) Click "Add Ingress Rules" and enter:

Field Value
Stateless Leave unchecked
Source type CIDR
Source CIDR 0.0.0.0/0 (allow from anywhere)
IP protocol TCP
Source port range Leave empty (all)
Destination port range 80

Add a second rule the same way with destination port 443.

A few things to watch out for:

  • Do not check Stateless. With a stateful rule, responses to incoming requests are allowed automatically. A stateless rule also requires matching egress rules and is easy to get wrong.
  • Do not mix up source port and destination port. Browsers connect from a random high port, so leave the source port empty and put 80/443 in the destination port (the server side). If you swap them, the rule exists but connections still fail.
  • If you use network security groups (NSGs), you can put the same rules in the NSG attached to the instance's VNIC instead. Security lists and NSGs are combined so that traffic is allowed if either one allows it. Pick one place and manage the rules there to avoid confusion later.
  • If you attached the instance to a VCN or subnet you built yourself, also check that the subnet's route table has an internet gateway route (0.0.0.0/0) and that the instance has a public IP. A VCN created with the console's default wizard usually already has both.

Step 2: Open the iptables rules inside Ubuntu

This is where most people get stuck. OCI's Ubuntu platform images ship with iptables rules already in place, and those rules allow only what is essential, such as SSH, then REJECT everything else. List the current rules with numbers:

sudo iptables -L INPUT -n --line-numbers

It varies slightly by image version, but looks roughly like this:

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp spt:123
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

(Line 3 actually applies only to the loopback interface lo; the interface is not shown without the -v option.)

iptables checks rules from the top down and stops at the first match. So the allow rules must go before the final REJECT rule. A common mistake is using -A (append to the end): the rule lands after REJECT and has no effect.

# Insert at the REJECT rule's position (6 in the example above); the old rule 6 moves down
sudo iptables -I INPUT 6 -p tcp -m state --state NEW --dport 80 -j ACCEPT
sudo iptables -I INPUT 7 -p tcp -m state --state NEW --dport 443 -j ACCEPT

Use the REJECT rule's number from your own listing. If counting is a hassle, -I INPUT 1 (insert at the top) works just as well; placing the rules right before REJECT simply keeps the list tidier.

Many examples online hard-code the network interface name, such as -i ens3. The interface name can differ by instance shape or image, so check the real name with ip -br addr before copying such a command. For opening web ports, you do not need to specify an interface at all.

Save the rules so they survive a reboot

Rules changed with the iptables command live only in memory and disappear after a reboot. The Ubuntu image includes netfilter-persistent (the iptables-persistent package), so you can save the current rules to a file:

sudo netfilter-persistent save

The saved rules are in /etc/iptables/rules.v4 (rules.v6 for IPv6). If you edit the file directly, reload it with sudo netfilter-persistent reload.

Older posts online sometimes also list commands like service iptables save and service iptables restart. Those belong to older CentOS/RHEL systems; Ubuntu has no such service, so they do not work there. On Ubuntu, stick to netfilter-persistent.

What not to do

  • Do not flush all rules with sudo iptables -F. The OCI image's rules include some that look unrelated to web ports but are needed for the instance to talk to OCI's internal services (such as the metadata service and block volume attachment in the 169.254.x.x range). Flushing everything can cause problems in unexpected places. Add only the ports you need.
  • Do not enable ufw on top of the existing iptables rules. ufw is itself a tool that generates iptables rules, and mixing it with the rules already present makes it hard to tell which rule applies. On OCI's Ubuntu image, adding the ports you need to the existing iptables rules is the simplest approach.

If you use the Oracle Linux image

Oracle Linux images use firewalld instead of plain iptables. Open the ports like this:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Step 3: Check in the right order

If it still does not work after adding the rules, the fastest way is to check from the inside out.

① Is the web server actually listening on the port?

sudo ss -tlnp | grep -E ':(80|443|8080)\b'

You should see a LISTEN line. Look at the address part as well. If it says something like 127.0.0.1:8080, the server accepts connections only from inside the machine and will never be reachable from outside. To accept outside connections it must be 0.0.0.0:80 or *:80.

② Does it respond from inside the server?

curl -I http://localhost

If this fails, the problem is the web server configuration, not the firewall.

③ Is the iptables rule before REJECT, and are packets actually hitting it?

sudo iptables -L INPUT -n -v --line-numbers

With -v, each rule shows how many packets matched it (pkts). If the counter on the port 80 rule goes up right after you try to connect from outside, packets are passing the VCN and reaching the server. If it stays at 0, go back to Step 1 (VCN ingress rules).

④ Connect from outside the server

Always test from a machine other than the server (your own PC, for example).

curl -I http://<public IP>
# or check just the port
nc -vz <public IP> 80

The error the client sees already tells you roughly where traffic is blocked.

Symptom seen from outside Most likely cause
Long wait, then timeout No rule in the VCN security list/NSG, or a route/public IP problem
No route to host Hit the REJECT rule (icmp-host-prohibited) in the server's iptables
Connection refused Passed the firewalls, but no process is listening on that port
HTTP response arrives but with 502 or similar Not a firewall problem; check the application behind Nginx (Tomcat, etc.)

Step 4: Run Nginx and Tomcat

With the ports open, it is time to run the actual service. A common setup for Java web applications is Nginx listening on 80/443 and forwarding to Tomcat on 8080 behind it.

Reasons for this split:

  • On Linux, ordinary users cannot bind ports below 1024. Letting Nginx receive traffic and forward it is safer than running Tomcat as root so it can bind port 80 directly.
  • Nginx handles HTTPS certificates, static files, compression and access logs, while Tomcat focuses on the application.
  • Port 8080 does not need to be exposed, so both the VCN and iptables only need 80/443 open.

Choosing Java and Tomcat versions

Each Tomcat version requires a different minimum Java version and uses a different Servlet API package name.

Tomcat Minimum Java Servlet API package
9.0.x Java 8 javax.servlet
10.1.x Java 11 jakarta.servlet
11.0.x Java 17 jakarta.servlet

If you are moving an existing javax.*-based JSP/servlet application, Tomcat 9 is the easiest path; for a new project, choose 10.1 or later. In either case, an LTS Java release with a long support window (17 or 21) is recommended. Tomcat 9 runs fine on Java 17.

What matters is confirming that the version you chose is the version you actually installed. It is surprisingly common for notes to say "we use Java 11" while the install command actually installs Java 8.

sudo apt update
sudo apt install -y openjdk-17-jdk
java -version   # check the version actually installed and selected

If several versions are installed, choose the default with sudo update-alternatives --config java.

You can install Tomcat from the distribution's packages, or download the binary for the version you want from the Apache Tomcat website and register it as a systemd service running under a dedicated user. Either way, the default HTTP connector is on port 8080. After installing, first confirm a response from inside the server with curl -I http://localhost:8080.

If Tomcat will sit only behind Nginx, setting address="127.0.0.1" on the connector in Tomcat's server.xml prevents direct outside access to 8080, which is safer.

Nginx reverse proxy configuration

sudo apt install -y nginx

Create /etc/nginx/sites-available/myapp with the following content, replacing example.com with your real domain.

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the site, check the syntax, and reload.

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Now opening http://<public IP> or your domain from outside should show the Tomcat application.

Adding HTTPS

If your domain's DNS points to the instance's public IP, you can get a Let's Encrypt certificate with certbot.

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com

certbot's default validation method (HTTP-01) only succeeds if port 80 is reachable from outside. If issuing the certificate fails, use the Step 3 order to confirm that port 80 is really open. Once it succeeds, also check from outside that port 443 works.

Checklist

  • OCI console: added TCP 80 and 443 ingress rules to the subnet's security list (or the VNIC's NSG), with the source port empty and the ports in the destination port field.
  • The subnet's route table has an internet gateway route, and the instance has a public IP.
  • Ubuntu: checked with iptables -L INPUT -n --line-numbers and inserted the 80/443 allow rules before the REJECT rule.
  • Saved with sudo netfilter-persistent save, and did not use other distributions' commands such as service iptables ....
  • Did not flush existing rules with iptables -F or mix in ufw.
  • Confirmed with ss -tlnp that the web server listens on 0.0.0.0 or *.
  • Tested with curl from an outside PC, not from the server itself.
  • Kept Tomcat on 8080 (preferably 127.0.0.1) with Nginx receiving 80/443, and confirmed with java -version that the installed Java matches the version you chose.

In short, most "ports won't open on Oracle Cloud" problems are solved as soon as you remember the two-layer structure: one place in the console, one place on the server. Use the client's error message to guess which gate is blocking, then check from the inside out, and you will spend far less time guessing.

If you are setting up a cloud server for the first time, or moving an existing service to the cloud and need help with firewalls, web servers and the Java runtime environment, contact Springuptech. We will review your current setup and how you operate it, and put together the configuration you need.

※ This article expands on our lead engineer's earlier personal blog post (in Korean): "Oracle Cloud Tomcat + JAVA + JSP + MySql 개발환경".

Oracle CloudLinuxiptablesFirewallNginx
J

Jaeyong Roh

Lead engineer at Springuptech · 22 years in software engineering

Have a project related to this topic?

Even if it is just an idea, we will help you work out what is possible.

Practical tips from real projects

8 min read

Building "MiniPlay", a Mini Games Site — Seven Languages, Leaderboards and Game Uploads with Build-Free Vanilla JavaScript

How we built a site with 20 instant-play browser mini games in five days — why we chose a no-build structure, how each game plugs in as an independent folder, generating pages in seven languages, Firebase sign-in and leaderboard security rules, and an admin page for uploading games.

PortfolioJavaScriptFirebase
Read more
14 min read

Getting Started with C++ Unit Testing Using GoogleTest on Ubuntu — CMake FetchContent Setup, First Tests, GoogleMock, and Testing std::filesystem File Utilities

A step-by-step guide to setting up C++ unit tests with GoogleTest and GoogleMock on Ubuntu. It covers installing with CMake FetchContent (compared with the older build-from-source approach), first tests and fixtures, a mock example, running with ctest, and a complete example that tests C++17 std::filesystem functions for counting files, changing permissions recursively and setting modification times.

C++GoogleTestCMake
Read more
13 min read

Building an Oracle Query That Alerts When the Failure Rate Exceeds 10% in the Last 5 Minutes — Date Arithmetic, SUM(CASE), HAVING, Indexes and Batch Integration

A step-by-step guide to an Oracle query that computes the failure rate of the last N minutes from a transaction log and flags when it crosses a threshold — covering DATE and TIMESTAMP arithmetic, time-window filtering, aggregation with SUM(CASE) and HAVING, division by zero and small samples, indexes, and calling it from a Pro*C batch.

OracleSQLMonitoring
Read more