index.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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">État 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-feu">Le pare-feu</h1>
  179. <p>Il nous faut installer un pare-feu 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 suivant :</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éfinit 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 sont 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 backend (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 autorisé 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
  327. ceph-mon cfengine cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client
  328. etcd-server finger freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps
  329. ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network
  330. llmnr managesieve matrix mdns minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp nut openvpn
  331. ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio
  332. puppetmaster quassel radius redis rpc-bind rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps
  333. snmp snmptrap spideroak-lansync squid ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client
  334. tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local
  335. xmpp-server zabbix-agent zabbix-server
  336. pi@piras:~ $
  337. </code></pre>
  338. <p>Chaque détail des services est détaillé dans un fichier xml dans /usr/lib/firewalld.</p>
  339. <p>Voyons quels services sont actuellement activés sur notre raspi :</p>
  340. <pre><code>pi@piras:~ $ ss -t -u -l -a
  341. Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
  342. udp UNCONN 0 0 0.0.0.0:55853 0.0.0.0:*
  343. udp UNCONN 0 0 127.0.0.1:domain 0.0.0.0:*
  344. udp UNCONN 0 0 0.0.0.0:bootpc 0.0.0.0:*
  345. udp UNCONN 0 0 0.0.0.0:mdns 0.0.0.0:*
  346. udp UNCONN 0 0 [::1]:domain *:*
  347. udp UNCONN 0 0 *:59578 *:*
  348. udp UNCONN 0 0 *:mdns *:*
  349. tcp LISTEN 0 511 127.0.0.1:domain-s 0.0.0.0:*
  350. tcp LISTEN 0 511 127.0.0.1:domain 0.0.0.0:*
  351. tcp LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
  352. tcp ESTAB 0 0 192.168.111.170:ssh 192.168.111.150:59092
  353. tcp LISTEN 0 511 [::1]:domain-s [::]:*
  354. tcp LISTEN 0 511 [::1]:domain [::]:*
  355. tcp LISTEN 0 128 [::]:ssh [::]:*
  356. pi@piras:~ $
  357. </code></pre>
  358. <p>Nous voyons notre connexion <strong>ssh</strong> établie entre ma machine de travail en ip 192.168.111.150 et piras 192.168.111.170.</p>
  359. <p>Notre raspi écoute également le port 22 sur toutes les interfaces présentes.</p>
  360. <p>Liste des ports en écoute (TCP) :</p>
  361. <pre><code>pi@piras:~ $ ss -ltn
  362. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  363. LISTEN 0 511 127.0.0.1:853 0.0.0.0:*
  364. LISTEN 0 511 127.0.0.1:53 0.0.0.0:*
  365. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  366. LISTEN 0 511 [::1]:853 [::]:*
  367. LISTEN 0 511 [::1]:53 [::]:*
  368. LISTEN 0 128 [::]:22 [::]:*
  369. pi@piras:~ $
  370. </code></pre>
  371. <p>Les ports 22 (ssh), 53 (dns), 853 (dns) sont à l'écoute en IPV4 et IPV6.</p>
  372. <p>Liste des ports en écoute (UDP) :</p>
  373. <pre><code>pi@piras:~ $ ss -lun
  374. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  375. UNCONN 0 0 127.0.0.1:53 0.0.0.0:*
  376. UNCONN 0 0 0.0.0.0:68 0.0.0.0:*
  377. UNCONN 0 0 0.0.0.0:5353 0.0.0.0:*
  378. UNCONN 0 0 [::1]:53 *:*
  379. UNCONN 0 0 *:59578 *:*
  380. UNCONN 0 0 *:5353 *:*
  381. pi@piras:~ $
  382. </code></pre>
  383. <h3 id="etat-des-lieux">État des lieux</h3>
  384. <p>Vérifions le fonctionnement de Firewalld. Souvenez-vous qu'il était configuré pour fonctionner avec Iptables.</p>
  385. <p>Vérifions les règles établies :</p>
  386. <pre><code>pi@piras:~ $ sudo iptables -L
  387. Chain INPUT (policy ACCEPT)
  388. target prot opt source destination
  389. ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
  390. ACCEPT all -- anywhere anywhere
  391. INPUT_direct all -- anywhere anywhere
  392. INPUT_ZONES_SOURCE all -- anywhere anywhere
  393. INPUT_ZONES all -- anywhere anywhere
  394. DROP all -- anywhere anywhere ctstate INVALID
  395. REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
  396. Chain FORWARD (policy ACCEPT)
  397. target prot opt source destination
  398. ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
  399. ACCEPT all -- anywhere anywhere
  400. FORWARD_direct all -- anywhere anywhere
  401. FORWARD_IN_ZONES_SOURCE all -- anywhere anywhere
  402. FORWARD_IN_ZONES all -- anywhere anywhere
  403. FORWARD_OUT_ZONES_SOURCE all -- anywhere anywhere
  404. FORWARD_OUT_ZONES all -- anywhere anywhere
  405. DROP all -- anywhere anywhere ctstate INVALID
  406. REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
  407. Chain OUTPUT (policy ACCEPT)
  408. target prot opt source destination
  409. OUTPUT_direct all -- anywhere anywhere
  410. Chain INPUT_direct (1 references)
  411. target prot opt source destination
  412. Chain INPUT_ZONES_SOURCE (1 references)
  413. target prot opt source destination
  414. Chain INPUT_ZONES (1 references)
  415. target prot opt source destination
  416. IN_public all -- anywhere anywhere [goto]
  417. IN_public all -- anywhere anywhere [goto]
  418. Chain FORWARD_direct (1 references)
  419. target prot opt source destination
  420. Chain FORWARD_IN_ZONES_SOURCE (1 references)
  421. target prot opt source destination
  422. Chain FORWARD_IN_ZONES (1 references)
  423. target prot opt source destination
  424. FWDI_public all -- anywhere anywhere [goto]
  425. FWDI_public all -- anywhere anywhere [goto]
  426. Chain FORWARD_OUT_ZONES_SOURCE (1 references)
  427. target prot opt source destination
  428. Chain FORWARD_OUT_ZONES (1 references)
  429. target prot opt source destination
  430. FWDO_public all -- anywhere anywhere [goto]
  431. FWDO_public all -- anywhere anywhere [goto]
  432. Chain OUTPUT_direct (1 references)
  433. target prot opt source destination
  434. Chain IN_public (2 references)
  435. target prot opt source destination
  436. IN_public_log all -- anywhere anywhere
  437. IN_public_deny all -- anywhere anywhere
  438. IN_public_allow all -- anywhere anywhere
  439. ACCEPT icmp -- anywhere anywhere
  440. Chain IN_public_log (1 references)
  441. target prot opt source destination
  442. Chain IN_public_deny (1 references)
  443. target prot opt source destination
  444. Chain IN_public_allow (1 references)
  445. target prot opt source destination
  446. ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW,UNTRACKED
  447. Chain FWDI_public (2 references)
  448. target prot opt source destination
  449. FWDI_public_log all -- anywhere anywhere
  450. FWDI_public_deny all -- anywhere anywhere
  451. FWDI_public_allow all -- anywhere anywhere
  452. ACCEPT icmp -- anywhere anywhere
  453. Chain FWDI_public_log (1 references)
  454. target prot opt source destination
  455. Chain FWDI_public_deny (1 references)
  456. target prot opt source destination
  457. Chain FWDI_public_allow (1 references)
  458. target prot opt source destination
  459. Chain FWDO_public (2 references)
  460. target prot opt source destination
  461. FWDO_public_log all -- anywhere anywhere
  462. FWDO_public_deny all -- anywhere anywhere
  463. FWDO_public_allow all -- anywhere anywhere
  464. Chain FWDO_public_log (1 references)
  465. target prot opt source destination
  466. Chain FWDO_public_deny (1 references)
  467. target prot opt source destination
  468. Chain FWDO_public_allow (1 references)
  469. target prot opt source destination
  470. pi@piras:~ $
  471. </code></pre>
  472. <p>Les règles Iptables ont bien été configurées par Firewalld.</p>
  473. <p>Après reboot, nous voyons que rien n'a été conservé !</p>
  474. <p>Il va falloir investiguer ...</p>
  475. <p>Bien : voilà la procédure à suivre :</p>
  476. <p>sudo firewall-cmd <strong>--permanent</strong> --zone=public --change-interface=eth0</p>
  477. <p>Permet de changer de façon <strong>permanente</strong> l'interface associée à la zone <strong>public</strong>.</p>
  478. <pre><code>Test :
  479. pi@piras:~ $ sudo firewall-cmd --permanent --zone=public --change-interface=eth0
  480. success
  481. pi@piras:~ $ sudo cat /etc/firewalld/zones/public.xml
  482. &lt;?xml version="1.0" encoding="utf-8"?&gt;
  483. &lt;zone&gt;
  484. &lt;short&gt;Public&lt;/short&gt;
  485. &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;
  486. &lt;interface name="eth0"/&gt;
  487. &lt;service name="ssh"/&gt;
  488. &lt;service name="dhcpv6-client"/&gt;
  489. &lt;/zone&gt;
  490. pi@piras:~ $
  491. 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é.
  492. pi@piras:~ $ sudo firewall-cmd --list-all
  493. public (active)
  494. target: default
  495. icmp-block-inversion: no
  496. interfaces: eth0
  497. sources:
  498. services: dhcpv6-client ssh
  499. ports:
  500. protocols:
  501. masquerade: no
  502. forward-ports:
  503. source-ports:
  504. icmp-blocks:
  505. rich rules:
  506. pi@piras:~ $
  507. </code></pre>
  508. <p>Test après redémarrage :</p>
  509. <p>Cette fois-ci, ça marche ! (Yes !)</p>
  510. <pre><code>pi@piras:~ $ sudo firewall-cmd --list-all
  511. public (active)
  512. target: default
  513. icmp-block-inversion: no
  514. interfaces: eth0
  515. sources:
  516. services: dhcpv6-client ssh
  517. ports:
  518. protocols:
  519. masquerade: no
  520. forward-ports:
  521. source-ports:
  522. icmp-blocks:
  523. rich rules:
  524. pi@piras:~ $
  525. </code></pre>
  526. <p>Nous verrons ensuite comment ajouter des règles suivant les services que nous voudrons déployer.</p>
  527. </div>
  528. </div>
  529. <footer>
  530. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  531. <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>
  532. <a href="../Knot/" class="btn btn-neutral" title="Installation de Knot-resolver"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  533. </div>
  534. <hr/>
  535. <div role="contentinfo">
  536. <!-- Copyright etc -->
  537. </div>
  538. 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>.
  539. </footer>
  540. </div>
  541. </div>
  542. </section>
  543. </div>
  544. <div class="rst-versions" role="note" aria-label="versions">
  545. <span class="rst-current-version" data-toggle="rst-current-version">
  546. <span><a href="../Knot/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  547. <span style="margin-left: 15px"><a href="../Fail2ban/" style="color: #fcfcfc">Next &raquo;</a></span>
  548. </span>
  549. </div>
  550. <script>var base_url = '../../..';</script>
  551. <script src="../../../js/theme.js" defer></script>
  552. <script src="../../../search/main.js" defer></script>
  553. <script defer>
  554. window.onload = function () {
  555. SphinxRtdTheme.Navigation.enable(true);
  556. };
  557. </script>
  558. </body>
  559. </html>