Sabito
Posted on September 2, 2024
Lately, quite a few of you have been asking how to open ports in Oracle Cloud. Honestly, it’s not as complicated as it sounds. So today, let’s dive into how to easily open ports in Oracle Cloud, both through the console and within the virtual machine (VM), to keep your projects running smoothly.
1. Opening Ports in Oracle Cloud Console: The Right Way
1.1 Access Oracle Cloud Console
First, you need to log in to the Oracle Cloud Console. If you don't have an account yet, no worries—sign up, they often have some decent free plans available. Once logged in, follow these steps:
- Find Your Instance: In the console, on the left sidebar, locate and click on "Instances." This will show all your active virtual machines (VMs).
-
Access Virtual Cloud Network (VCN): In the "Instance Information" section, look for "Virtual Cloud Network" (VCN)—it should have a name like
VirtualCloudNetwork-XXXX-XXXX
. Click on it! - Select a Subnet: Under "Subnets in (Root) Compartment," you’ll find something like "Public Subnet pbOp:XXXX-XX-1." Just pick one and go in.
- Edit Security List: Scroll down and find the "Security List." Then, click on the "Default Security List for VirtualCloudNetwork-XXXX-XXXX."
- Modify Ingress Rules: In the Ingress Rules section, you'll see a rule for port 22 (which is used for SSH connections). Either edit that rule and change the "Destination Port Range" from "22" to "22,80,443," or create new rules to allow ports 80 and 443, which are for HTTP and HTTPS respectively.
- Save Changes: Once you’re done editing, click "Save Changes," and you’re all set!
Now, you’ve successfully opened ports 22, 80, and 443, meaning both web access and SSH should be good to go. Remember to separate port numbers with commas, and if you need to open UDP ports, you can select UDP as the protocol when creating a rule.
Pro Tip:
- Don't go overboard opening too many ports. Too many open ports increase your risk of attacks.
- Oracle’s security groups will automatically generate IP-based rules, so no need to manually add extra ones.
2. Other Methods to Open Ports: The Simple, Brutal Ways
Sometimes, even after setting everything up in the Oracle Cloud Console, the firewall inside the VM may still block your traffic. Below are some quick and dirty methods to handle port opening directly within the VM.
2.1 Disabling the Firewall (Extreme)
If you’re feeling lazy, you can just disable the firewall entirely. This is super quick but not the best practice, especially in a production environment.
2.1.1 Deleting iptables Rules
One command and all the iptables rules are gone. After rebooting, the firewall will be completely disabled:
sudo rm -rf /etc/iptables && reboot
2.1.2 Opening All Ports
If you’re in a rush or just need all ports open temporarily, use these commands. But be warned, this exposes your server to the internet, so it’s not a safe option for long-term use:
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F
sudo apt-get purge netfilter-persistent
reboot
2.2 Using iptables for Fine-Grained Control
If you want more control and prefer to only open specific ports, you can use iptables
to do it in a more secure and flexible way.
2.2.1 Opening a Specific Port
Say you need to open port 8888 (often used for Jupyter Notebook), just run the following command:
sudo iptables -I INPUT -s 0.0.0.0/0 -p tcp --dport 8888 -j ACCEPT
2.2.2 Opening Common Web Ports (80 and 443)
To open the standard HTTP (port 80) and HTTPS (port 443) ports, you can run:
sudo iptables -I INPUT -s 0.0.0.0/0 -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -s 0.0.0.0/0 -p tcp --dport 443 -j ACCEPT
2.2.3 Saving iptables Rules
After opening the ports, make sure to save the iptables
rules to avoid losing them after a reboot:
sudo iptables-save
sudo apt-get update
sudo apt-get install iptables-persistent -y
sudo netfilter-persistent save
sudo netfilter-persistent reload
3. Wrapping It Up: Opening Ports Made Easy
Opening ports through the Oracle Cloud Console is pretty straightforward. Once you're done, your server should be accessible, and you can manage it without a hitch. Using iptables
for fine-tuning port access inside the VM allows you to control which ports are open, ensuring better security.
But always remember, brothers, security first! Don’t leave unnecessary ports open. The fewer the open ports, the safer your server is. Hope this guide helps you all out, and if you’ve got any questions or issues, feel free to drop a comment. Let’s figure it out together!
Posted on September 2, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.