sudo ufw status verbose # View current firewall status and rules sudo ufw status # Check if UFW is enabled
sudo ufw allow 22/tcp # Allow SSH (port 22) from any IP sudo ufw allow from x.x.x.x to any port 22 # Allow SSH from specific IP (replace x.x.x.x with IP)
sudo ufw limit 22/tcp # Limit SSH to default rate (e.g., 6 attempts per 30 seconds)
sudo ufw deny 22/tcp # Deny all incoming SSH requests sudo ufw deny from x.x.x.x to any port 22 # Deny SSH from a specific IP
sudo ufw delete allow 22/tcp # Delete the SSH allow rule sudo ufw delete limit 22/tcp # Delete the SSH limit rule
sudo iptables -L -v -n --line-numbers # List all iptables rules with line numbers sudo iptables -L -v -n | grep dpt:22 # Filter for SSH-specific rules
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSH access from any IP sudo iptables -A INPUT -p tcp -s x.x.x.x --dport 22 -j ACCEPT # Allow SSH from specific IP
sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 11 -j DROP
sudo iptables -A INPUT -p tcp --dport 22 -j DROP # Block SSH access from all IPs sudo iptables -A INPUT -p tcp -s x.x.x.x --dport 22 -j DROP # Block SSH from a specific IP
sudo iptables -L INPUT -v -n --line-numbers # List rules with line numbers for deletion sudo iptables -D INPUT [line_number] # Delete specific rule by line number
sudo netfilter-persistent save # Save iptables rules for persistence on reboot sudo apt-get install iptables-persistent # Install iptables-persistent if not installed