« Raspbian Commandes » : différence entre les versions

 
(47 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
=== Redémarrer ===
=== Redémarrer ===
<pre>
<syntaxhighlight lang="bash" line copy>
sudo reboot
sudo reboot
</pre>
</syntaxhighlight>
 
=== Arrêt ===
=== Arrêt ===
<pre>
<syntaxhighlight lang="bash" line copy>
sudo shutdown -h now
sudo shutdown -h now
</pre>
</syntaxhighlight>
 
=== Firewall ===
=== Firewall ===
<syntaxhighlight lang="bash" line copy>
# Créer /etc/init.d/firewall
# Afin de l'ajouter aux scripts appelés au démarrage :
# Ajouter une entête dans le fichier
#!/bin/sh
### BEGIN INIT INFO
# Provides:          firewall rules
# Required-Start:    $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Firewall deamon
# Description:      Enable service provided by daemon.
### END INIT INFO
</syntaxhighlight>


#<=> stop & start /etc/init.d/firewall
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">sudo update-rc.d firewall defaults</span>
# Sauvegarde
démarrer un deamon -> http://manpages.ubuntu.com/manpages/trusty/fr/man8/update-rc.d.8.html
sudo systemctl enable firewall
</syntaxhighlight>
 
<syntaxhighlight lang="bash" line copy>
"Relance
sudo update-rc.d firewall defaults
</syntaxhighlight>
démarrer un deamon -> http://manpages.ubuntu.com/manpages/trusty/fr/man8/update-rc.d.8.html
 
<syntaxhighlight lang="bash" line copy>
sudo /etc/init.d/firewall status
</syntaxhighlight>


=== cron ===
=== cron ===
<pre>
<syntaxhighlight lang="bash" line copy>
#relancer service cron
#relancer service cron
sudo /etc/init.d/cron restart
sudo /etc/init.d/cron restart
</pre>
</syntaxhighlight>
 
=== IPv6 ===
<syntaxhighlight lang="bash" line copy>
/etc/sysctl.d/enableipv6.conf
journalctl | grep -Ei 'dhcp6'
ip -6 route
</syntaxhighlight>
 
=== Désactivation ===
==== Bluetooth & Wifi ====
<syntaxhighlight lang="bash" line copy>
dans /boot/config.txt
dtoverlay=pi3-disable-wifi
dtoverlay=pi3-disable-bt
puis sudo reboot
</syntaxhighlight>
 
==== ipv6 ====
<syntaxhighlight lang="bash" line copy>
# * au démarage
# dans /etc/sysctl.d/
#créer /etc/sysctl.d/disableipv6.conf
#avec :
 
# désactivation de ipv6 pour toutes les interfaces
net.ipv6.conf.all.disable_ipv6=1
 
# désactivation de l’auto configuration pour toutes les interfaces
net.ipv6.conf.all.autoconf=0
 
# désactivation de ipv6 pour les nouvelles interfaces (ex:si ajout de carte réseau)
net.ipv6.conf.default.disable_ipv6=1
 
# désactivation de l’auto configuration pour les nouvelles interfaces
net.ipv6.conf.default.autoconf=0
</syntaxhighlight>
 
=== version de l'OS ===
<syntaxhighlight lang="bash" line>
#Informations du système
hostnamectl
</syntaxhighlight>
<syntaxhighlight lang="bash" line copy>
cat /etc/os-release
</syntaxhighlight>
<syntaxhighlight lang="bash" line copy>
lsb_release -a
</syntaxhighlight>


=== version matériel ===
=== version matériel ===
cat /proc/cpuinfo
<syntaxhighlight lang="bash" line copy>
#Raspberry Pi 3 Model B Rev 1.2
cat /proc/cpuinfo
#Raspberry Pi 3 Model B Rev 1.2
</syntaxhighlight>


=== CPU infos ===
=== CPU infos ===
lscpu
<syntaxhighlight lang="bash" line copy>
lscpu
</syntaxhighlight>


=== Paquets APT ===
=== Paquets APT ===
[[ APT | voir APT]]
=== Redémarrer unbound ===
<syntaxhighlight lang="bash" line copy>
sudo service unbound restart
</syntaxhighlight>
=== DHCPCD (static ip_address) ===
<pre>
DHCPCD signifie DHCP Client Daemon. Comme son nom l'indique, c'est un client DHCP s'exécutant en tâche de fond. Mais son nom est également trompeur car il ne se limite pas à récupérer une adresse IP via DHCP, c'est aussi sur lui que repose toute la configuration réseau d'une machine Linux.
DHCPCD est emmené à remplacer la configuration du réseau que l'on fait via le fichier /etc/network/interfaces et le service networking sous les distributions Linux dérivées de Debian.
</pre>
*voir:[https://www.jesus-forain.fr/blog/configuration-de-dhcpcd-52.html Configuration de DHCPCD]
<syntaxhighlight lang="bash" line copy>
sudo service dhcpcd status
</syntaxhighlight>
/etc/dhcpcd.conf


#mettre à jour un paquet :
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">sudo apt update (mise à jour de '''la liste''' des paquets) </span>
dhcpcd man
<span style="color: red;font-weight:bold;">sudo apt list --upgradable (pour voir ce qui doit être mis à jour) </span>
</syntaxhighlight>
<span style="color: red;font-weight:bold;">sudo apt install --only-upgrade firefox </span>
#voir tous les paquets
<span style="color: red;font-weight:bold;">dpkg --list</span>
#voir si un paquet est à jour
<span style="color: red;font-weight:bold;">apt-cache policy firefox</span>


=== Redémarrer unbound ===
<pre>
  <span style="color: red;font-weight:bold;">sudo service unbound restart</font>
static value
            Configures a static value. If you set ip_address then dhcpcd will not attempt to obtain a lease and will just use the value for the address with an infinite lease time.  If you
            set ip6_address, dhcpcd will continue auto-configuration as normal.


=== Redémarrer Lighttpd ===
            Here is an example which configures two static address, overriding the default IPv4 broadcast address, an IPv4 router, DNS and disables IPv6 auto-configuration.  You could also
<span style="color: red;font-weight:bold;">sudo service lighttpd status</span>
            use the inform6 command here if you wished to obtain more information via DHCPv6.  For IPv4, you should use the inform ipaddress option instead of setting a static address.
                  interface eth0
                  noipv6rs
                  static ip_address=192.168.0.10/24
                  static broadcast_address=192.168.0.63
                  static ip6_address=fd51:42f8:caae:d92e::ff/64
                  static routers=192.168.0.1
                  static domain_name_servers=192.168.0.1 fd51:42f8:caae:d92e::1


=== Pihole ===
            Here is an example for PPP which gives the destination a default route.  It uses the special destination keyword to insert the destination address into the value.
                  interface ppp0
                  static ip_address=
                  destination routers
</pre>


=== Lighttpd ===
<syntaxhighlight lang="bash" line copy>
sudo service lighttpd status
sudo service lighttpd restart
</syntaxhighlight>
==== vhost ====
<syntaxhighlight lang="bash" line copy>
ln -s /etc/lighttpd/conf-available/91-exemple.com.conf /etc/lighttpd/conf-enabled/91-exemple.com.conf
</syntaxhighlight>


==== Black Lists ====
=== Commandes Réseaux ===
[https://fleuryk.kappatau.fr/pihole-blocklist/ pihole-blocklist]
<syntaxhighlight lang="bash" line>
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/ParsedBlacklists/Block-EU-Cookie-Shit-List.txt
# voir les ip du reseaux et le mac adress
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/CountryCodesLists/France.txt
arp
* https://easylist-downloads.adblockplus.org/liste_fr%2Beasylist.txt
# Pour voir les DNS en cours
* https://blocklist.site/app/dl/malware
# cat /etc/resolv.conf
* https://blocklist.site/app/dl/ransomware
dig pi-hole.net @127.0.0.1 -p 53
* https://blocklist.site/app/dl/phishing
# table de routage (IPv4/IPv6)
* https://blocklist.site/app/dl/ads
ip route
* https://gist.githubusercontent.com/BBcan177/4a8bf37c131be4803cb2/raw/343ff780e15205b4dd0de37c86af34cfb26b2fbe/MS-2
iip -6 neigh show
* https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt
# Vérification des interfaces
* https://blocklist.site/app/dl/spam
ifconfig
* https://hosts.ubuntu101.co.za/domains.list
# Lister les ports ouverts et les services réseaux en écoute sur son serveur Linux grâce à netstat.
* https://hosts.ubuntu101.co.za/ips.list
netstat -lntup
# Lister tous les ports :
netstat -a
# Lister tous les ports TCP :
netstat -at
# Lister tous les ports UDP :
netstat -au
# Lister tous les ports en écoute :
netstat -l
# Lister uniquement les ports TCP en écoutes :
netstat -lt
# Lister uniquement les ports UDP en écoutes :
netstat -lu
# Afficher les statistique de tous les ports :
netstat -s
# Affichier les statistique des Port TCP :
netstat -st
# Affichier les statistique des Port UDP :
netstat -su
# Affiche le nom du programme et le PID associé :
# Cette commande est très utile lorsque vous souhaitez connaitre quel programme est exécuté sur un port particulier.
netstat -p
# Afficher directement les IP et pas de résolution de nom :
# Pour afficher toutes les connexions et tous les ports en écoute mais n’affiche que les adresses IP sans la résolutions des noms.
netstat -an
# Affiche le numéro d’identification des processus (PID) associé à chaque connexion :
netstat -o
# Afficher la table de routage IPV4 et IP6 :
netstat -r
# Affichage à un interval de temps régulier en seconde :
netstat -t “temps en seconde” #( Exemple : netstat -t 5 )
netstat -t 5
</syntaxhighlight>


=== PiVpn ===
==== 1. Lister les machines à explorer ====
#ajouter un client vpn
:Cette commande va se contenter de lister les machines que nmap explorerait sur le réseau en question.
<span style="color: red;font-weight:bold;">pihole add nopass</span>
:La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
#update pihole
<syntaxhighlight lang="bash" line>
<span style="color: red;font-weight:bold;">pihole -up</span>
nmap -sL 192.168.0.1/24
#pour voir qui est connecté
</syntaxhighlight>
<span style="color: red;font-weight:bold;">pivpn clients</span>
==== 2. Scanner les machines du réseau ====
:On va maintenant passer la même commande en faisant un ping sur chaque machine.
<syntaxhighlight lang="bash" line>
nmap -sP 192.168.0.1/24
</syntaxhighlight>
==== 3. Scanner une machine ====
<syntaxhighlight lang="bash" line>
nmap 192.168.0.72
</syntaxhighlight>
==== 4. Scanner une machine plus en détail ====
:On peut en plus activer la détection du système d'exploitation et des versions dans la commande précédente an ajoutant le flag -A:
<syntaxhighlight lang="bash" line>
nmap -A 192.168.0.72
</syntaxhighlight>
:Si maintenant on scanne la Box Internet:
<syntaxhighlight lang="bash" line>
nmap -A 192.168.0.254
</syntaxhighlight>
==== 5. Accélérer le scan de la machine ====
:Le précédent scan ayant duré 17mn, on va essayer d'obtenir un résultat plus rapidement en changeant la politique de temporisation de nmap:
<syntaxhighlight lang="bash" line>
nmap -A -T5 192.168.0.254
</syntaxhighlight>


=== Réseaux ===
=== Heure ===
<pre>
#serveurs NTP
#Fichier de configuration des serveurs NTP : /etc/systemd/timesyncd.conf
#Permet la synchronisation NTP même si aucun serveur DNS n’est joignable :
#NTP=145.238.203.14 145.238.203.10


voir les ip du reseaux et le mac adress
#Vérifier la prise en compte du serveur avec
<span style="color: red;font-weight:bold;">arp</span>
systemctl status systemd-timesyncd.service
Pour voir les DNS en cours
timedatectl status
<span style="color: red;font-weight:bold;">cat /etc/resolv.conf</span>
timedatectl set-timezone "Europe/Paris"
<span style="color: red;font-weight:bold;">dig pi-hole.net @127.0.0.1 -p 53</span>
timedatectl set-ntp true
table de routage (IPv4/IPv6)
</pre>
<span style="color: red;font-weight:bold;">ip route</span>
* [https://www.jbnet.fr/systeme/raspbian/raspberry-pi-installation-mode-serveur.html www.jbnet.fr]
Vérification des interfaces
<span style="color: red;font-weight:bold;">ifconfig</span>
Lister les ports ouverts et les services réseaux en écoute sur son serveur Linux grâce à netstat.
<span style="color: red;font-weight:bold;">netstat -lntup</span>
Lister tous les ports :
<span style="color: red;font-weight:bold;">netstat -a</span>
Lister tous les ports TCP :
<span style="color: red;font-weight:bold;">netstat -at</span>
Lister tous les ports UDP :
<span style="color: red;font-weight:bold;">netstat -au</span>
Lister tous les ports en écoute :
<span style="color: red;font-weight:bold;">netstat -l</span>
Lister uniquement les ports TCP en écoutes :
<span style="color: red;font-weight:bold;">netstat -lt</span>
Lister uniquement les ports UDP en écoutes :
<span style="color: red;font-weight:bold;">netstat -lu</span>
Afficher les statistique de tous les ports :
<span style="color: red;font-weight:bold;">netstat -s</span>
Affichier les statistique des Port TCP :
<span style="color: red;font-weight:bold;">netstat -st</span>
Affichier les statistique des Port UDP :
<span style="color: red;font-weight:bold;">netstat -su</span>
Affiche le nom du programme et le PID associé :
Cette commande est très utile lorsque vous souhaitez connaitre quel programme est exécuté sur un port particulier.
<span style="color: red;font-weight:bold;">netstat -p</span>
Afficher directement les IP et pas de résolution de nom :
Pour afficher toutes les connexions et tous les ports en écoute mais n’affiche que les adresses IP sans la résolutions des noms.
<span style="color: red;font-weight:bold;">netstat -an</span>
Affiche le numéro d’identification des processus (PID) associé à chaque connexion :
<span style="color: red;font-weight:bold;">netstat -o</span>
Afficher la table de routage IPV4 et IP6 :
<span style="color: red;font-weight:bold;">netstat -r</span>
Affichage à un interval de temps régulier en seconde :
netstat -t “temps en seconde” ( Exemple : netstat -t 5 )
<span style="color: red;font-weight:bold;">netstat -t 5</span>


1. Lister les machines à explorer
=== Voir version installé ===
Cette commande va se contenter de lister les machines que nmap explorerait sur le réseau en question.
<pre>
La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
Sur les systèmes similaires à Debian, dans le dossier /proc :
<span style="color: red;font-weight:bold;">nmap -sL 192.168.0.1/24</span>
“cpuinfo” contient des informations sur votre processeur.
“meminfo” concerne la RAM.
</pre>


2. Scanner les machines du réseau
=== Bande passante ===
On va maintenant passer la même commande en faisant un ping sur chaque machine.
vnStat est un outil de surveillance du trafic réseau  
<span style="color: red;font-weight:bold;">nmap -sP 192.168.0.1/24</span>
<syntaxhighlight lang="bash" line copy>
vnstat -l -ru # Affiche les unités adaptées (Ko, Mo, etc.).
</syntaxhighlight>


3. Scanner une machine
<syntaxhighlight lang="bash" line>
<span style="color: red;font-weight:bold;">nmap 192.168.0.72</span>
vnstat -l  #Bande passante en temps réel
vnstat #Affiche le résumé du trafic.
vnstat -d #Affiche les stats journalières.
vnstat -m #Affiche les stats mensuelles.
vnstat -h #Affiche les stats horaires.
vnstat -i eth0 #Spécifie une interface.
vnstati -s -i eth0 -o /tmp/stats.png #Génère un graphique.
</syntaxhighlight>


4. Scanner une machine plus en détail
On peut en plus activer la détection du système d'exploitation et des versions dans la commande précédente an ajoutant le flag -A:
<span style="color: red;font-weight:bold;">nmap -A 192.168.0.72</span>


Si maintenant on scanne la Box Internet:
Nethogs indique quels processus consomment de la bande passante, ce qui est très utile pour diagnostiquer des applications gourmandes en réseau.
<span style="color: red;font-weight:bold;">nmap -A 192.168.0.254</span>
<syntaxhighlight lang="bash" line copy>
sudo nethogs
</syntaxhighlight>


5. Accélérer le scan de la machine
<syntaxhighlight lang="bash" line>
Le précédent scan ayant duré 17mn, on va essayer d'obtenir un résultat plus rapidement en changeant la politique de temporisation de nmap:
sudo nethogs #Surveille toutes les interfaces.
<span style="color: red;font-weight:bold;">nmap -A -T5 192.168.0.254</span>
sudo nethogs eth0 #Cible une interface spécifique.
sudo nethogs -d 2 #Rafraîchit toutes les 2 secondes (par défaut: 1s).
sudo nethogs -v 3 #Mode verbeux (détails techniques).
sudo nethogs -p #Mode "promiscuité" (écoute tout le trafic, même non destiné à la machine).
</syntaxhighlight>


m : Change l'unité (KB/s → MB/s → B/s).
[[Catégorie: Raspian]]
[[Catégorie: Raspian]]