Selenium binds to 0.0.0.0 regardless of what host info you provide when configuring Selenium. That means requests to Selenium on local and public IP addresses will be processed.
Ubuntu comes with a package called Uncomplicated Firewall (aka UFW). It however, is not enabled by default.
You'll want to enable SSH access before enabling UFW or you'll lock yourself out of your machine if you depend on SSH for access.
You'll want to enable things like SSH and possibly port 80 if you're hosting a website on this machine.
sudo ufw allow ssh # If you're running a website. sudo ufw allow 80 # If you're running SSL. sudo ufw allow 443
Now that we have our desired ports configured, we can enable UFW.
sudo ufw enable
You should get a response message saying UFW was successfully enabled and is enabled on boot.
Software engineer by profession, embedded systems tinkerer, husband, father, fantasy novel devourer, wine lush, beer and cheese connoisseur