« Raspbian Commandes » : différence entre les versions

 
(32 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>
<syntaxhighlight lang="bash" line copy>
# Sauvegarde
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


<code>sudo /etc/init.d/firewall status</code>
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">sudo update-rc.d firewall defaults</span>
sudo /etc/init.d/firewall status
démarrer un deamon -> http://manpages.ubuntu.com/manpages/trusty/fr/man8/update-rc.d.8.html
</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]]


#mettre à jour un paquet :
=== Redémarrer unbound ===
<span style="color: red;font-weight:bold;">sudo apt update (mise à jour de '''la liste''' des paquets) </span>
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">sudo apt list --upgradable (pour voir ce qui doit être mis à jour) </span>
sudo service unbound restart
<span style="color: red;font-weight:bold;">sudo apt install --only-upgrade firefox </span>
</syntaxhighlight>
<span style="color: red;font-weight:bold;">sudo apt-get --with-new-pkgs upgrade </span>


#voir tous les paquets
=== DHCPCD (static ip_address) ===
<span style="color: red;font-weight:bold;">dpkg --list</span>
<pre>
#voir si un paquet est à jour
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.
<span style="color: red;font-weight:bold;">apt-cache policy firefox</span>
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]


sudo aptitude update
<syntaxhighlight lang="bash" line copy>
aptitude search '~U'
sudo service dhcpcd status
sudo aptitude upgrade
</syntaxhighlight>
/etc/dhcpcd.conf


=== Redémarrer unbound ===
<syntaxhighlight lang="bash" line copy>
  <span style="color: red;font-weight:bold;">sudo service unbound restart</font>
dhcpcd man
</syntaxhighlight>
 
<pre>
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.
 
            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
            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
 
            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 ===
=== Lighttpd ===
<span style="color: red;font-weight:bold;">sudo service lighttpd status</span>
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">sudo service lighttpd restart</span>
sudo service lighttpd status
sudo service lighttpd restart
</syntaxhighlight>
==== vhost ====
==== vhost ====
<span style="color: red;font-weight:bold;">ln -s /etc/lighttpd/conf-available/91-exemple.com.conf /etc/lighttpd/conf-enabled/91-exemple.com.conf</span>
<syntaxhighlight lang="bash" line copy>
ln -s /etc/lighttpd/conf-available/91-exemple.com.conf /etc/lighttpd/conf-enabled/91-exemple.com.conf
</syntaxhighlight>


=== Pihole ===
=== Commandes Réseaux ===
#update pihole
<syntaxhighlight lang="bash" line>
<span style="color: red;font-weight:bold;">pihole -up</span>
# voir les ip du reseaux et le mac adress
arp
# Pour voir les DNS en cours
# cat /etc/resolv.conf
dig pi-hole.net @127.0.0.1 -p 53
# table de routage (IPv4/IPv6)
ip route
iip -6 neigh show
# Vérification des interfaces
ifconfig
# Lister les ports ouverts et les services réseaux en écoute sur son serveur Linux grâce à netstat.
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>


==== Black Lists ====
==== 1. Lister les machines à explorer ====
[https://fleuryk.kappatau.fr/pihole-blocklist/ pihole-blocklist]
:Cette commande va se contenter de lister les machines que nmap explorerait sur le réseau en question.
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/ParsedBlacklists/Block-EU-Cookie-Shit-List.txt
:La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/CountryCodesLists/France.txt
<syntaxhighlight lang="bash" line>
* https://easylist-downloads.adblockplus.org/liste_fr%2Beasylist.txt
nmap -sL 192.168.0.1/24
* https://blocklist.site/app/dl/malware
</syntaxhighlight>
* https://blocklist.site/app/dl/ransomware
==== 2. Scanner les machines du réseau ====
* https://blocklist.site/app/dl/phishing
:On va maintenant passer la même commande en faisant un ping sur chaque machine.
* https://blocklist.site/app/dl/ads
<syntaxhighlight lang="bash" line>
* https://gist.githubusercontent.com/BBcan177/4a8bf37c131be4803cb2/raw/343ff780e15205b4dd0de37c86af34cfb26b2fbe/MS-2
nmap -sP 192.168.0.1/24
* https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt
</syntaxhighlight>
* https://blocklist.site/app/dl/spam
==== 3. Scanner une machine ====
* https://hosts.ubuntu101.co.za/domains.list
<syntaxhighlight lang="bash" line>
* https://hosts.ubuntu101.co.za/ips.list
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>


=== PiVpn ===
=== Heure ===
#ajouter un client vpn
<pre>
<span style="color: red;font-weight:bold;">pivpn add nopass</span>
#serveurs NTP
#pour voir qui est connecté
#Fichier de configuration des serveurs NTP : /etc/systemd/timesyncd.conf
<span style="color: red;font-weight:bold;">pivpn clients</span>
#Permet la synchronisation NTP même si aucun serveur DNS n’est joignable :
==== upgrading ====
#NTP=145.238.203.14 145.238.203.10
*mise à jour : [https://github.com/pivpn/pivpn/wiki/Upgrading pivpn/wiki/Upgrading]<br>


*Voir la version en cours d'openvpn disponible pour le raspberry : [https://packages.debian.org/search?arch=armhf&keywords=openvpn debian dépot armhf]
#Vérifier la prise en compte du serveur avec
systemctl status systemd-timesyncd.service
timedatectl status
timedatectl set-timezone "Europe/Paris"
timedatectl set-ntp true
</pre>
* [https://www.jbnet.fr/systeme/raspbian/raspberry-pi-installation-mode-serveur.html www.jbnet.fr]


=== Réseaux ===
=== Voir version installé ===
 
<pre>
voir les ip du reseaux et le mac adress
Sur les systèmes similaires à Debian, dans le dossier /proc :
<span style="color: red;font-weight:bold;">arp</span>
“cpuinfo” contient des informations sur votre processeur.
Pour voir les DNS en cours
“meminfo” concerne la RAM.
<span style="color: red;font-weight:bold;">cat /etc/resolv.conf</span>
</pre>
<span style="color: red;font-weight:bold;">dig pi-hole.net @127.0.0.1 -p 53</span>
table de routage (IPv4/IPv6)
<span style="color: red;font-weight:bold;">ip route</span>
<span style="color: red;font-weight:bold;">iip -6 neigh show</span>
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
Cette commande va se contenter de lister les machines que nmap explorerait sur le réseau en question.
La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
<span style="color: red;font-weight:bold;">nmap -sL 192.168.0.1/24</span>


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]]