This is how I did it without directly meddling with iptables
.
First create an Ingress Rule
in Oracle Cloud vps's dashboard/Networking/Virtual Cloud Networks, for example, for port range 23-90

Next, install firewalld
in ubuntu (firewalld
is available in centos I think)
sudo apt-get install firewalld
sudo systemctl enable firewalld
sudo systemctl start firewalld
You only need to do this one time. It will still be there after a reboot.
Then, to open port 80:
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent # or --add-service=http
sudo firewall-cmd --reload
To verify:
sudo firewall-cmd --list-all
Output:
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: 80/tcp
...
The same applies to opening other port(s). You can easily remove the port (--remove-port=80/tcp
+ a --reload
), refer to firewalld
docs.
To test from a remote computer
- run a web server at port 80 in Oracle Cloud vps if one is not already running, for example:
python3 -m http.server 80
- In a remote computer
curl ip-of-oc-vps:80
I also wasted a lot of time on Oracle Cloud Always Free vps' firewall. I hope this can save other people some time.