How to allow SSH only from local network via iptables [closed]

Solution 1:

Here are the required rules:

# iptables -A INPUT -p tcp --dport 22 -s 192.168.0.0/16 -j ACCEPT
# iptables -A INPUT -p tcp --dport 22 -s 127.0.0.0/8 -j ACCEPT
# iptables -A INPUT -p tcp --dport 22 -j DROP

The first rule allows connection through port 22 (ssh) on protocol tcp to everyone from the 192.168.0.0/16 networks.

The second rule allows connecting to ssh locally.

The third rule drops all other IP's/network coming through port 22.