How to allow SSH only from local network via iptables
14,368
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.
Related videos on Youtube
Author by
ECII
Updated on September 18, 2022Comments
-
ECII over 1 year
I would like to configure
iptables
to allow SSH on port 22 only from IPs from192.168.*.*
and block from every other IP. -
Dr. Mike almost 6 yearsGood stuff here! :)