Iptables that only allow incoming traffic to OpenSSH and block all other traffic

I need to configure a firewall using iptables that only allows incoming traffic to the openssh services and block all other traffic. I know how to block all incoming traffic but don't know how to only allow incoming traffic to the openssh and block all other incoming traffic simultaneously. I also need the ssh to be logged as "ssh traffic" and all the other blocked traffic to be logged as "blocked traffic". Any help would be much appreciated.

Thanks guys


The simplest way to do this would be like this:

  1. Open Terminal (if it's not already open)
  2. Block all incoming traffic:
    sudo ufw default deny incoming
    
  3. Allow OpenSSH:
    sudo ufw allow OpenSSH
    

If SSH connections are coming in from a limited subset of IPs, such as an internal network, then you can limit OpenSSH to just the local network like this:

sudo ufw allow from 192.168.0.0/24 to any port 22 proto tcp

Note: Be sure to change 192.168.0.0 to a value applicable to the network.