« Raspbian Commandes » : différence entre les versions

(28 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>
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 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 :
<span style="color: red;font-weight:bold;">sudo apt update (mise à jour de '''la liste''' des paquets) </span>
<span style="color: red;font-weight:bold;">sudo apt list --upgradable (pour voir ce qui doit être mis à jour) </span>
<span style="color: red;font-weight:bold;">sudo apt install --only-upgrade firefox </span>
<span style="color: red;font-weight:bold;">sudo apt-get --with-new-pkgs upgrade </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>
 
sudo aptitude update
aptitude search '~U'
sudo aptitude upgrade


=== Redémarrer unbound ===
=== Redémarrer unbound ===
<span style="color: red;font-weight:bold;">sudo service unbound restart</font>
<syntaxhighlight lang="bash" line copy>
sudo service unbound restart
</syntaxhighlight>


=== Lighttpd ===
=== DHCPCD (static ip_address) ===
<span style="color: red;font-weight:bold;">sudo service lighttpd status</span>
<pre>
<span style="color: red;font-weight:bold;">sudo service lighttpd restart</span>
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.
==== vhost ====
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.
<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>
</pre>
*voir:[https://www.jesus-forain.fr/blog/configuration-de-dhcpcd-52.html Configuration de DHCPCD]


=== Pihole ===
<syntaxhighlight lang="bash" line copy>
#update pihole
sudo service dhcpcd status
<span style="color: red;font-weight:bold;">pihole -up</span>
</syntaxhighlight>
/etc/dhcpcd.conf


==== Black Lists ====
<syntaxhighlight lang="bash" line copy>
[https://fleuryk.kappatau.fr/pihole-blocklist/ pihole-blocklist]
dhcpcd man
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/ParsedBlacklists/Block-EU-Cookie-Shit-List.txt
</syntaxhighlight>
* https://raw.githubusercontent.com/deathbybandaid/piholeparser/master/Subscribable-Lists/CountryCodesLists/France.txt
* https://easylist-downloads.adblockplus.org/liste_fr%2Beasylist.txt
* https://blocklist.site/app/dl/malware
* https://blocklist.site/app/dl/ransomware
* https://blocklist.site/app/dl/phishing
* https://blocklist.site/app/dl/ads
* https://gist.githubusercontent.com/BBcan177/4a8bf37c131be4803cb2/raw/343ff780e15205b4dd0de37c86af34cfb26b2fbe/MS-2
* https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt
* https://blocklist.site/app/dl/spam
* https://hosts.ubuntu101.co.za/domains.list
* https://hosts.ubuntu101.co.za/ips.list


=== PiVpn ===
<pre>
#ajouter un client vpn
static value
  <span style="color: red;font-weight:bold;">pivpn add nopass</span>
            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
  #pour voir qui est connecté
            set ip6_address, dhcpcd will continue auto-configuration as normal.
<span style="color: red;font-weight:bold;">pivpn clients</span>
==== upgrading ====
*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]
            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


=== Réseaux ===
            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>


voir les ip du reseaux et le mac adress
=== Lighttpd ===
<span style="color: red;font-weight:bold;">arp</span>
<syntaxhighlight lang="bash" line copy>
Pour voir les DNS en cours
sudo service lighttpd status
<span style="color: red;font-weight:bold;">cat /etc/resolv.conf</span>
sudo service lighttpd restart
<span style="color: red;font-weight:bold;">dig pi-hole.net @127.0.0.1 -p 53</span>
</syntaxhighlight>
table de routage (IPv4/IPv6)
==== vhost ====
<span style="color: red;font-weight:bold;">ip route</span>
<syntaxhighlight lang="bash" line copy>
<span style="color: red;font-weight:bold;">iip -6 neigh show</span>
ln -s /etc/lighttpd/conf-available/91-exemple.com.conf /etc/lighttpd/conf-enabled/91-exemple.com.conf
Vérification des interfaces
</syntaxhighlight>
<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
=== Commandes Réseaux ===
Cette commande va se contenter de lister les machines que nmap explorerait sur le réseau en question.
<syntaxhighlight lang="bash" line>
La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
# voir les ip du reseaux et le mac adress
<span style="color: red;font-weight:bold;">nmap -sL 192.168.0.1/24</span>
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>


2. Scanner les machines du réseau
==== 1. Lister les machines à explorer ====
On va maintenant passer la même commande en faisant un ping sur chaque machine.
: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;">nmap -sP 192.168.0.1/24</span>
:La valeur 24 indique que les trois premières valeurs sont fixes et que seule la dernière va varier.
<syntaxhighlight lang="bash" line>
nmap -sL 192.168.0.1/24
</syntaxhighlight>
==== 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>


3. Scanner une machine
=== Heure ===
<span style="color: red;font-weight:bold;">nmap 192.168.0.72</span>
<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


4. Scanner une machine plus en détail
#Vérifier la prise en compte du serveur avec
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:
systemctl status systemd-timesyncd.service
<span style="color: red;font-weight:bold;">nmap -A 192.168.0.72</span>
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]


Si maintenant on scanne la Box Internet:
=== Voir version installé ===
<span style="color: red;font-weight:bold;">nmap -A 192.168.0.254</span>
<pre>
 
Sur les systèmes similaires à Debian, dans le dossier /proc :
5. Accélérer le scan de la machine
“cpuinfo” contient des informations sur votre processeur.
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:
“meminfo” concerne la RAM.
<span style="color: red;font-weight:bold;">nmap -A -T5 192.168.0.254</span>
</pre>


[[Catégorie: Raspian]]
[[Catégorie: Raspian]]