#1 Le 27/08/2013, à 20:36
- DJiK
Bloquer les accès SSH avec iptables [résolu]
Bonjour,
J'ai un serveur web avec ISPConfig qui a définit des règles dans iptables par défaut. Je voudrais n'autoriser le SSH que pour 2-3 IPs et j'ai fait des recherches et des essais, mais tout ce que j'ai réussi à faire c'est à tout bloquer!
J'ai commencé par ceci, mais ça ne bloque rien:
iptables -A INPUT -p tcp --dport 22 -s XX.XX.XX.XX -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s YY.YY.YY.YY -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j REJECT
Sans doute parce que le REJECT est écrasé par une des autres règles d'origine:
#iptables -L -v
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
336 33004 fail2ban-ssh tcp -- any any anywhere anywhere multiport dports ssh
97 5240 fail2ban-pureftpd tcp -- any any anywhere anywhere multiport dports ftp
112 5844 fail2ban-dovecot-pop3imap tcp -- any any anywhere anywhere multiport dports pop3,pop3s,imap2,imaps
0 0 DROP tcp -- !lo any anywhere loopback/8
315K 120M ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
10185 629K ACCEPT all -- lo any anywhere anywhere
0 0 DROP all -- any any base-address.mcast.net/4 anywhere
27478 2273K PUB_IN all -- eth+ any anywhere anywhere
0 0 PUB_IN all -- ppp+ any anywhere anywhere
0 0 PUB_IN all -- slip+ any anywhere anywhere
0 0 PUB_IN all -- venet+ any anywhere anywhere
0 0 PUB_IN all -- bond+ any anywhere anywhere
0 0 DROP all -- any any anywhere anywhere
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
0 0 DROP all -- any any anywhere anywhere
Chain OUTPUT (policy ACCEPT 48140 packets, 32M bytes)
pkts bytes target prot opt in out source destination
337K 304M PUB_OUT all -- any eth+ anywhere anywhere
0 0 PUB_OUT all -- any ppp+ anywhere anywhere
0 0 PUB_OUT all -- any slip+ anywhere anywhere
0 0 PUB_OUT all -- any venet+ anywhere anywhere
0 0 PUB_OUT all -- any bond+ anywhere anywhere
Chain INT_IN (0 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT icmp -- any any anywhere anywhere
0 0 DROP all -- any any anywhere anywhere
Chain INT_OUT (0 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT icmp -- any any anywhere anywhere
0 0 ACCEPT all -- any any anywhere anywhere
Chain PAROLE (15 references)
pkts bytes target prot opt in out source destination
18747 1041K ACCEPT all -- any any anywhere anywhere
Chain PUB_IN (5 references)
pkts bytes target prot opt in out source destination
45 2628 ACCEPT icmp -- any any anywhere anywhere icmp destination-unreachable
0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-reply
0 0 ACCEPT icmp -- any any anywhere anywhere icmp time-exceeded
9 340 ACCEPT icmp -- any any anywhere anywhere icmp echo-request
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:ftp-data
2 96 PAROLE tcp -- any any anywhere anywhere tcp dpt:ftp
6 820 PAROLE tcp -- any any anywhere anywhere tcp dpt:ssh
28 1504 PAROLE tcp -- any any anywhere anywhere tcp dpt:smtp
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:domain
18426 1022K PAROLE tcp -- any any anywhere anywhere tcp dpt:www
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:pop3
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:imap2
4 240 PAROLE tcp -- any any anywhere anywhere tcp dpt:https
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:imaps
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:pop3s
266 16087 PAROLE tcp -- any any anywhere anywhere tcp dpt:mysql
15 780 PAROLE tcp -- any any anywhere anywhere tcp dpt:http-alt
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:tproxy
0 0 PAROLE tcp -- any any anywhere anywhere tcp dpt:webmin
2 130 ACCEPT udp -- any any anywhere anywhere udp dpt:domain
0 0 ACCEPT udp -- any any anywhere anywhere udp dpt:mysql
0 0 DROP icmp -- any any anywhere anywhere
8675 1229K DROP all -- any any anywhere anywhere
Chain PUB_OUT (5 references)
pkts bytes target prot opt in out source destination
337K 304M ACCEPT all -- any any anywhere anywhere
Chain fail2ban-dovecot-pop3imap (1 references)
pkts bytes target prot opt in out source destination
112 5844 RETURN all -- any any anywhere anywhere
Chain fail2ban-pureftpd (1 references)
pkts bytes target prot opt in out source destination
97 5240 RETURN all -- any any anywhere anywhere
Chain fail2ban-ssh (1 references)
pkts bytes target prot opt in out source destination
336 33004 RETURN all -- any any anywhere anywhere
Mais je ne connais même pas ces chaines PUB_IN, PAROLE, où se trouve SSH. Comment autoriser seulement quelques IP en SSH?
Dernière modification par DJiK (Le 28/08/2013, à 10:43)
Hors ligne
#2 Le 27/08/2013, à 21:15
- classdroogies
Re : Bloquer les accès SSH avec iptables [résolu]
Salut,
Avec les fichiers /etc/hosts.allow et /etc/hosts.deny.
Bloquer l'accès au démon sshd ajouter au /etc/hosts.deny :
sshd: ALL
Autoriser certaines adresses pour sshd, ajouter au /etc/hosts.allow:
sshd: xx.xxx.xx.x xxx.xxx.xx.x
Plus d'infos :
man hosts_access
Dernière modification par classdroogies (Le 28/08/2013, à 18:39)
Hors ligne
#3 Le 28/08/2013, à 10:43
- DJiK
Re : Bloquer les accès SSH avec iptables [résolu]
J'avais lu quelque part que sshd n'était pas concerné par ces fichiers parce qu'il démarrait avant. Mais ce n'est pas le cas, c'est plus simple et ça fonctionne! Merci!
(Je n'ai pas mis la virgule d'après les exemples, c'est juste un espace.)
Dernière modification par DJiK (Le 28/08/2013, à 10:45)
Hors ligne
#4 Le 28/08/2013, à 18:43
- classdroogies
Re : Bloquer les accès SSH avec iptables [résolu]
(Je n'ai pas mis la virgule d'après les exemples, c'est juste un espace.)
Corrigé !
Hors ligne