# Opening a port in Ubuntu VM (OCI - Oracle Cloud Infrastructure)

Whether you're setting up a web server, database, or other services on a virtual machine (VM) in Oracle Cloud Infrastructure (OCI), you'll often need to open specific ports to allow incoming traffic. Opening a port in OCI VM is not as straightforward as other cloud providers. OCI makes use of iptables so there's an additional step involved to make it work.

Assuming you've

* Create a VM and have a service running on a port
    
* Opened the port in your security list and security group
    

### SSH to the VM

First, let's ssh to our VM. We need to save our current iptables by running below command in the SSH shell

```bash
iptables-save > current-rules.txt
```

After that, we need to run the below command to allow all traffic to flow.

```bash
sudo iptables -I INPUT -j ACCEPT
```

This will temporarily enable the flow of all traffic. Test everything and make sure it works.

After you've verified everything is fine, we need to persist this rule across reboots.

Run the below command

```bash
sudo iptables-save -f /etc/iptables/rules.v4
```

This will persist the rule across reboot.

Now, for any firewalling, you need to use either a security list or a security group.

Credit goes to [https://stackoverflow.com/a/73400079](https://stackoverflow.com/a/73400079)

Happy OCI'ing
