это как я понял разрешить доступ всем ?
# Accept tcp packets on destination port 22 (SSH)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Это разрешить всем ip 192.168.0.0 - 192.168.0.24 ?
# Accept tcp packets on destination port 22 (SSH) from private LAN
iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 22 -j ACCEPT
Но опять ряд вопросов:
можно ли использовать как то так:
iptables -A INPUT -p tcp -s 192.168.0.1 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -s 193.128.0.2 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -s 194.128.1.6 --dport 22 -j ACCEPT
И если использовать правило
iptables -A INPUT -p tcp -s 192.168.0.1 --dport 22 -j ACCEPT
Зависит от вашей политики по умолчанию.
Выполните iptables -S и посмотрите на цепочку INPUT.
Там будет либо DROP (запрещено всё, что не разрешено явно), либо ACCEPT (разрешено всё, что не запрещено явно).
Now we've seen the basics, we can start combining these rules.
A popular UNIX/Linux service is the secure shell (SSH) service allowing remote logins. By default SSH uses port 22 and again uses the tcp protocol. So if we want to allow remote logins, we would need to allow tcp connections on port 22:
# Accept tcp packets on destination port 22 (SSH)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
This will open up port 22 (SSH) to all incoming tcp connections which poses a potential security threat as hackers could try brute force cracking on accounts with weak passwords. However, if we know the IP addresses of trusted remote machines that will be used to log on using SSH, we can limit access to only these source IP addresses. For example, if we just wanted to open up SSH access on our private lan (192.168.0.x), we can limit access to just this source IP address range:
# Accept tcp packets on destination port 22 (SSH) from private LAN
iptables -A INPUT -p tcp -s 192.168.0.0/24 --dport 22 -j ACCEPT
Using source IP filtering allows us to securely open up SSH access on port 22 to only trusted IP addresses. For example, we could use this method to allow remote logins between work and home machines. To all other IP addresses, the port (and service) would appear closed as if the service were disabled so hackers using port scanning methods are likely to pass us by.