index.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <link rel="shortcut icon" href="../../../img/favicon.ico">
  9. <title>Installation d'un pare-feux - Les Tutoriels du Yojik</title>
  10. <link rel="stylesheet" href="../../../css/theme.css" />
  11. <link rel="stylesheet" href="../../../css/theme_extra.css" />
  12. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  13. <script>
  14. // Current page data
  15. var mkdocs_page_name = "Installation d'un pare-feux";
  16. var mkdocs_page_input_path = "Tutoriels/tutoraspi/Firewall.md";
  17. var mkdocs_page_url = null;
  18. </script>
  19. <script src="../../../js/jquery-2.1.1.min.js" defer></script>
  20. <script src="../../../js/modernizr-2.8.3.min.js" defer></script>
  21. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  22. <script>hljs.initHighlightingOnLoad();</script>
  23. </head>
  24. <body class="wy-body-for-nav" role="document">
  25. <div class="wy-grid-for-nav">
  26. <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
  27. <div class="wy-side-scroll">
  28. <div class="wy-side-nav-search">
  29. <a href="../../.." class="icon icon-home"> Les Tutoriels du Yojik</a>
  30. <div role="search">
  31. <form id ="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <p class="caption"><span class="caption-text">Home</span></p>
  38. <ul>
  39. <li class="toctree-l1"><a class="reference internal" href="../../..">Page d'accueil</a>
  40. </li>
  41. </ul>
  42. <p class="caption"><span class="caption-text">Tutoriels</span></p>
  43. <ul class="current">
  44. <li class="toctree-l1"><a class="reference internal" href="../../tutos/">Introduction</a>
  45. </li>
  46. <li class="toctree-l1"><a class="reference internal" href="#">Installation d'un serveur sécurisé, version Debian/Stretch (obsolète)</a>
  47. <ul>
  48. <li class="toctree-l2"><a class="reference internal" href="../../tutostretch/tutostretch/">Présentation</a>
  49. </li>
  50. <li class="toctree-l2"><a class="reference internal" href="#">Installation</a>
  51. <ul>
  52. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-de-base/">Installation du système de base</a>
  53. </li>
  54. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/ovh/">Démarrage sur serveur OVH</a>
  55. </li>
  56. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Premi%C3%A8re-Etape-S%C3%A9curisation/">Première étapes de sécurisation du serveur</a>
  57. </li>
  58. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Configuration-R%C3%A9seau/">Configuration du réseau</a>
  59. </li>
  60. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Temps/">Installation d'un serveur de temps</a>
  61. </li>
  62. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Parre-Feu/">Installation d'un pare-feu</a>
  63. </li>
  64. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Fail2ban/">Contrer les attaques de brute-force avec fail2ban</a>
  65. </li>
  66. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Courrier-Basique/">Installation d'un serveur de courrier basique</a>
  67. </li>
  68. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-DNS/">Installation du serveur DNS</a>
  69. </li>
  70. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Serveur-Web/">Installation d'un serveur web</a>
  71. </li>
  72. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Dovecot-Authentification/">Installation de dovecot et de l'authentification</a>
  73. </li>
  74. <li class="toctree-l3"><a class="" href="../../tutostretch/Installation-Certificats-Letsencrypt.md)">Installation des certificats letsencrypt</a>
  75. </li>
  76. <li class="toctree-l3"><a class="" href="../../tutostretch/courrier-SPF-DKIM-OPENDMARC.md">Ajout des enregistrements **spf**, **DKIM**, **DMARC** au fichier de zone DNS</a>
  77. </li>
  78. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Courrier-Comptes-Virtuels/">Ajout des comptes émail virtuels</a>
  79. </li>
  80. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Surveillance-Serveur/">Installation de programmes de surveillance du serveur</a>
  81. </li>
  82. <li class="toctree-l3"><a class="reference internal" href="../../tutostretch/Installation-Webmail/">Installation d'un webmail (rainloop)</a>
  83. </li>
  84. <li class="toctree-l3"><a class="" href="../../tutostretch/Sécurisation-Serveur-Web">Sécurisation d'un serveur WEB</a>
  85. </li>
  86. </ul>
  87. </li>
  88. </ul>
  89. </li>
  90. <li class="toctree-l1"><a class="reference internal" href="#">Installation d'un serveur sécurisé, version Debian/Buster (en cours d'écriture)</a>
  91. <ul>
  92. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/1-tutobuster/">Présentation</a>
  93. </li>
  94. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/2-Installation-de-base/">Installation de base</a>
  95. </li>
  96. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/3-ovh/">Démarrage sur serveur OVH</a>
  97. </li>
  98. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/4-Plan/">Plan d'ensemble</a>
  99. </li>
  100. <li class="toctree-l2"><a class="reference internal" href="../../tutobuster/5-Premi%C3%A8re-Etape-S%C3%A9curisation/">Premières étapes de sécurisation du serveur</a>
  101. </li>
  102. </ul>
  103. </li>
  104. <li class="toctree-l1 current"><a class="reference internal current" href="#">Installation d'un serveur sécurisé, version Debian/Buster sur RaspberryPI</a>
  105. <ul class="current">
  106. <li class="toctree-l2"><a class="reference internal" href="../tutoraspi/">Présentation</a>
  107. </li>
  108. <li class="toctree-l2"><a class="reference internal" href="../Installation-de-base/">Installation de base</a>
  109. </li>
  110. <li class="toctree-l2"><a class="reference internal" href="../Premier-d%C3%A9marrage/">Premier démarrage</a>
  111. </li>
  112. <li class="toctree-l2"><a class="reference internal" href="../Etat-des-lieux/">État des lieux</a>
  113. </li>
  114. <li class="toctree-l2"><a class="reference internal" href="../S%C3%A9curisation-SSH/">Sécurisation SSH</a>
  115. </li>
  116. <li class="toctree-l2"><a class="reference internal" href="../R%C3%A9seau/">Réseau (des IPs fixes)</a>
  117. </li>
  118. <li class="toctree-l2"><a class="reference internal" href="../Knot/">Installation de Knot-resolver</a>
  119. </li>
  120. <li class="toctree-l2 current"><a class="reference internal current" href="./">Installation d'un pare-feux</a>
  121. <ul class="current">
  122. <li class="toctree-l3"><a class="reference internal" href="#installation-de-iptables">Installation de IPtables</a>
  123. </li>
  124. <li class="toctree-l3"><a class="reference internal" href="#test">Test</a>
  125. <ul>
  126. <li class="toctree-l4"><a class="reference internal" href="#la-notion-de-zones">La notion de zones</a>
  127. </li>
  128. <li class="toctree-l4"><a class="reference internal" href="#les-differentes-zones">Les différentes zones</a>
  129. </li>
  130. <li class="toctree-l4"><a class="reference internal" href="#les-fichiers-de-configuration">Les fichiers de configuration</a>
  131. </li>
  132. <li class="toctree-l4"><a class="reference internal" href="#quelques-commandes">Quelques commandes</a>
  133. </li>
  134. <li class="toctree-l4"><a class="reference internal" href="#premiere-etape-de-configuration">Première étape de configuration</a>
  135. </li>
  136. <li class="toctree-l4"><a class="reference internal" href="#les-services">Les services</a>
  137. </li>
  138. <li class="toctree-l4"><a class="reference internal" href="#etat-des-lieux">Etat des lieux</a>
  139. </li>
  140. </ul>
  141. </li>
  142. </ul>
  143. </li>
  144. <li class="toctree-l2"><a class="reference internal" href="../Fail2ban/">Contrer les attaques de force brute</a>
  145. </li>
  146. <li class="toctree-l2"><a class="reference internal" href="../Logwatch/">Surveillance du serveur</a>
  147. </li>
  148. <li class="toctree-l2"><a class="reference internal" href="../Installation-courrier-basique/">Installation d'un serveur de courriers basique</a>
  149. </li>
  150. <li class="toctree-l2"><a class="reference internal" href="../Annexe/">Annexe</a>
  151. </li>
  152. </ul>
  153. </li>
  154. </ul>
  155. </div>
  156. </div>
  157. </nav>
  158. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  159. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  160. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  161. <a href="../../..">Les Tutoriels du Yojik</a>
  162. </nav>
  163. <div class="wy-nav-content">
  164. <div class="rst-content">
  165. <div role="navigation" aria-label="breadcrumbs navigation">
  166. <ul class="wy-breadcrumbs">
  167. <li><a href="../../..">Docs</a> &raquo;</li>
  168. <li>Installation d'un serveur sécurisé, version Debian/Buster sur RaspberryPI &raquo;</li>
  169. <li>Tutoriels &raquo;</li>
  170. <li>Installation d'un pare-feux</li>
  171. <li class="wy-breadcrumbs-aside">
  172. </li>
  173. </ul>
  174. <hr/>
  175. </div>
  176. <div role="main">
  177. <div class="section">
  178. <h1 id="le-pare-feux">Le pare-feux</h1>
  179. <p>Il nous faut installer un pare-feux sur notre raspi pour éviter les intrusions.</p>
  180. <p>Nous allons limiter les machines susceptibles de se connecter à celles de notre réseau local, et également limiter les ports accessibles sur notre réseau.</p>
  181. <p>Nous allons utiliser IPtables et Firewalld.</p>
  182. <p>J'aurai préféré utiliser <strong>nftables</strong> qui est le successeur de <strong>iptables</strong>, mais j'ai eu quelques soucis à l'utilisation. Peut-être est-ce pour ça que la distribution RaspiOS a configuré <strong>firewalld</strong> avec <strong>IPtables</strong>...</p>
  183. <h2 id="installation-de-iptables">Installation de IPtables</h2>
  184. <p>IPtables est installé par défaut: rien à faire ici.</p>
  185. <h2 id="test">Test</h2>
  186. <p>Si on tape: </p>
  187. <pre><code>pi@raspberrypi:~ $ sudo iptables -L
  188. Chain INPUT (policy ACCEPT)
  189. target prot opt source destination
  190. Chain FORWARD (policy ACCEPT)
  191. target prot opt source destination
  192. Chain OUTPUT (policy ACCEPT)
  193. target prot opt source destination
  194. pi@raspberrypi:~ $
  195. </code></pre>
  196. <p>On voit que c'est iptables qui a été chosi par RaspiOS.</p>
  197. <p>D'abord, il faut comprendre comment fonctionne Firewalld. Je me suis basé sur les sites suivants:</p>
  198. <ul>
  199. <li><a href="https://lwn.net/Articles/484506/">lw.net</a></li>
  200. <li><a href="https://www.certdepot.net/rhel7-get-started-firewalld/">How to get started with Firewalld</a></li>
  201. <li><a href="https://www.tutorialspoint.com/network_security/network_security_firewalls.htm">tutorial points</a></li>
  202. <li><a href="https://firewalld.org/documentation/zone/predefined-zones.html">la documentation officielle</a></li>
  203. <li><a href="https://linuxconfig.org/introduction-to-firewalld-and-firewall-cmd-command-on-linux">introduction-to-firewalld</a></li>
  204. <li><a href="https://doc.fedora-fr.org/wiki/Parefeu_-_firewall_-_FirewallD">La documentation de Fedora</a></li>
  205. <li><a href="https://www.it-connect.fr/centos-7-utilisation-et-configuration-de-firewalld/">it connect</a></li>
  206. </ul>
  207. <p>La documentation de Fedora est la plus compréhensible.</p>
  208. <h3 id="la-notion-de-zones">La notion de zones</h3>
  209. <p>Firewalld défnit 9 zones qui sont en fait des règles de pare-feux par défaut. Une zone va par exemple bloquer toute entrée sauf SSH, une autre permettre l'accès en HTTP et HTTPS. Ces zones correspondent à des utilisations types, comme un serveur dans une DMZ, ou un serveur <strong>chez soi</strong>, un serveur public etc.</p>
  210. <p>On peut imaginer une zone <strong>émail</strong> qui ne laisserait passer que les ports spécifiques à l'émail et DNS bien sûr.</p>
  211. <p>Il est possible de créer des zones personnelles.</p>
  212. <p>Un certain nombre de zones sont prédéfinies. Voyons leur contenu.</p>
  213. <h3 id="les-differentes-zones">Les différentes zones</h3>
  214. <p>Les différentes zones sont:</p>
  215. <ul>
  216. <li>trusted: non modifiable</li>
  217. <li>home: modifiable</li>
  218. <li>work: modifiable</li>
  219. <li>internal: modifiable</li>
  220. <li>dmz: modifiable</li>
  221. <li>public: modifiable</li>
  222. <li>external: modifiable</li>
  223. <li>block: non modifiable</li>
  224. <li>drop: non modifiable</li>
  225. </ul>
  226. <p>Une très bonne présentation des zones est ici: <a href="https://www.it-connect.fr/centos-7-utilisation-et-configuration-de-firewalld/">it connect</a></p>
  227. <h3 id="les-fichiers-de-configuration">Les fichiers de configuration</h3>
  228. <p>Ils ont situés à 2 endroits:</p>
  229. <ul>
  230. <li>/usr/lib/firewalld/ : il ne faut pas toucher au contenu de ce répertoire</li>
  231. <li>/etc/firewalld/: c'est là que nous mettrons notre configuration, en copiant les fichiers de /usr/lib/firewalld si besoin est.</li>
  232. </ul>
  233. <p>Dans le répertoire /etc/firewalld, le fichier firewalld.conf permet de configurer la zone par défaut, ainsi que le backtend (iptables, nftables et autre).</p>
  234. <p>La zone par défaut est <strong>public</strong>: pas de confiance, mais possibilité d'ajuster au cas par cas les règles. Le seul accès auorisé est l'accès <strong>ssh</strong> et <strong>dhcp</strong>.</p>
  235. <h3 id="quelques-commandes">Quelques commandes</h3>
  236. <ul>
  237. <li>Démarrer Firewalld:<strong>$ sudo systemctl start firewalld</strong></li>
  238. <li>Stopper Fireawalld:<strong>$ sudo systemctl stop firewalld</strong></li>
  239. <li>Tester le fonctionnement de Firewalld:<strong>$ sudo firewall-cmd --state</strong></li>
  240. <li>Connaître les zones prédéfinies: <strong>$ sudo firewall-cmd --get-zones</strong></li>
  241. <li>Connaître la zone par défaut:<strong>$ sudo firewall-cmd --get-default-zone</strong></li>
  242. <li>Connaître la zone active:<strong>$ sudo firewall-cmd --get-active-zones</strong></li>
  243. </ul>
  244. <p>Exemples:</p>
  245. <pre><code>pi@piras:~ $ sudo firewall-cmd --state
  246. running
  247. pi@piras:~ $
  248. </code></pre>
  249. <p>Le service tourne.</p>
  250. <pre><code>pi@piras:~ $ sudo firewall-cmd --get-default-zone
  251. public
  252. pi@piras:~ $
  253. </code></pre>
  254. <p>La zone par défaut est: public</p>
  255. <pre><code>pi@piras:~ $ sudo firewall-cmd --get-zones
  256. block dmz drop external home internal public trusted work
  257. pi@piras:~ $
  258. </code></pre>
  259. <p>Les zones prédéfinies sont: <strong>block dmz drop external home internal public trusted work</strong></p>
  260. <p>Quelle est la zone active: aucune!</p>
  261. <pre><code>pi@piras:~ $ sudo firewall-cmd --get-active-zones
  262. pi@piras:~ $
  263. </code></pre>
  264. <p>Nous pouvons vérifier la zone en fonctionnement et l'interface réseau qui y est attachée:</p>
  265. <pre><code>pi@piras:~ $ sudo firewall-cmd --list-all
  266. public
  267. target: default
  268. icmp-block-inversion: no
  269. interfaces:
  270. sources:
  271. services: dhcpv6-client ssh
  272. ports:
  273. protocols:
  274. masquerade: no
  275. forward-ports:
  276. source-ports:
  277. icmp-blocks:
  278. rich rules:
  279. pi@piras:~ $
  280. </code></pre>
  281. <p>Aucune interface n'est attachée. Les seuls services autorisé sont: dhcp et ssh.</p>
  282. <h3 id="premiere-etape-de-configuration">Première étape de configuration</h3>
  283. <p>Nous allons utiliser les commandes en ligne de commande pour configurer Firewalld, mais il existe une GUI pour le faire graphiquement. Référez-vous aux liens que j'ai indiqués au-dessus.</p>
  284. <ul>
  285. <li>
  286. <p>Définition de la zone par défaut: (public)</p>
  287. <pre><code>pi@piras:~ $ sudo firewall-cmd --set-default-zone=public
  288. Warning: ZONE_ALREADY_SET: public
  289. success
  290. pi@piras:~ $
  291. </code></pre>
  292. </li>
  293. <li>
  294. <p>Attribution de l'interface réseau à cette zone:</p>
  295. <pre><code>pi@piras:~ $ sudo firewall-cmd --zone=public --change-interface=eth0
  296. success
  297. pi@piras:~ $
  298. </code></pre>
  299. <p>Attention, ce changement n'est pas permanent! (voir ci-dessous)</p>
  300. </li>
  301. <li>
  302. <p>Test:</p>
  303. <pre><code>pi@piras:~ $ sudo firewall-cmd --list-all
  304. public (active)
  305. target: default
  306. icmp-block-inversion: no
  307. interfaces: eth0
  308. sources:
  309. services: dhcpv6-client ssh
  310. ports:
  311. protocols:
  312. masquerade: no
  313. forward-ports:
  314. source-ports:
  315. icmp-blocks:
  316. rich rules:
  317. pi@piras:~ $
  318. </code></pre>
  319. </li>
  320. </ul>
  321. <p>Nous voyons que l'interface <strong>eth0</strong> a bien été attribuée à la zone <strong>public</strong>.</p>
  322. <h3 id="les-services">Les services</h3>
  323. <p>Il est possible de configurer les services accessibles (ou pas) attribués à la zone active.</p>
  324. <p>Pour connaître les différents services disponibles, tapez la commande suivante:</p>
  325. <pre><code>pi@piras:~ $ sudo firewall-cmd --get-services
  326. RH-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
  327. pi@piras:~ $
  328. </code></pre>
  329. <p>Chaque détail des services est détaillé dans un fichier xml dans /usr/lib/firewalld.</p>
  330. <p>Voyons quels services sont acuellement activés sur notre raspi:</p>
  331. <pre><code>pi@piras:~ $ ss -t -u -l -a
  332. Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
  333. udp UNCONN 0 0 0.0.0.0:55853 0.0.0.0:*
  334. udp UNCONN 0 0 127.0.0.1:domain 0.0.0.0:*
  335. udp UNCONN 0 0 0.0.0.0:bootpc 0.0.0.0:*
  336. udp UNCONN 0 0 0.0.0.0:mdns 0.0.0.0:*
  337. udp UNCONN 0 0 [::1]:domain *:*
  338. udp UNCONN 0 0 *:59578 *:*
  339. udp UNCONN 0 0 *:mdns *:*
  340. tcp LISTEN 0 511 127.0.0.1:domain-s 0.0.0.0:*
  341. tcp LISTEN 0 511 127.0.0.1:domain 0.0.0.0:*
  342. tcp LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
  343. tcp ESTAB 0 0 192.168.111.170:ssh 192.168.111.150:59092
  344. tcp LISTEN 0 511 [::1]:domain-s [::]:*
  345. tcp LISTEN 0 511 [::1]:domain [::]:*
  346. tcp LISTEN 0 128 [::]:ssh [::]:*
  347. pi@piras:~ $
  348. </code></pre>
  349. <p>Nous voyons notre connexion <strong>ssh</strong> établie entre mon desktop en ip 192.168.111.150 et piras 192.168.111.170.</p>
  350. <p>Notre raspi écoute également le port 22 sur toutes les interfaces présentes.</p>
  351. <p>Liste des ports en écoute (TCP):</p>
  352. <pre><code>pi@piras:~ $ ss -ltn
  353. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  354. LISTEN 0 511 127.0.0.1:853 0.0.0.0:*
  355. LISTEN 0 511 127.0.0.1:53 0.0.0.0:*
  356. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  357. LISTEN 0 511 [::1]:853 [::]:*
  358. LISTEN 0 511 [::1]:53 [::]:*
  359. LISTEN 0 128 [::]:22 [::]:*
  360. pi@piras:~ $
  361. </code></pre>
  362. <p>les ports 22 (ssh) , 53 (dns) , 853 (dns) sont à l'écoute en IPV4 et IPV6.</p>
  363. <p>Liste des ports en écoute (UDP):</p>
  364. <pre><code>pi@piras:~ $ ss -lun
  365. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  366. UNCONN 0 0 0.0.0.0:55853 0.0.0.0:*
  367. UNCONN 0 0 127.0.0.1:53 0.0.0.0:*
  368. UNCONN 0 0 0.0.0.0:68 0.0.0.0:*
  369. UNCONN 0 0 0.0.0.0:5353 0.0.0.0:*
  370. UNCONN 0 0 [::1]:53 *:*
  371. UNCONN 0 0 *:59578 *:*
  372. UNCONN 0 0 *:5353 *:*
  373. pi@piras:~ $
  374. </code></pre>
  375. <h3 id="etat-des-lieux">Etat des lieux</h3>
  376. <p>Vérifions le fonctionnement de Firewalld. Souvenez-vous qu'il était configuré pour fonctionner avec Iptables.</p>
  377. <p>Vérifions les règles établies:</p>
  378. <pre><code>pi@piras:~ $ sudo iptables -L
  379. Chain INPUT (policy ACCEPT)
  380. target prot opt source destination
  381. ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
  382. ACCEPT all -- anywhere anywhere
  383. INPUT_direct all -- anywhere anywhere
  384. INPUT_ZONES_SOURCE all -- anywhere anywhere
  385. INPUT_ZONES all -- anywhere anywhere
  386. DROP all -- anywhere anywhere ctstate INVALID
  387. REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
  388. Chain FORWARD (policy ACCEPT)
  389. target prot opt source destination
  390. ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
  391. ACCEPT all -- anywhere anywhere
  392. FORWARD_direct all -- anywhere anywhere
  393. FORWARD_IN_ZONES_SOURCE all -- anywhere anywhere
  394. FORWARD_IN_ZONES all -- anywhere anywhere
  395. FORWARD_OUT_ZONES_SOURCE all -- anywhere anywhere
  396. FORWARD_OUT_ZONES all -- anywhere anywhere
  397. DROP all -- anywhere anywhere ctstate INVALID
  398. REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
  399. Chain OUTPUT (policy ACCEPT)
  400. target prot opt source destination
  401. OUTPUT_direct all -- anywhere anywhere
  402. Chain INPUT_direct (1 references)
  403. target prot opt source destination
  404. Chain INPUT_ZONES_SOURCE (1 references)
  405. target prot opt source destination
  406. Chain INPUT_ZONES (1 references)
  407. target prot opt source destination
  408. IN_public all -- anywhere anywhere [goto]
  409. IN_public all -- anywhere anywhere [goto]
  410. Chain FORWARD_direct (1 references)
  411. target prot opt source destination
  412. Chain FORWARD_IN_ZONES_SOURCE (1 references)
  413. target prot opt source destination
  414. Chain FORWARD_IN_ZONES (1 references)
  415. target prot opt source destination
  416. FWDI_public all -- anywhere anywhere [goto]
  417. FWDI_public all -- anywhere anywhere [goto]
  418. Chain FORWARD_OUT_ZONES_SOURCE (1 references)
  419. target prot opt source destination
  420. Chain FORWARD_OUT_ZONES (1 references)
  421. target prot opt source destination
  422. FWDO_public all -- anywhere anywhere [goto]
  423. FWDO_public all -- anywhere anywhere [goto]
  424. Chain OUTPUT_direct (1 references)
  425. target prot opt source destination
  426. Chain IN_public (2 references)
  427. target prot opt source destination
  428. IN_public_log all -- anywhere anywhere
  429. IN_public_deny all -- anywhere anywhere
  430. IN_public_allow all -- anywhere anywhere
  431. ACCEPT icmp -- anywhere anywhere
  432. Chain IN_public_log (1 references)
  433. target prot opt source destination
  434. Chain IN_public_deny (1 references)
  435. target prot opt source destination
  436. Chain IN_public_allow (1 references)
  437. target prot opt source destination
  438. ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW,UNTRACKED
  439. Chain FWDI_public (2 references)
  440. target prot opt source destination
  441. FWDI_public_log all -- anywhere anywhere
  442. FWDI_public_deny all -- anywhere anywhere
  443. FWDI_public_allow all -- anywhere anywhere
  444. ACCEPT icmp -- anywhere anywhere
  445. Chain FWDI_public_log (1 references)
  446. target prot opt source destination
  447. Chain FWDI_public_deny (1 references)
  448. target prot opt source destination
  449. Chain FWDI_public_allow (1 references)
  450. target prot opt source destination
  451. Chain FWDO_public (2 references)
  452. target prot opt source destination
  453. FWDO_public_log all -- anywhere anywhere
  454. FWDO_public_deny all -- anywhere anywhere
  455. FWDO_public_allow all -- anywhere anywhere
  456. Chain FWDO_public_log (1 references)
  457. target prot opt source destination
  458. Chain FWDO_public_deny (1 references)
  459. target prot opt source destination
  460. Chain FWDO_public_allow (1 references)
  461. target prot opt source destination
  462. pi@piras:~ $
  463. </code></pre>
  464. <p>Les règles Iptables ont bien été configurées par Firewalld.</p>
  465. <p>Après reboot, nous voyons que rien n'a été conservé!</p>
  466. <p>Il va falloir investiguer ...</p>
  467. <p>Bien: voilà la procédure à suivre:</p>
  468. <p>sudo firewall-cmd <strong>--permanent</strong> --zone=public --change-interface=eth0</p>
  469. <p>Permet de changer de façon <strong>permanente</strong> l'interface associée à la zone <strong>public</strong>.</p>
  470. <pre><code>Test:
  471. pi@piras:~ $ sudo firewall-cmd --permanent --zone=public --change-interface=eth0
  472. success
  473. pi@piras:~ $ sudo cat /etc/firewalld/zones/public.xml
  474. &lt;?xml version="1.0" encoding="utf-8"?&gt;
  475. &lt;zone&gt;
  476. &lt;short&gt;Public&lt;/short&gt;
  477. &lt;description&gt;For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.&lt;/description&gt;
  478. &lt;interface name="eth0"/&gt;
  479. &lt;service name="ssh"/&gt;
  480. &lt;service name="dhcpv6-client"/&gt;
  481. &lt;/zone&gt;
  482. pi@piras:~ $
  483. Nous voyons que firewalld a créé des répertoires et un fichier dans le répertoire **zones** dont le contenu correspond à ce que nous avons demandé.
  484. pi@piras:~ $ sudo firewall-cmd --list-all
  485. public (active)
  486. target: default
  487. icmp-block-inversion: no
  488. interfaces: eth0
  489. sources:
  490. services: dhcpv6-client ssh
  491. ports:
  492. protocols:
  493. masquerade: no
  494. forward-ports:
  495. source-ports:
  496. icmp-blocks:
  497. rich rules:
  498. pi@piras:~ $
  499. </code></pre>
  500. <p>Test après reboot</p>
  501. <p>Cette fois-ci, ça marche! (Yes!)</p>
  502. <pre><code>pi@piras:~ $ sudo firewall-cmd --list-all
  503. public (active)
  504. target: default
  505. icmp-block-inversion: no
  506. interfaces: eth0
  507. sources:
  508. services: dhcpv6-client ssh
  509. ports:
  510. protocols:
  511. masquerade: no
  512. forward-ports:
  513. source-ports:
  514. icmp-blocks:
  515. rich rules:
  516. pi@piras:~ $
  517. </code></pre>
  518. <p>Nous verrons ensuite comment ajouter des règles suivant les services que nous voudrons déployer.</p>
  519. </div>
  520. </div>
  521. <footer>
  522. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  523. <a href="../Fail2ban/" class="btn btn-neutral float-right" title="Contrer les attaques de force brute">Next <span class="icon icon-circle-arrow-right"></span></a>
  524. <a href="../Knot/" class="btn btn-neutral" title="Installation de Knot-resolver"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  525. </div>
  526. <hr/>
  527. <div role="contentinfo">
  528. <!-- Copyright etc -->
  529. </div>
  530. Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  531. </footer>
  532. </div>
  533. </div>
  534. </section>
  535. </div>
  536. <div class="rst-versions" role="note" aria-label="versions">
  537. <span class="rst-current-version" data-toggle="rst-current-version">
  538. <span><a href="../Knot/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  539. <span style="margin-left: 15px"><a href="../Fail2ban/" style="color: #fcfcfc">Next &raquo;</a></span>
  540. </span>
  541. </div>
  542. <script>var base_url = '../../..';</script>
  543. <script src="../../../js/theme.js" defer></script>
  544. <script src="../../../search/main.js" defer></script>
  545. <script defer>
  546. window.onload = function () {
  547. SphinxRtdTheme.Navigation.enable(true);
  548. };
  549. </script>
  550. </body>
  551. </html>