Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
netadmin:linux:ufw:exemples:ufw_ipset [2021/10/19 16:23] – créée yoann | netadmin:linux:ufw:exemples:ufw_ipset [2022/01/08 18:53] (Version actuelle) – Ajout référence yoann | ||
---|---|---|---|
Ligne 22: | Ligne 22: | ||
<code bash> | <code bash> | ||
- | # journaliser | + | # Journalise |
iptables -A ufw-after-output -m set --match-set canon_mfc dst -p tcp --dport 8000 -j ufw-logging-allow | iptables -A ufw-after-output -m set --match-set canon_mfc dst -p tcp --dport 8000 -j ufw-logging-allow | ||
- | # autorise en sortie | + | # Autorise le trafic sortant à destination des machines de l' |
iptables -A ufw-after-output -m set --match-set canon_mfc dst -p tcp --dport 8000 -j ACCEPT | iptables -A ufw-after-output -m set --match-set canon_mfc dst -p tcp --dport 8000 -j ACCEPT | ||
+ | |||
+ | # Journalise le trafic provenant des machines de l' | ||
+ | iptables -A ufw-after-input -i eth0 -m set --match-set set_autorized_hosts src -j ufw-logging-allow | ||
+ | |||
+ | # Autorise le trafic en provenance des machines de l' | ||
+ | iptables -A ufw-after-input -i eth0 -m set --match-set mgmt src -j ACCEPT | ||
</ | </ | ||
Ligne 46: | Ligne 52: | ||
</ | </ | ||
- | <note warning> | + | |
- | Si l' | + | En cas de problème ou une fois le fonctionnement |
- | </ | + | |
<code bash> | <code bash> | ||
- | # modification du groupe | + | ufw reload |
- | ipset add canon_mfc 192.168.0.218 | + | </ |
- | # Le contact du nouvel hote échoue, les traces du journal système | + | ===== Rendre la règle permanente ===== |
- | journalctl | + | |
- | -- Logs begin at Wed 2021-06-16 14:39:52 CEST, end at Tue 2021-10-19 18:15:34 CEST. -- | + | Pour rendre la règle permanente, il faut l' |
- | oct. 19 18:15:26 node-7c87 kernel: [UFW ALLOW] IN= OUT=enp0s31f6 SRC=192.9.200.14 DST=192.9.200.218 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=291 DF PROTO=TCP SPT=60840 DPT=8000 WINDOW=64240 RES=0x00 SYN URGP=0 | + | |
+ | <code bash> | ||
+ | # rendre executable le script before.init s' | ||
+ | chmod +x before.init | ||
+ | |||
+ | # Sauvegarder les ensembles ipset existants: | ||
+ | ipset save > / | ||
+ | </ | ||
+ | |||
+ | Modifier le fichier ''/ | ||
+ | <file bash before.init> | ||
+ | #!/bin/sh | ||
+ | # | ||
+ | # before.init: | ||
+ | # details. Note that output from these scripts is not seen via the | ||
+ | # the ufw command, but instead via ufw-init. | ||
+ | # | ||
+ | # Copyright 2013 Canonical Ltd. | ||
+ | # | ||
+ | # This program is free software: you can redistribute it and/or modify | ||
+ | # it under the terms of the GNU General Public License version 3, | ||
+ | # as published by the Free Software Foundation. | ||
+ | # | ||
+ | # This program is distributed in the hope that it will be useful, | ||
+ | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
+ | # GNU General Public License for more details. | ||
+ | # | ||
+ | # You should have received a copy of the GNU General Public License | ||
+ | # along with this program. | ||
+ | # | ||
+ | set -e | ||
+ | |||
+ | case "$1" | ||
+ | start) | ||
+ | # create ipsets from definition file | ||
+ | ipset restore < / | ||
+ | ;; | ||
+ | stop) | ||
+ | # delete all ipsets | ||
+ | ipset destroy | ||
+ | ;; | ||
+ | status) | ||
+ | # optional | ||
+ | ;; | ||
+ | flush-all) | ||
+ | # optional | ||
+ | ;; | ||
+ | *) | ||
+ | echo "' | ||
+ | echo " | ||
+ | ;; | ||
+ | esac | ||
+ | </ | ||
+ | |||
+ | Pour l' | ||
+ | |||
+ | < | ||
+ | # Journalise et autorise le traffic vers l' | ||
+ | -A ufw-after-output | ||
+ | -A ufw-after-output -m set --match-set canon_mfc dst -p tcp --dport 8000 -j ACCEPT -m comment --comment "Allow Management Canon MFC" | ||
+ | </ | ||
+ | |||
+ | On recharge les règles: | ||
+ | <code bash> | ||
+ | ufw reload | ||
+ | </ | ||
+ | |||
+ | D' | ||
+ | |||
+ | <code bash> | ||
+ | # Ajoute une nouvelle machine au groupe. La règle existante s' | ||
+ | ipset add canon_mfc | ||
</ | </ | ||
<note warning> | <note warning> | ||
- | **A retenir: TOUJOURS recharger les règles après | + | Lors de toute modification d' |
</ | </ | ||
- | ===== Rendre la règle permanente | + | <code bash> |
+ | # root | ||
+ | ipset save > / | ||
+ | |||
+ | # ou depuis un sudoer | ||
+ | sudo ipset save | sudo tee / | ||
+ | </ | ||
+ | |||
+ | |||
+ | Pour afficher les règles évaluées après les règles utilisateur auxquelles notre nouvelle règle a été ajoutée: | ||
+ | |||
+ | <code bash> | ||
+ | ufw show after-rules | ||
+ | </ | ||
+ | |||
+ | ===== Références | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * man ufw-framework | ||