[Résolu]Point d'accès Wifi !

Photographie ultra-rapide, pilotage d'imprimante 3D ou de CNC, fabrication de bière.... Enfin tout ce que le Raspberry peut gérer trouvera sa place dans cette rubrique

Modérateur : Francois

Répondre
Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

[Résolu]Point d'accès Wifi !

Message par Artemus24 » sam. 14 juil. 2018 17:48

Salut à tous.

J'ai voulu suivre le didacticiel suivant :
--> https://www.raspberrypi.org/documentati ... s-point.md
qui consiste a créer un point d'accès wifi.

J'ai donc utilisé une nouvelle carte micro SD où j'ai installé la dernière version raspbian stretch, soit celle du 27 juin 2018.
J'utilise ma Rpi2B puisque ce test, je le fais sur une carte Micro SD.

Ma Rpi2B est branché à ma box par le câble éthernet et j'ai mis aussi ma clef wifi.

En résumé, j'ai configuré les points suivants :
1) test de ma clef wifi, afin de savoir si je peux l'utiliser en tant que "AP". La réponse est OUI.

2) configuration du fichier "/etc/dhcpcd.conf" :

Code : Tout sélectionner

denyinterfaces wlan0
denyinterfaces eth0

interface wlan0
nohook wpa_supplicant
static ip_address=192.168.4.1/24
3) installation de dnsmasq et configuration du fichier "/etc/dnsmasq.conf" :

Code : Tout sélectionner

interface=wlan0
  dhcp-range=192.168.4.20,192.168.4.240,255.255.255.0,24h
4) installatiobn de hostapd et configuration du fichier "/etc/hostapd/hostapd.conf" :

Code : Tout sélectionner

interface=wlan0
bridge=br0
driver=nl80211
ssid=mywap
hw_mode=g
channel=7
ieee80211n=1
ieee80211ac=1
country_code=FR
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=blablabla
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
5) décommenter la ligne suivante dans "/etc/sysctl.conf" :

Code : Tout sélectionner

net.ipv4.ip_forward=1
6) exécution de :

Code : Tout sélectionner

sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE
7) puis ceci :

Code : Tout sélectionner

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
8) ajout de cela :

Code : Tout sélectionner

iptables-restore < /etc/iptables.ipv4.nat
dans le fichier "/etc/rc.local", juste avant le "exit".

9) j'ai aussi ajouté un pont comme indiqué dans la dernière partie du didacticiel. Le pont fonctionne.

Voici le statut du service "dnsmasq" :

Code : Tout sélectionner

root@raspberrypi:~# sudo service dnsmasq status
? dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-07-14 15:29:24 UTC; 4min 24s ago
  Process: 1452 ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf (code=exited, status=0/SUCCESS)
  Process: 1523 ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf (code=exited, status=0/SUCCESS)
  Process: 1514 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=0/SUCCESS)
  Process: 1511 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)
 Main PID: 1522 (dnsmasq)
   CGroup: /system.slice/dnsmasq.service
           +-1522 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -r /run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service --trust-a

juil. 14 15:29:24 raspberrypi dnsmasq[1522]: demarré, version 2.76 (taille de cache 150)
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: options à la compilation : IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: attention : l'interface wlan0 n'existe pas actuellement
juil. 14 15:29:24 raspberrypi dnsmasq-dhcp[1522]: DHCP, plage d'adresses IP 192.168.4.20 -- 192.168.4.240, durée de bail 1d
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: Lecture de /run/dnsmasq/resolv.conf
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: utilise le serveur de nom 192.168.1.1#53
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: utilise le serveur de nom 2a02:8435:342:3801::1#53
juil. 14 15:29:24 raspberrypi dnsmasq[1522]: lecture /etc/hosts - 6 adresses
juil. 14 15:29:24 raspberrypi dnsmasq[1523]: Too few arguments.
juil. 14 15:29:24 raspberrypi systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
root@raspberrypi:~#
Comme on peut le constater, l'interface wlan0 n'existe pas. Le dongle wifi ne clignote pas.
Du coup, pas de point d'accès et je ne sais pas trop pourquoi.

Voici le test du service "hostapd" :

Code : Tout sélectionner

root@raspberrypi:~# sudo service hostapd status
? hostapd.service - LSB: Advanced IEEE 802.11 management daemon
   Loaded: loaded (/etc/init.d/hostapd; generated; vendor preset: enabled)
   Active: active (exited) since Sat 2018-07-14 15:01:28 UTC; 35min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 580 ExecStart=/etc/init.d/hostapd start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/hostapd.service

juil. 14 15:01:28 raspberrypi systemd[1]: Starting LSB: Advanced IEEE 802.11 management daemon...
juil. 14 15:01:28 raspberrypi systemd[1]: Started LSB: Advanced IEEE 802.11 management daemon.
root@raspberrypi:~#
Pas d'erreur dans ce service.

Et enfin, le service "dhcpcd.conf" :

Code : Tout sélectionner

root@raspberrypi:~# sudo service dhcpcd  status
? dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-07-14 15:17:50 UTC; 20min ago
  Process: 1127 ExecStop=/sbin/dhcpcd -x (code=exited, status=0/SUCCESS)
  Process: 1131 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b (code=exited, status=0/SUCCESS)
 Main PID: 1133 (dhcpcd)
   CGroup: /system.slice/dhcpcd.service
           +-1133 /sbin/dhcpcd -q -b

juil. 14 15:18:37 raspberrypi dhcpcd[1133]: br0: confirming prior DHCPv6 lease
juil. 14 15:18:37 raspberrypi dhcpcd[1133]: br0: DHCPv6 REPLY: confirm failed
juil. 14 15:18:37 raspberrypi dhcpcd[1133]: br0: soliciting a DHCPv6 lease
juil. 14 15:18:38 raspberrypi dhcpcd[1133]: br0: REPLY6 received from fe80::46ce:7dff:fe96:45d0
juil. 14 15:18:38 raspberrypi dhcpcd[1133]: br0: adding address 2a02:8435:342:3801::440/128
juil. 14 15:18:38 raspberrypi dhcpcd[1133]: br0: renew in 43200, rebind in 75600, expire in 86400 seconds
juil. 14 15:18:38 raspberrypi dhcpcd[1133]: br0: probing address 192.168.1.44/24
juil. 14 15:18:43 raspberrypi dhcpcd[1133]: br0: leased 192.168.1.44 for 86400 seconds
juil. 14 15:18:43 raspberrypi dhcpcd[1133]: br0: adding route to 192.168.1.0/24
juil. 14 15:18:43 raspberrypi dhcpcd[1133]: br0: adding default route via 192.168.1.1
root@raspberrypi:~#
Un petit problème avec le DHCPv6, sans conséquence, je crois, avec le point d'accès et mon dongle wifi.

Le problème que je rencontre est que mon dongle wifi ne démarre pas et je ne sais pas pourquoi.
Par ailleurs, j'utilise ce dongle wifi avec une autre configuration de raspbian et je n'ai aucun problème pour me connecter.

Qu'est-ce que j'ai mal fait ?

@+
Modifié en dernier par Artemus24 le jeu. 19 juil. 2018 01:14, modifié 3 fois.
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

Re: Point d'accès Wifi !

Message par Artemus24 » dim. 15 juil. 2018 17:55

Salut à tous.

Je complète mon message précédant.

Voici le compte-rendu de la commande "iw list" :

Code : Tout sélectionner

root@raspberrypi:~# iw list
Wiphy phy1
        max # scan SSIDs: 9
        max scan IEs length: 2304 bytes
        max # sched scan SSIDs: 0
        max # match sets: 0
        max # scan plans: 1
        max scan plan interval: -1
        max scan plan iterations: 0
        Retry short limit: 7
        Retry long limit: 4
        Coverage class: 0 (up to 0m)
        Supported Ciphers:
                * WEP40 (00-0f-ac:1)
                * WEP104 (00-0f-ac:5)
                * TKIP (00-0f-ac:2)
                * CCMP-128 (00-0f-ac:4)
        Available Antennas: TX 0 RX 0
        Supported interface modes:
                 * IBSS
                 * managed
                 * AP
                 * monitor
                 * P2P-client
                 * P2P-GO
        Band 1:
                Capabilities: 0x1862
                        HT20/HT40
                        Static SM Power Save
                        RX HT20 SGI
                        RX HT40 SGI
                        No RX STBC
                        Max AMSDU length: 7935 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 16 usec (0x07)
                HT Max RX data rate: 150 Mbps
                HT TX/RX MCS rate indexes supported: 0-7, 32
                Bitrates (non-HT):
                        * 1.0 Mbps
                        * 2.0 Mbps
                        * 5.5 Mbps
                        * 11.0 Mbps
                        * 6.0 Mbps
                        * 9.0 Mbps
                        * 12.0 Mbps
                        * 18.0 Mbps
                        * 24.0 Mbps
                        * 36.0 Mbps
                        * 48.0 Mbps
                        * 54.0 Mbps
                Frequencies:
                        * 2412 MHz [1] (20.0 dBm)
                        * 2417 MHz [2] (20.0 dBm)
                        * 2422 MHz [3] (20.0 dBm)
                        * 2427 MHz [4] (20.0 dBm)
                        * 2432 MHz [5] (20.0 dBm)
                        * 2437 MHz [6] (20.0 dBm)
                        * 2442 MHz [7] (20.0 dBm)
                        * 2447 MHz [8] (20.0 dBm)
                        * 2452 MHz [9] (20.0 dBm)
                        * 2457 MHz [10] (20.0 dBm)
                        * 2462 MHz [11] (20.0 dBm)
                        * 2467 MHz [12] (20.0 dBm) (no IR)
                        * 2472 MHz [13] (20.0 dBm) (no IR)
                        * 2484 MHz [14] (20.0 dBm) (no IR)
        Band 2:
                Capabilities: 0x1862
                        HT20/HT40
                        Static SM Power Save
                        RX HT20 SGI
                        RX HT40 SGI
                        No RX STBC
                        Max AMSDU length: 7935 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
                Minimum RX AMPDU time spacing: 16 usec (0x07)
                HT Max RX data rate: 150 Mbps
                HT TX/RX MCS rate indexes supported: 0-7, 32
                Bitrates (non-HT):
                        * 6.0 Mbps
                        * 9.0 Mbps
                        * 12.0 Mbps
                        * 18.0 Mbps
                        * 24.0 Mbps
                        * 36.0 Mbps
                        * 48.0 Mbps
                        * 54.0 Mbps
                Frequencies:
                        * 5170 MHz [34] (disabled)
                        * 5180 MHz [36] (20.0 dBm) (no IR)
                        * 5190 MHz [38] (20.0 dBm) (no IR)
                        * 5200 MHz [40] (20.0 dBm) (no IR)
                        * 5210 MHz [42] (20.0 dBm) (no IR)
                        * 5220 MHz [44] (20.0 dBm) (no IR)
                        * 5230 MHz [46] (20.0 dBm) (no IR)
                        * 5240 MHz [48] (20.0 dBm) (no IR)
                        * 5260 MHz [52] (20.0 dBm) (no IR, radar detection)
                        * 5280 MHz [56] (20.0 dBm) (no IR, radar detection)
                        * 5300 MHz [60] (20.0 dBm) (no IR, radar detection)
                        * 5320 MHz [64] (20.0 dBm) (no IR, radar detection)
                        * 5500 MHz [100] (20.0 dBm) (no IR, radar detection)
                        * 5520 MHz [104] (20.0 dBm) (no IR, radar detection)
                        * 5540 MHz [108] (20.0 dBm) (no IR, radar detection)
                        * 5560 MHz [112] (20.0 dBm) (no IR, radar detection)
                        * 5580 MHz [116] (20.0 dBm) (no IR, radar detection)
                        * 5600 MHz [120] (20.0 dBm) (no IR, radar detection)
                        * 5620 MHz [124] (20.0 dBm) (no IR, radar detection)
                        * 5640 MHz [128] (20.0 dBm) (no IR, radar detection)
                        * 5660 MHz [132] (20.0 dBm) (no IR, radar detection)
                        * 5680 MHz [136] (20.0 dBm) (no IR, radar detection)
                        * 5700 MHz [140] (20.0 dBm) (no IR, radar detection)
                        * 5745 MHz [149] (20.0 dBm) (no IR)
                        * 5765 MHz [153] (20.0 dBm) (no IR)
                        * 5785 MHz [157] (20.0 dBm) (no IR)
                        * 5805 MHz [161] (20.0 dBm) (no IR)
                        * 5825 MHz [165] (20.0 dBm) (no IR)
                        * 5920 MHz [184] (disabled)
                        * 5940 MHz [188] (disabled)
                        * 5960 MHz [192] (disabled)
                        * 5980 MHz [196] (disabled)
                        * 6000 MHz [200] (disabled)
                        * 6020 MHz [204] (disabled)
                        * 6040 MHz [208] (disabled)
                        * 6060 MHz [212] (disabled)
                        * 6080 MHz [216] (disabled)
        Supported commands:
                 * new_interface
                 * set_interface
                 * new_key
                 * start_ap
                 * new_station
                 * set_bss
                 * join_ibss
                 * set_pmksa
                 * del_pmksa
                 * flush_pmksa
                 * remain_on_channel
                 * frame
                 * set_channel
                 * connect
                 * disconnect
        Supported TX frame types:
                 * IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
                 * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0
        Supported RX frame types:
                 * IBSS: 0xd0
                 * managed: 0x40 0xd0
                 * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
                 * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
                 * P2P-client: 0x40 0xd0
                 * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0
        software interface modes (can always be added):
                 * monitor
        interface combinations are not supported
        Device supports scan flush.
root@raspberrypi:~#
Dans la section "Supported interface modes:", on peut constater que mon dongle wifi est bien "ap".
A priori, je peut l'utiliser en tant que point d'accès wifi.

Ensuite, au lieu de rebooter systématiquement ma raspberry, j'ai préféré lancer la commande suivante :

Code : Tout sélectionner

root@raspberrypi:~# sudo hostapd -dd /etc/hostapd/hostapd.conf
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
nl80211: Supported cipher 00-0f-ac:2
nl80211: Supported cipher 00-0f-ac:4
nl80211: Using driver-based off-channel TX
nl80211: interface wlan0 in phy phy0
nl80211: Set mode ifindex 3 iftype 3 (AP)
nl80211: Setup AP(wlan0) - device_ap_sme=1 use_monitor=1
nl80211: Enable Probe Request reporting nl_preq=0x3fb038
nl80211: Register frame type=0x40 (WLAN_FC_STYPE_PROBE_REQ) nl_handle=0x3fb038 match=
nl80211: Add own interface ifindex 4
nl80211: if_indices[16]: 4
nl80211: Add own interface ifindex 3
nl80211: if_indices[16]: 4 3
nl80211: Adding interface wlan0 into bridge br0
phy: phy0
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
nl80211: Regulatory information - country=00
nl80211: 2402-2472 @ 40 MHz 20 mBm
nl80211: 2457-2482 @ 20 MHz 20 mBm (no IR)
nl80211: 2474-2494 @ 20 MHz 20 mBm (no OFDM) (no IR)
nl80211: 5170-5250 @ 80 MHz 20 mBm (no IR)
nl80211: 5250-5330 @ 80 MHz 20 mBm (DFS) (no IR)
nl80211: 5490-5730 @ 160 MHz 20 mBm (DFS) (no IR)
nl80211: 5735-5835 @ 80 MHz 20 mBm (no IR)
nl80211: 57240-63720 @ 2160 MHz 0 mBm
nl80211: Added 802.11b mode based on 802.11g information
Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=20 dBm
Completing interface initialization
Mode: IEEE 802.11g  Channel: 7  Frequency: 2442 MHz
DFS 0 channels required radar detection
nl80211: Set freq 2442 (ht_enabled=0, vht_enabled=0, bandwidth=20 MHz, cf1=2442 MHz, cf2=0 MHz)
  * freq=2442
  * vht_enabled=0
  * ht_enabled=0
RATE[0] rate=10 flags=0x1
RATE[1] rate=20 flags=0x1
RATE[2] rate=55 flags=0x1
RATE[3] rate=110 flags=0x1
RATE[4] rate=60 flags=0x0
RATE[5] rate=90 flags=0x0
RATE[6] rate=120 flags=0x0
RATE[7] rate=180 flags=0x0
RATE[8] rate=240 flags=0x0
RATE[9] rate=360 flags=0x0
RATE[10] rate=480 flags=0x0
RATE[11] rate=540 flags=0x0
hostapd_setup_bss(hapd=0x3fa9a0 (wlan0), first=1)
wlan0: Flushing old station entries
nl80211: flush -> DEL_STATION wlan0 (all)
wlan0: Deauthenticate all stations
nl80211: sta_remove -> DEL_STATION wlan0 ff:ff:ff:ff:ff:ff --> -22 (Invalid argument)
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=(nil) key_idx=0 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=(nil) key_idx=1 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=(nil) key_idx=2 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=(nil) key_idx=3 set_tx=0 seq_len=0 key_len=0
Using interface wlan0 with hwaddr 00:e0:4c:08:ac:db and ssid "mywap"
Deriving WPA PSK based on passphrase
SSID - hexdump_ascii(len=5):
     6d 79 77 61 70                                    mywap
PSK (ASCII passphrase) - hexdump_ascii(len=19): [REMOVED]
PSK (from passphrase) - hexdump(len=32): [REMOVED]
random: Got 15/20 bytes from /dev/random
random: Only 15/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
Get randomness: len=32 entropy=0
GMK - hexdump(len=32): [REMOVED]
Get randomness: len=32 entropy=0
Key Counter - hexdump(len=32): [REMOVED]
WPA: Delay group state machine start until Beacon frames have been configured
nl80211: Set beacon (beacon_set=0)
nl80211: Beacon head - hexdump(len=56): 80 00 00 00 ff ff ff ff ff ff 00 e0 4c 08 ac db 00 e0 4c 08 ac db 00 00 00 00 00 00 00 00 00 00 64 00 11 04 00 05 6d 79 77 61 70 01 08 82 84 8b 96 0c 12 18 24 03 01 07
nl80211: Beacon tail - hexdump(len=39): 2a 01 04 32 04 30 48 60 6c dd 16 00 50 f2 01 01 00 00 50 f2 02 01 00 00 50 f2 02 01 00 00 50 f2 02 7f 04 00 00 00 02
nl80211: ifindex=3
nl80211: beacon_int=100
nl80211: dtim_period=2
nl80211: ssid - hexdump_ascii(len=5):
     6d 79 77 61 70                                    mywap
  * beacon_int=100
nl80211: hidden SSID not in use
nl80211: privacy=1
nl80211: auth_algs=0x1
nl80211: wpa_version=0x1
nl80211: key_mgmt_suites=0x2
nl80211: pairwise_ciphers=0x8
nl80211: group_cipher=0x8
nl80211: beacon_ies - hexdump(len=6): 7f 04 00 00 00 02
nl80211: proberesp_ies - hexdump(len=6): 7f 04 00 00 00 02
nl80211: assocresp_ies - hexdump(len=6): 7f 04 00 00 00 02
WPA: Start group state machine to set initial keys
WPA: group state machine entering state GTK_INIT (VLAN-ID 0)
Get randomness: len=16 entropy=0
GTK - hexdump(len=32): [REMOVED]
WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=2 addr=0xc7868 key_idx=1 set_tx=1 seq_len=0 key_len=32
nl80211: KEY_DATA - hexdump(len=32): [REMOVED]
   broadcast key
nl80211: Set wlan0 operstate 0->1 (UP)
netlink: Operstate: ifindex=3 linkmode=-1 (no change), operstate=6 (IF_OPER_UP)
Failed to set TX queue parameters for queue 0.
Failed to set TX queue parameters for queue 1.
Failed to set TX queue parameters for queue 2.
Failed to set TX queue parameters for queue 3.
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
wlan0: Setup of interface done.
ctrl_iface not configured!
random: Got 5/5 bytes from /dev/random
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1003 ([UP])
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 master=4 ifi_family=0 ifi_flags=0x1003 ([UP])
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 master=4 ifi_family=0 ifi_flags=0x1003 ([UP])
RTM_NEWLINK: ifi_index=3 ifname=wlan0 master=4 operstate=2 ifi_family=7 ifi_flags=0x1003 ([UP])
nl80211: Add ifindex 4 for bridge br0
nl80211: Add own interface ifindex 4
nl80211: ifindex 4 already in the list
RTM_NEWLINK: ifi_index=4 ifname=br0 operstate=6 linkmode=0 ifi_family=0 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
wlan0: Event INTERFACE_STATUS (5) received
Unknown event 5
RTM_NEWLINK: ifi_index=3 ifname=wlan0 master=4 operstate=6 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
nl80211: Add ifindex 4 for bridge br0
nl80211: Add own interface ifindex 4
nl80211: ifindex 4 already in the list
RTM_NEWLINK: ifi_index=3 ifname=wlan0 master=4 operstate=6 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
nl80211: Add ifindex 4 for bridge br0
nl80211: Add own interface ifindex 4
nl80211: ifindex 4 already in the list
RTM_NEWLINK: ifi_index=3 ifname=wlan0 master=4 operstate=6 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
nl80211: Add ifindex 4 for bridge br0
nl80211: Add own interface ifindex 4
nl80211: ifindex 4 already in the list
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=6 linkmode=0 master=4 ifi_family=0 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: RTM_NEWLINK: ifi_index=3 ifname=wlan0 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: vlan_newlink(wlan0)
VLAN: RTM_NEWLINK: ifi_index=3 ifname=wlan0 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: vlan_newlink(wlan0)
VLAN: RTM_NEWLINK: ifi_index=3 ifname=wlan0 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: vlan_newlink(wlan0)
VLAN: RTM_NEWLINK: ifi_index=3 ifname=wlan0 ifi_family=0 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: vlan_newlink(wlan0)
RTM_NEWLINK: ifi_index=3 ifname=wlan0 master=4 operstate=6 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
nl80211: Add ifindex 4 for bridge br0
nl80211: Add own interface ifindex 4
nl80211: ifindex 4 already in the list
VLAN: RTM_NEWLINK: ifi_index=3 ifname=wlan0 ifi_family=7 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
VLAN: vlan_newlink(wlan0)
J'obtiens bien mon point d'accès wifi, de nom "mywap".

Je rencontre un problème que je ne sais pas comment le résoudre.
Si je démarre le service "dhcpcd", il me provoque une erreur :

Code : Tout sélectionner

root@raspberrypi:~# sudo systemctl restart dhcpcd
Job for dhcpcd.service failed because the control process exited with error code.
See "systemctl status dhcpcd.service" and "journalctl -xe" for details.
root@raspberrypi:~# sudo systemctl status dhcpcd.service
? dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-07-15 14:38:27 UTC; 28s ago
  Process: 1016 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b (code=exited, status=6)

juil. 15 14:38:27 raspberrypi systemd[1]: Starting dhcpcd on all interfaces...
juil. 15 14:38:27 raspberrypi dhcpcd[1016]: Not running dhcpcd because /etc/network/interfaces
juil. 15 14:38:27 raspberrypi dhcpcd[1016]: defines some interfaces that will use a
juil. 15 14:38:27 raspberrypi dhcpcd[1016]: DHCP client or static address
juil. 15 14:38:27 raspberrypi systemd[1]: dhcpcd.service: Control process exited, code=exited status=6
juil. 15 14:38:27 raspberrypi systemd[1]: Failed to start dhcpcd on all interfaces.
juil. 15 14:38:27 raspberrypi systemd[1]: dhcpcd.service: Unit entered failed state.
juil. 15 14:38:27 raspberrypi systemd[1]: dhcpcd.service: Failed with result 'exit-code'.
root@raspberrypi:~#
L'origine de cette erreur, vient du fichier "/etc/network/interfaces" que j'ai dû modifié, à cause du pont (bridge). Voici son nouveau contenu :

Code : Tout sélectionner

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0
Et voici le contenu du fichier "/etc/dhcpcd.conf" :

Code : Tout sélectionner

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

denyinterfaces eth0 wlan0

interface wlan0
static ip_address=10.0.10.1/24
nohook wpa_supplicant
Ce que j'ai ajouté, se trouve en fin du fichier.

Si je ne modifie pas le fichier "/etc/network/interfaces", je n'ai pas accès à internet par mon point d'accès.
Mais je n'ai aucune erreur quand je redémarre le service "dhcpcd".

Par contre, si je modifie "/etc/network/interfaces", j'ai bien accès à internet et de ce fait, le pont est bien activé.
Mais j'ai une erreur lors du redémarrage du service "dhcpcd".

Autre chose qui est certainement lié à mon problème.
Quand je me connecte au travers de mon point d'accès wifi, je n'obtiens pas les adresses IP (DHCP) de ma raspberry, mais celles de ma box.
En fait, tout ce passe comme si le DHCP de ma raspberry (dnsmasq) ne faisait pas son travail et allait cherchez les adresses IP dans le DHCP de ma box.

Si vous savez comment déclarer le pont sans passer par le fichier "/etc/network/interfaces", je suis preneur de cette information.
Il est pourtant dit de ne plus utiliser ce fichier "/etc/network/interfaces" mais on ne trouve aucune information sur la façon de bien configurer "/etc/dhcpcd.conf".

@+
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

Re: Point d'accès Wifi !

Message par Artemus24 » jeu. 19 juil. 2018 01:13

Salut à tous.

J'ai résolu mon problème avec des difficultés.
Il y a beaucoup de conneries dans les didacticiels sur le net, ce qui m'a induit à plusieurs reprises en erreur.

1) pour le driver "nl80211", certains didacticiels (sûrement assez ancien) stipulaient que le dongle wifi que j'utilise (RTL8188CUS) n'était pas compatible.
Je devais installer un nouveau driver. Oui sauf que j'ai été incapable de le trouver, même avec le lien donné.
Après des tests, il s'est avéré que le driver "nl80211" permet de piloter mon dongle wifi.

2) il ne faut surtout pas toucher au fichier "/etc/network/interfaces" avec la version raspbian stretch.
Or la plupart des didacticiels modifient ce fichier, ce qui provoque une erreur sur le service dhcpcd.

3) il y a une confusion qui est à l'origine de mon problème.
Les didacticiel n'ont pas compris la différences entre un pont et un routeur.
Quand on installe un pont (bridge), il ne pas faut installer dnsmasq (routeur).
D'ailleurs, même si le service dnsmasq fonctionne, il est totalement inopérant.
Inversement, si vous utilisez dnsmasq (routeur), il ne faut pas installer un pont (bridge).
Autrement dit, c'est l'un ou l'autre mais pas les deux à la fois.

Pour ma part, j'ai testé les deux cas, et de loin, je préfère gérer, au travers de dnsmasq, le dhcp et le dns.

4) dans le cas du pont, je n'ai pas trouvé l'équivalent du paramétrage de /etc/network/interfaces, à faire dans le fichier dhcpcd.
Le service dhcpcd provoque une erreur à cause du paramétrage dans /etc/network/interfaces.
Et comme je ne peux pas lancer le service dhcpcd, je ne peux pas attribuer une adresse ip fixe à la raspberry.
Et l'attribution des adresses IP se fait par la box SFR, ce qui st tout à fait normal, puisque c'est un pont.

5) le fichier de configuration dnsmasq est incomplet, ce qui provoque chez moi des anomalies.
Je n'ai pas terminé les tests, mais actuellement, je suis arrivé à faire ce que je voulais :
--> Créer une adresse du genre "10.0.10.1" pour ma raspberry.
--> Transformer ma raspberry en point d'accès wifi de nom "mywap".
--> Gérer les adresses MAC au travers du DHCP, en leur attribuant une adresse IPv4 fixe.

Les problèmes rencontrés concernent :
--> le fichier /etc/resolv.conf
--> le fichier /etc/hosts
que j'ai pu rendre inopérant dans la configuration de dnsmasq.

6) j'ai eu moins de problème avec hostapd. Il a fonctionné correctement, dès le début de l'installation.

@+
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

dyox
Raspinaute
Messages : 969
Enregistré le : dim. 28 déc. 2014 15:28
Localisation : Le long de la côte, au dessus du pays des bigoudennes, aïe

Re: [Résolu]Point d'accès Wifi !

Message par dyox » jeu. 19 juil. 2018 11:52

Bonjour Artemus24,

Quel est la finalité de votre point d'accès ?

Vous pouvez tester ça aussi. C'est clair et cela n'installe que le strict minimum mais je n'ai pas testé. https://forums.framboise314.fr/viewtopi ... 064#p20064

Vous avez aussi la distribution OpenWRT pour le AP et routeur/firewall. On peut même lui rajouter un adblock (qui agit comme pi-hole).https://openwrt.org/start.
J'ai testé ça le mois dernier. Et j'ai même poussé le vice à compiler ma propre distribution avec les drivers wifi intégrés pour ma pi2.

Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

Re: [Résolu]Point d'accès Wifi !

Message par Artemus24 » dim. 22 juil. 2018 19:09

Salut Dyox.
Dyox a écrit :Quel est la finalité de votre point d'accès ?
A priori, aucune. Je m'intéresse à tout ce qui concerne le réseau.
Aussi bien, l'aspect pont, routeur, point d'accès wifi, répéteur, les câbles, hub, ...

Et avec une raspberry, je peux me permettre d'utiliser autant de carte micro SD que je veux pour faire des tests.
Dyox a écrit :Vous pouvez tester ça aussi. C'est clair et cela n'installe que le strict minimum mais je n'ai pas testé.
Merci pour le lien.

Pour le fichier de configuration hostapd.conf, c'est à peu de chose près, ce que j'ai mis.
A l'inverse de pat499, j'ai fait une recherche sur le net, et j'ai rassemblé ce qui me semblait être la meilleur configuration.
En ce qui me concerne, ma box utilise que "b/g/n" pour le wifi et de ce fait, j'utilise "n".

Pour le bridge, j'ai utilisé le package bridge-utils.
Je n'ai pas eu de dificulté à l'utilisé, mais par contre, à l'inverse de pat499, mon problème concernait l'adresse ip fixe que je devais attribuer à la raspberry.
Comme je l'ai dit précédemment, si j'utilise le pont, je suis obligé de configurer le fichier "/etc/network/interfaces" et provoque une erreur sur le service "dhcpcd".
Donc pas d'adresse ip fixe, comme l'indique le didacticiel.
Si j'utilise le service "dnsmasq", je n'ai plus ce problème.
Ma confusion a été de croire que pour obtenir internet, j'étais obligé d'utiliser le pont, ce qui est faux.
Dyox a écrit :Vous avez aussi la distribution OpenWRT pour le AP et routeur/firewall.
J'ai jeté un coup d'oeil, et je ne sais pas trop ce cela me convient.
Après tout, la distribution raspbian me convient parfaitement, pour l'instant.
Dyox a écrit :J'ai testé ça le mois dernier. Et j'ai même poussé le vice à compiler ma propre distribution avec les drivers wifi intégrés pour ma pi2.
Pour l'instant, ce n'est pas trop mon objectif.
Comme je l'ai dit, ci-dessus, ce qui m'intéresse, c'est de comprendre le fonctionnement du réseau, aussi bien l'aspect matériel que les logiciels.

Sinon, j'ai vu une de vos dernières interventions dans le sujet "créez votre hotspot wifi avec un raspberry pi de facon express" :
--> https://www.framboise314.fr/raspap-cree ... n-express/

Si j'avais besoin d'un point d'accès wifi, ce serait pour accéder à l'internet, à partir d'une pièce où je ne peux pas capter directement le wifi de ma box.
Je sais, un répéteur aurait fait l'affaire, mais c'est surtout pour comprendre comment ce la fonctionne que j'ai fait le test.
Et cela me plait bien !

@+
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

Re: [Résolu]Point d'accès Wifi !

Message par Artemus24 » mar. 24 juil. 2018 15:33

Salut à tous.

Je vous communique mes fichiers de configuration :

1) Le fichier "/etc/hostapd/hostapd.conf" :

Code : Tout sélectionner

# ================================== #
#     hostapd configuration file     #
# ===================================#

# ----------------- #
# Global Parameters #
# ----------------- #

interface=wlan0
# bridge=br0
driver=nl80211

logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2

# --------------------------------- #
# IEEE 802.11 related configuration #
# --------------------------------- #

ssid=mywap
country_code=FR

hw_mode=g
channel=7

beacon_int=100
dtim_period=2
max_num_sta=255
rts_threshold=2347
fragm_threshold=2346

macaddr_acl=1
accept_mac_file=/etc/hostapd/hostapd.accept

auth_algs=3
ignore_broadcast_ssid=0

# ---------------------------------- #
# IEEE 802.11n related configuration #
# ---------------------------------- #

ieee80211n=1

wmm_enabled=1
require_ht=1

# ------------------------------ #
# WPA/IEEE 802.11i configuration #
# ------------------------------ #

wpa=2
wpa_passphrase=lesmysteresdelouest
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP


# --------------------------- #
# Wi-Fi Protected Setup (WPS) #
# --------------------------- #

wps_state=0
Le fichier de nom "/etc/hostapd.accept" contient la liste des adresses MAC que j'autorise à accéder à mon WAP.

2) le fichier "/etc/dnsmasq.d/local.conf" (c'est le fichier "dnsmasq.conf") :

Code : Tout sélectionner

# ============================== #
# Configuration File for Dnsmasq #
# ============================== #

# ---------------------- #
# Basic Server Operation #
# ---------------------- #

listen-address=127.0.0.1
port=53
bind-dynamic

# pid-file=/var/run/dnsmasq.pid

# -------------- #
# User and Group #
# -------------- #

user=root
group=root

# ------- #
# Logging #
# ------- #

log-facility=/var/log/dnsmasq.log
log-queries
log-dhcp

# ----------------------- #
# Name Resolution Options #
# ----------------------- #

domain-needed
expand-hosts
bogus-priv

no-hosts

dns-forward-max=150
cache-size=1024

# no-negcache
neg-ttl=3600

# ------- #
# Servers #
# ------- #

no-poll
no-resolv
strict-order

server=/localnet/10.0.10.1
server=8.8.4.4
server=8.8.8.8

# ----------- #
# Domain Name #
# ----------- #

domain=athome.lan

interface=wlan0

# ----------- #
# DHCP Server #
# ----------- #

dhcp-authoritative
dhcp-leasefile=/tmp/dhcp.leases
dhcp-option=option:router,10.0.10.1
dhcp-range=wlan0,10.0.10.100,10.0.10.240,255.255.255.0,24h

# ------------------ #
# Fixed IP Addresses #
# ------------------ #

dhcp-host=00:21:6B:C8:16:10,W-Orion,10.0.10.20,infinite
dhcp-host=00:E0:4C:14:61:28,W-TnB,10.0.10.34,infinite
Quand je choisis de sélectionner "mywap" dans la liste des points d'accès wifi, celui-ci m'attribue bien une adresse IP commençant par "10.0.10.x".
J'ai bien par la suite accès à internet !

Il me reste encore à perfectionner :
3) un fichier de nom "firewall.sh" où je vais mettre toutes les règles NAT (pare-feu) que je désire.
4) revoir le fichier "/etc/dhcpcd.conf" afin de le compléter.
5) un accès par l'IPv6.

Pour l'instant, mon point d'accès wifi fonctionne correctement.

@+
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

dyox
Raspinaute
Messages : 969
Enregistré le : dim. 28 déc. 2014 15:28
Localisation : Le long de la côte, au dessus du pays des bigoudennes, aïe

Re: [Résolu]Point d'accès Wifi !

Message par dyox » mar. 24 juil. 2018 16:20

Bonjour Artemus24,

Si cela peut vous aider, j'avais trouvé ce script pour iptables que je trouve bien foutu. Jamais testé et il contient des erreurs grossières, facilement repérable.
Il peut servir de base mais il faut le contrôler ligne par ligne.

Code : Tout sélectionner

#!/bin/sh
### BEGIN INIT INFO
# Provides:          firewall
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Démarrage du script lors de la séquence de boot
# Description:       Ajouts des règles de parefeu
### END INIT INFO

# Variables de couleur shell
yellowBold='\033[1;33m'
green='\033[0;32m'
yellow='\033[0;33m'
red='\033[0;31m'
greenBgWhiteBold='\033[1;42m'
redBgWhiteBold='\033[1;41m'
NC='\033[0m'
OK="${yellowBold}[${NC}${green}OK${NC}${yellowBold}]${NC}"

PATH=/bin:/sbin:/usr/bin:/usr/sbin

if ! [ -x /sbin/iptables ]; then
 exit 0
fi
 
PORT_SSH=2002 #22
PORT_MONIT=2020 #2812
IP_ADMIN=192.168.1.1
IFACE=eth0
 
 
##########################
# Application des règles
##########################

fw_start()
{
echo ""
echo "  - ${green} Initialisation du firewall : ${NC} OK"

# Vidage des tables et des règles personnelles
/sbin/iptables -F
/sbin/iptables -X
echo "  - ${green} Vidage des tables et des règles personnelles : ${NC} OK"

# Interdire toutes les connexions entrantes et sortantes
/sbin/iptables -t filter -P INPUT DROP
/sbin/iptables -t filter -P FORWARD DROP
/sbin/iptables -t filter -P OUTPUT DROP
echo "  - ${green} Interdire toutes les connexions entrantes et sortantes : ${NC} OK"

# Ne pas casser les connexions établies
#/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#/sbin/iptables -A OUTPUT -m state ! --state INVALID -j ACCEPT
#echo "  - ${green} Ne pas casser les connexions établies : ${NC} OK"
         

########## Règles de base du serveur ##########

# Autoriser loopback (Le serveur à tous les droits sur lui-même)
/sbin/iptables -t filter -i lo -A INPUT -j ACCEPT
/sbin/iptables -t filter -o lo -A OUTPUT -j ACCEPT
echo "  - ${green} Autoriser le loopback : ${NC} OK"

# Autoriser le ping (serveur vers extérieur)
/sbin/iptables -t filter -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
/sbin/iptables -t filter -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
echo "  - ${green} Autoriser le ping (serveur vers extérieur): ${NC} OK"

# Autoriser le ping (extérieur vers serveur)
#/sbin/iptables -t filter  -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
#/sbin/iptables -t filter  -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
#echo "  - ${green} Autoriser le ping (extérieur vers serveur): ${NC} OK"

# On accepte la transmission des erreurs de ping
/sbin/iptables -t filter -A INPUT -p icmp -m state --state RELATED -j ACCEPT
echo "  - ${green} Autoriser la transmission des erreurs de ping: ${NC} OK"

# Autoriser la résolution de nom
/sbin/iptables -t filter -i $IFACE -A INPUT -p udp --dport 53 -j ACCEPT
echo "  - ${green} Autoriser la résolution de nom : ${NC} OK"

# Autoriser NTP
/sbin/iptables -t filter -o $IFACE -A OUTPUT -p udp --dport 123 -j ACCEPT
echo "  - ${green} Autoriser NTP : ${NC} OK"


########## Règles pour authorisation via une ip management ##########

# Autoriser SSH
#/sbin/iptables -t filter -A INPUT -p TCP --dport $PORT_SSH -j ACCEPT
#/sbin/iptables -t filter -A OUTPUT -p TCP --dport $PORT_SSH -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport $PORT_SSH -j ACCEPT
/sbin/iptables -t filter -A OUTPUT -o $IFACE -p TCP --dport $PORT_SSH –d $IP_ADMIN -j ACCEPT
echo "  - ${green} Autoriser SSH : ${NC} OK"

# Autoriser Monit
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport $PORT_MONIT –s $IP_ADMIN -j ACCEPT
echo "  - ${green} Autoriser Monit : ${NC} OK"

# Autoriser Samba
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 137 –s $IP_ADMIN -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 138 –s $IP_ADMIN -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 139 –s $IP_ADMIN -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 445 –s $IP_ADMIN -j ACCEPT
echo "  - ${green} Autoriser Samba : ${NC} OK"
 
 
########## Règles pour l'authorisation Apache/postfix ##########
 
# Autoriser HTTP
/sbin/iptables -t filter -A OUTPUT -o $IFACE -p TCP --dport 80 -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 80 -j ACCEPT
/sbin/iptables -t filter -A OUTPUT -o $IFACE -p TCP --dport 8080 –d $IP_ADMIN -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 8080 –s $IP_ADMIN -j ACCEPT
echo "  - ${green} Autoriser HTTP : ${NC} OK"

# Autoriser HTTPS
/sbin/iptables -t filter -A OUTPUT -o $IFACE -p TCP --dport 443 -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 443 -j ACCEPT
/sbin/iptables -t filter -A INPUT -i $IFACE -p TCP --dport 8443 -j ACCEPT
echo "  - ${green} Autoriser HTTPS : ${NC} OK"

# Autoriser SMTP
#/sbin/iptables -t filter -A INPUT -p TCP --dport 25 -j ACCEPT
/sbin/iptables -t filter -A OUTPUT -o $IFACE -p TCP --dport 25 -j ACCEPT
echo "  - ${green} Autoriser SMTP : ${NC} OK"

          
########## Règles pour sécuriser ##########

## Anti-spoofing rules
/sbin/iptables -A INPUT -i $IFACE -s 0.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 10.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 127.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 172.16.0.0/12 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 169.254.0.0/16 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 192.168.0.0/16 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 224.0.0.0/3 -j DROP
/sbin/iptables -A INPUT -i $IFACE -s 240.0.0.0/5 -j DROP

/sbin/iptables -A INPUT -i $IFACE -d 0.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i $IFACE -d 240.0.0.0/5 -j DROP
/sbin/iptables -A INPUT -i $IFACE -d 224.0.0.0/3 -j DROP
/sbin/iptables -A INPUT -i $IFACE -d 239.255.255.0/24 -j DROP
/sbin/iptables -A INPUT -i $IFACE -d 255.255.255.255 -j DROP
/sbin/iptables -A INPUT -i $IFACE -d 240.0.0.0/5 -j DROP
echo "  - ${green} Règles anti-usurpation $IFACE : ${NC} OK"

/sbin/iptables -A FORWARD -i $IFACE -p TCP --syn -m limit --limit 1/second -j ACCEPT
/sbin/iptables -A FORWARD -i $IFACE -p udp -m limit --limit 1/second -j ACCEPT
/sbin/iptables -A FORWARD -i $IFACE -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
echo "  - ${green} Règles anti-usurpation TCP/UDP/ICMP : ${NC} OK"

# for SMURF attack protection
iptables -t filter -A INPUT -p icmp -m icmp --icmp-type address-mask-request -j DROP
iptables -t filter -A INPUT -p icmp -m icmp --icmp-type timestamp-request -j DROP
iptables -t filter -A INPUT -p icmp -m icmp -m limit --limit 1/second -j ACCEPT
echo "  - ${green} Règles anti-SMURF attack protection: ${NC} OK"

# Interdire le scan de ports
## NULL-SCAN
iptables -t filter -A INPUT -p TCP --TCP-flags ALL NONE -j LOG --log-prefix "IPTABLES NULL-SCAN:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL NONE -j DROP

## XMAS-SCAN
iptables -t filter -A INPUT -p TCP --TCP-flags ALL ALL -j LOG --log-prefix "IPTABLES XMAS-SCAN:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL ALL -j DROP

## SYNFIN-SCAN
iptables -t filter -A INPUT -p TCP --TCP-flags ALL SYN,FIN -j LOG --log-prefix "IPTABLES SYNFIN-SCAN:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL SYN,FIN -j DROP

## NMAP-XMAS-SCAN
iptables -t filter -A INPUT -p TCP --TCP-flags ALL URG,PSH,FIN -j LOG --log-prefix "IPTABLES NMAP-XMAS-SCAN:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL URG,PSH,FIN -j DROP

## FIN-SCAN
iptables -t filter -A INPUT -p TCP --TCP-flags ALL FIN -j LOG --log-prefix "IPTABLES FIN-SCAN:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL FIN -j DROP

## NMAP-ID
iptables -t filter -A INPUT -p TCP --TCP-flags ALL URG,PSH,SYN,FIN -j LOG --log-prefix "IPTABLES NMAP-ID:"
iptables -t filter -A INPUT -p TCP --TCP-flags ALL URG,PSH,SYN,FIN -j DROP

## SYN-RST
iptables -t filter -A INPUT -p TCP --TCP-flags SYN,RST SYN,RST -j LOG --log-prefix "IPTABLES SYN-RST:"
iptables -t filter -A INPUT -p TCP --TCP-flags SYN,RST SYN,RST -j DROP

## SYN-FLOODING
iptables -t filter -N syn-flood
iptables -t filter -A INPUT -i $IFACE -p TCP --syn -j syn-flood
iptables -t filter -A syn-flood -m limit --limit 1/sec --limit-burst 4 -j RETURN
iptables -t filter -A syn-flood -j LOG --log-prefix "IPTABLES SYN-FLOOD:"
iptables -t filter -A syn-flood -j DROP

## Make sure NEW TCP connections are SYN packets
iptables -t filter -A INPUT -i $IFACE -p TCP ! --syn -m state --state NEW -j LOG --log-prefix "IPTABLES SYN-FLOOD:"
iptables -t filter -A INPUT -i $IFACE -p TCP ! --syn -m state --state NEW -j DROP

## port scanner
iptables -t filter -N port-scan
iptables -t filter -A INPUT -i $IFACE -p TCP --TCP-flags SYN,ACK,FIN,RST RST -j port-scan
iptables -t filter -A port-scan -m limit --limit 1/s --limit-burst 4 -j RETURN
iptables -t filter -A port-scan -j LOG --log-prefix "IPTABLES PORT-SCAN:"
iptables -t filter -A port-scan -j DROP
echo "  - ${green} Règles anti-scan de port : ${NC} OK"

# Prévient des attaques de type Denial of Service (DoS)
iptables -t filter -A INPUT -i $IFACE -p TCP --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
echo "  - ${green} Règles anti-DoS : ${NC} OK"

# Autres protections réseau
# (certaines règles ne fonctionneront que pour certaines versions du noyau)
echo 1 > /proc/sys/net/ipv4/TCP_syncookies
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route 
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "  - ${green} Règles de protection réseaux : ${NC} OK"
echo ""
       
# So are security package updates:
# Note: You can hardcode the IP address here to prevent DNS spoofing
# and to setup the rules even if DNS does not work but then you
# will not "see" IP changes for this service:
/sbin/iptables -A OUTPUT -p TCP -d security.debian.org --dport 80 -j ACCEPT

}

sw_help()
{
    echo "  - ${green}Pour résumer, voici un récapitulatif de certaines attributs définis dans nos règles : ${NC}"
    echo "  - ${green}Dans la ligne de votre nouvelle règle, il faut préciser les paquets sont traités en entrée, en sortie ou bien s’ils sont routés: ${NC}"
    echo "  - ${yellow}FORWARD ${NC}${blue}: Traite les paquets routés. ${NC}"
    echo "  - ${yellow}INPUT ${NC}${blue}: Traite les paquets entrants. ${NC}"
    echo "  - ${yellow}OUTPUT ${NC}${blue}: Traite les paquets sortants. ${NC}"
    echo ""
    echo "  - ${green}Ceci définit l’action à faire sur les paquets d’une règle inscrite dans la table des règles : ${NC}"
    echo "  - ${yellow}DROP ${NC}${blue}: Le paquet est rejeté, aucune notification n’est envoyée à la source. ${NC}"
    echo "  - ${yellow}REJECT ${NC}${blue}: Le paquet est rejeté, une notification est envoyée à la source ${NC}"
    echo "  - ${yellow}ACCEPT ${NC}${blue}: Le paquet est accepté. ${NC}"
    echo ""
    echo "  - ${green}La définition des attributs pour les règles: ${NC}"
    echo "  - ${yellow}-A ${NC}${blue}: ajoute une règle ${NC}"
    echo "  - ${yellow}-D ${NC}${blue}: supprime une règle ${NC}"
    echo "  - ${yellow}-F ${NC}${blue}: vide les tables ${NC}"
    echo "  - ${yellow}-X ${NC}${blue}: vide les règles ${NC}"
    echo "  - ${yellow}-L ${NC}${blue}: liste les règles ${NC}"
    echo "  - ${yellow}-i ${NC}${blue}: interface entrante ${NC}"
    echo "  - ${yellow}-o ${NC}${blue}: interface sortante ${NC}"
    echo "  - ${yellow}-p ${NC}${blue}: protocole ${NC}"
    echo "  - ${yellow}-s ${NC}${blue}: nom d’hôte ou adresse ip ${NC}"
    echo "  - ${yellow}-j ${NC}${blue}: jump, action de la règle (ACCEPT, DROP, REJECT ) ${NC}"
    echo "  - ${yellow}-m ${NC}${blue}: options de concordance ${NC}"
    echo "  - ${yellow}–dport ${NC}${blue}: numéro port de destination ${NC}"
    echo "  - ${yellow}–sport ${NC}${blue}: numéro du port source ${NC}"
    echo ""
}

##########################
# Bloque tous les packets routés et entrants
##########################
 
fw_blockAll ()
{
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT ACCEPT
}
 
##########################
# Vidange des règles du firewall
##########################
 
fw_clear ()
{
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -t nat -F
/sbin/iptables -t nat -X
/sbin/iptables -t mangle -F
/sbin/iptables -t mangle -X
/sbin/iptables -t raw -F
/sbin/iptables -t raw -X
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
}

##########################
# Teste les règles du firewall
##########################
 
fw_save ()
{
    /sbin/iptables-save > /etc/iptables.backup
}
 
fw_restore ()
{
if [ -e /etc/iptables.backup ]; then
    /sbin/iptables-restore < /etc/iptables.backup
fi
}
 
fw_test ()
{
    fw_save
    fw_restart
    sleep 120
    echo "  - ${green}Restauration des anciennes règles du firewall...${NC} OK"
    fw_restore
   
}

case "$1" in
start|restart)
    echo ""
    echo "  - ${green}Démarrage du firewall...${NC} OK"
    fw_blockAll
    fw_start
    echo "  - ${green}Redémarrage de Fail2ban pour la restauration des règles${NC} OK"
    # relance fail2ban si installé
    if [ -x /usr/bin/fail2ban-server ]; then
        service fail2ban restart
    fi
        echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;

blockAllInput)
    echo ""
    echo "  - ${green}Verrouillage du trafic entrant...${NC} OK"
    fw_blockAll
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;

clear)
    echo ""
    echo "  - ${green}Vide les règles du firewall...${NC} OK"
    fw_clear
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;

test)
    echo ""
    echo "  - ${green}Test des nouvelles règles du firewall...${NC} OK"
    echo "  - ${green}L'ancienne configuration sera restaurée dans 120 secondes...${NC} OK"
    fw_test
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;

save)
    echo ""
    echo "  - ${green}Sauvegarde les règles actuelles: ${NC}"
    fw_save
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;
   
restore)
    echo ""
    echo "  - ${green}Restaure les règles sauvegardées: ${NC}"
    fw_restore
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;
   
list)
    echo ""
    echo "  - ${green}Liste des règles : ${NC}"
    /sbin/iptables -n -L --line-numbers
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;

status)
    echo ""
    echo "  - ${green}Liste des règles : ${NC}"
    /sbin/iptables -
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;   
   
help)
    echo ""
    echo "  - ${green}Rappel : ${NC}"
    sw_help
    echo "\n${greenBgWhiteBold}Fait!${NC} OK"
    echo ""
    ;;
   
*)
    echo "  - ${yellow}Usage: $0 {start|blockAllInput|restart|clear|test|list|status|save|restore|help}${NC}"
    echo "  - ${red}Attention blockAll bloque tout trafic entrant/sortant!!!${NC}"
    echo "  - ${red}Attention clear autorise tout trafic entrant/sortant!!!${NC}"
    exit 1
    ;;
esac
exit 0

Répondre

Retourner vers « Les applications spécialisées du Raspberry Pi »