Sunday, February 22, 2026

Oracle Cloud Instance Ubuntu iptables

I've recently been exploring Oracle's Cloud offerings while looking to migrate a website from an Amazon EC2 instance.  After struggling with troubleshooting connectivity through Oracle's Cloud seemingly straight forward security offerings, I found the default Ubuntu image has iptables configured as well.  It restricts all ingress except port 22 for SSH.

Given I rarely dabble in iptables, here's a few tips for next time:

! Show iptables configuration including line numbers
sudo iptables -L -n --line-numbers

! Add and entry to accept traffic on port 80 at configuration line number 4
! Existing entries at line 4 and beyond will slide down to 5 and beyond
sudo iptables -I INPUT 4 -p tcp --dport 80 -m state --state NEW -j ACCEPT

! Add and entry to accept traffic on port 443 at configuration line number 4
! Existing entries at line 4 and beyond will slide down to 5 and beyond
sudo iptables -I INPUT 4 -p tcp --dport 443 -m state --state NEW -j ACCEPT

! Make the entries persistent
sudo netfilter-persistent save

If your successful, your iptables look something like this:

ubuntu@server001:~$
ubuntu@server001:~$ sudo iptables -L -n --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
2    ACCEPT     1    --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     0    --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 state NEW
5    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 state NEW
6    ACCEPT     6    --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
7    REJECT     0    --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited