Ubuntu 18.04.6 LTS (Bionic Beaver) / Ubuntu 20.04.3 LTS (Focal Fossa) - Common Commands & Frequent Tasks
Allowing Incoming Traffic on Specific Ports
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
or
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
List Iptable rules
sudo iptables -L
Save iptables rules
sudo sh -c "iptables-save > /etc/iptables.rules"
Apply rules
sudo iptables-apply /etc/iptables.rules
Disabling the firewall - iptables
If you need to disable the firewall temporarily, you can flush all the rules using
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -F
Delete Iptables rule by line number
sudo iptables -L --line-numbers
sudo iptables -D INPUT 3
Disabling the firewall - UFW
systemctl stop ufw
systemctl disable ufw
iptables-persistent
sudo apt-get install iptables-persistent
sudo netfilter-persistent save
Disable swap
sudo swapoff -a
SSH
ssh-keygen -t rsa
nano ~/.ssh/authorized_keys
nano /etc/ssh/sshd_config
systemctl restart sshd