all:bibles:linux:reseau:02-configuration
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| all:bibles:linux:reseau:02-configuration [2025/01/29 16:33] – [Configuration via fichiers] omeylhoc | all:bibles:linux:reseau:02-configuration [2025/02/19 10:30] (Version actuelle) – [IP statique] omeylhoc | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== Configuration IP ====== | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== netplan (à partir d' | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | < | ||
| + | « Serveur » avec systemd-networkd | ||
| + | « Cloud Image » avec systemd-networkd : 50-cloud-init.yaml\\ | ||
| + | « Desktop » avec NetworkManager | ||
| + | </ | ||
| + | |||
| + | ==== DHCP ==== | ||
| + | |||
| + | <color # | ||
| + | <code yaml> | ||
| + | network: | ||
| + | ethernets: | ||
| + | ens160: | ||
| + | dhcp4: true | ||
| + | version: 2 | ||
| + | </ | ||
| + | |||
| + | ==== DHCP avec bonding ==== | ||
| + | |||
| + | <color # | ||
| + | |||
| + | <code yaml> | ||
| + | bonds: | ||
| + | bond0: | ||
| + | dhcp4: yes | ||
| + | interfaces: | ||
| + | - enp3s0 | ||
| + | - enp4s0 | ||
| + | parameters: | ||
| + | mode: active-backup | ||
| + | primary: enp3s0 | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | Voir cette [[https:// | ||
| + | |||
| + | === Basculement bond0 sur eth1 === | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt-get install ifenslave | ||
| + | ifenslave -c bond0 eth1 | ||
| + | </ | ||
| + | |||
| + | ==== IP statique ==== | ||
| + | |||
| + | <color # | ||
| + | <code yaml> | ||
| + | network: | ||
| + | ethernets: | ||
| + | ens160: | ||
| + | dhcp4: false | ||
| + | addresses: | ||
| + | - 10.35.130.71/ | ||
| + | routes: | ||
| + | - to: default | ||
| + | via: 10.35.130.126 | ||
| + | nameservers: | ||
| + | addresses: | ||
| + | - 8.8.8.8 | ||
| + | - 8.8.4.4 | ||
| + | search: [] | ||
| + | version: 2 | ||
| + | </ | ||
| + | |||
| + | ==== IP statique avec VLAN ==== | ||
| + | |||
| + | <color # | ||
| + | |||
| + | <code yaml> | ||
| + | network: | ||
| + | version: 2 | ||
| + | ethernets: | ||
| + | ens3: | ||
| + | addresses: | ||
| + | - 192.168.122.201/ | ||
| + | routes: | ||
| + | - to: default | ||
| + | via: 192.168.122.1 | ||
| + | nameservers: | ||
| + | addresses: [192.168.122.1] | ||
| + | ens8: {} | ||
| + | |||
| + | vlans: | ||
| + | vlan.101: | ||
| + | id: 101 | ||
| + | link: ens8 | ||
| + | addresses: [192.168.101.1/ | ||
| + | vlan.102: | ||
| + | id: 102 | ||
| + | link: ens8 | ||
| + | addresses: [192.168.102.1/ | ||
| + | </ | ||
| + | |||
| + | ==== Network Manager ==== | ||
| + | |||
| + | <color # | ||
| + | |||
| + | <code yaml> | ||
| + | network: | ||
| + | version: 2 | ||
| + | renderer: NetworkManager | ||
| + | </ | ||
| + | |||
| + | === Désactivation === | ||
| + | |||
| + | Editer le fichier **/ | ||
| + | |||
| + | < | ||
| + | [main] | ||
| + | plugins=ifupdown, | ||
| + | |||
| + | [ifupdown] | ||
| + | managed=true | ||
| + | |||
| + | [device] | ||
| + | wifi.scan-rand-mac-address=no | ||
| + | </ | ||
| + | |||
| + | ==== Prise en compte ==== | ||
| + | |||
| + | <code bash> | ||
| + | sudo netplan try # test une nouvelle configuration pour un temps donné | ||
| + | sudo netplan apply # prise en compte nouvelle configuration | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== Avant Ubuntu 18.04 ===== | ||
| + | |||
| + | ==== Configuration manuelle ==== | ||
| + | |||
| + | <code bash> | ||
| + | sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0 | ||
| + | sudo route add default gw 10.0.0.1 eth0 | ||
| + | </ | ||
| + | |||
| + | Modifier le fichier **/ | ||
| + | |||
| + | Pour effacer la conf : | ||
| + | |||
| + | <code bash> | ||
| + | ip addr flush eth0 | ||
| + | </ | ||
| + | |||
| + | ==== IP statique ==== | ||
| + | |||
| + | <color # | ||
| + | |||
| + | < | ||
| + | auto lo | ||
| + | iface lo inet loopback | ||
| + | |||
| + | auto enp1s0 | ||
| + | iface enp1s0 inet static | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | <note tip>Pour un démarrage plus rapide sans attendre le réseau préférer **allow-hotplug enp1s0** à la place de **auto enp1s0**</ | ||
| + | |||
| + | ==== DHCP ==== | ||
| + | | ||
| + | <color # | ||
| + | |||
| + | < | ||
| + | auto lo | ||
| + | iface lo inet loopback | ||
| + | |||
| + | auto enp1s0 | ||
| + | iface enp1s0 inet dhcp | ||
| + | </ | ||
| + | |||
| + | ==== Network Manager ==== | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | <color # | ||
| + | |||
| + | < | ||
| + | [802-3-ethernet] | ||
| + | duplex=full | ||
| + | mac-address=00: | ||
| + | |||
| + | [connection] | ||
| + | id=Wired connection 4 | ||
| + | uuid=99f48bd3-f1fd-43e5-8dce-6e8f020d8560 | ||
| + | type=802-3-ethernet | ||
| + | timestamp=1531129513 | ||
| + | |||
| + | [ipv6] | ||
| + | method=auto | ||
| + | |||
| + | [ipv4] | ||
| + | method=manual | ||
| + | dns=10.1.2.11; | ||
| + | address1=10.1.242.67/ | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== DHCP Client Daemon (Debian) ===== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== IPV6 ===== | ||
| + | |||
| + | ==== Désactivation IPV6 ==== | ||
| + | |||
| + | === Temporairement === | ||
| + | |||
| + | <code bash> | ||
| + | sysctl -w net.ipv6.conf.all.disable_ipv6=1 | ||
| + | sysctl -w net.ipv6.conf.default.disable_ipv6=1 | ||
| + | sysctl -w net.ipv6.conf.lo.disable_ipv6=1 | ||
| + | </ | ||
| + | |||
| + | === Persistant === | ||
| + | |||
| + | * Ajouter les lignes suivantes à la fin du fichier <color # | ||
| + | |||
| + | <code bash> | ||
| + | net.ipv6.conf.all.disable_ipv6=1 | ||
| + | net.ipv6.conf.default.disable_ipv6=1 | ||
| + | net.ipv6.conf.lo.disable_ipv6 = 1 | ||
| + | </ | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | * Redémarrer la machine | ||
| + | * Vérifier l' | ||
| + | * En cas de problème vérifier les valeurs en mémoire : | ||
| + | |||
| + | <code bash> | ||
| + | cat / | ||
| + | cat / | ||
| + | cat / | ||
| + | </ | ||
| + | |||
| + | === Persistant via Grub === | ||
| + | |||
| + | * Editer le fichier <color # | ||
| + | |||
| + | <code bash> | ||
| + | GRUB_DEFAULT=0 | ||
| + | GRUB_TIMEOUT_STYLE=hidden | ||
| + | GRUB_TIMEOUT=0 | ||
| + | GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` | ||
| + | GRUB_CMDLINE_LINUX_DEFAULT=" | ||
| + | GRUB_CMDLINE_LINUX="" | ||
| + | </ | ||
| + | |||
| + | * Regénérer la configuration Grub. | ||
| + | |||
| + | <code bash> | ||
| + | sudo update-grub | ||
| + | </ | ||
| + | |||
| + | * Redémarrer la machine. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== Commandes usuelles ===== | ||
| + | |||
| + | ==== Interroger ses adresses IP ==== | ||
| + | |||
| + | <code bash> | ||
| + | hostname -i | ||
| + | </ | ||
| + | |||
| + | ==== Prise en compte modifications ==== | ||
| + | |||
| + | === A partir d' | ||
| + | |||
| + | <code bash> | ||
| + | sudo netplan apply | ||
| + | </ | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | === A partir d' | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl restart networking | ||
| + | </ | ||
| + | |||
| + | === Avant Ubuntu 16.04 === | ||
| + | |||
| + | <code bash> | ||
| + | sudo service networking restart | ||
| + | </ | ||
| + | |||
| + | === Network manager === | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl restart NetworkManager | ||
| + | </ | ||
| + | |||
| + | ==== Renouvellement adresse IP en DHCP ==== | ||
| + | |||
| + | < | ||
| + | dhclient –r eth1 ⇒ force le client à libérer l' | ||
| + | dhclient –d eth1 ⇒ Récupérer une adresse IP auprès du serveur DHCP | ||
| + | </ | ||
| + | |||
| + | ==== Remplacement commandes réseau ==== | ||
| + | |||
| + | | arp | ip neigh | | ||
| + | | ifconfig | ||
| + | | iptunnel | ||
| + | | iwconfig | ||
| + | | nameif | ||
| + | | netstat | ||
| + | | ::: | ss | | ||
| + | | route | ip route | | ||
| + | |||
| + | ==== Commandes IP V6 ==== | ||
| + | |||
| + | | ping6 | | ||
| + | | nslookup -type aaaa domain.fr | ||
| + | | netstat -A inet6 -nr | | ||
| + | | service ip6tables stop | | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== Wifi ===== | ||
| + | |||
| + | ==== Configuration manuelle ==== | ||
| + | |||
| + | === Liste les réseaux sans fil sur l’interface wlan0 === | ||
| + | |||
| + | <code bash> | ||
| + | sudo iwlist wlan0 scan | egrep 'Cell |Encryption|Quality|Last beacon|ESSID' | ||
| + | </ | ||
| + | |||
| + | === Liste les réseau sans fil avec la puissance du signal sur l’interface wlan0 === | ||
| + | |||
| + | <code bash> | ||
| + | sudo iw dev wlan0 scan | egrep " | ||
| + | </ | ||
| + | | ||
| + | === Configure l’interface wlan0 pour se connecter sur le réseau dont le ssid est SSID === | ||
| + | |||
| + | <code bash> | ||
| + | sudo iwconfig wlan0 essid < | ||
| + | </ | ||
| + | |||
| + | === Obtient une adresse via DHCP sur l’interface wlan0 === | ||
| + | |||
| + | <code bash> | ||
| + | udhcpc –i wlan0 | ||
| + | </ | ||
| + | |||
| + | ==== Configuration via fichiers ==== | ||
| + | |||
| + | * Créer ou éditer le fichier <color # | ||
| + | |||
| + | < | ||
| + | ctrl_interface=/ | ||
| + | update_config=1 | ||
| + | |||
| + | network={ | ||
| + | ssid=" | ||
| + | psk=" | ||
| + | key_mgmt=WPA-PSK | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | * Possibilité de masquer la clef en la remplaçant par le résultat généré par la commande | ||
| + | |||
| + | <code bash> | ||
| + | wpa_passphrase " | ||
| + | </ | ||
| + | |||
| + | * Modifier les droits d' | ||
| + | |||
| + | <code bash> | ||
| + | sudo chmod 0600 / | ||
| + | </ | ||
| + | |||
| + | * Créer un fichier de configuration sous <color # | ||
| + | |||
| + | === DHCP === | ||
| + | |||
| + | < | ||
| + | auto wlan0 | ||
| + | allow-hotplug wlan0 | ||
| + | iface wlan0 inet dhcp | ||
| + | wpa-conf / | ||
| + | </ | ||
| + | |||
| + | === IP statique === | ||
| + | |||
| + | < | ||
| + | auto wlan0 | ||
| + | allow-hotplug wlan0 | ||
| + | iface wlan0 inet static | ||
| + | address <@IP> | ||
| + | netmask < | ||
| + | gateway <@IP gateway> | ||
| + | dns-nameservers <@IP DNS> | ||
| + | wpa-conf / | ||
| + | </ | ||
| + | |||
| + | * Arrêter les services | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl stop NetworkManager | ||
| + | sudo systemctl stop wpa_supplicant | ||
| + | sudo systemctl stop networking | ||
| + | </ | ||
| + | |||
| + | * Redémarrer les services en respectant l' | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl start networking | ||
| + | sudo systemctl start wpa_supplicant | ||
| + | sudo systemctl start NetworkManager | ||
| + | </ | ||
| + | |||
| + | ==== Optimisation ==== | ||
| + | |||
| + | Afin d' | ||
| + | Pour rechercher le meilleur canal on peut utiliser le logiciel [[https:// | ||
| + | |||
| + | === Installation === | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt-get install linssid | ||
| + | </ | ||
| + | |||
| + | === Utilisation === | ||
| + | |||
| + | Lancer l' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== Autres fichiers de configuration ===== | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | Nom de la machine que l'on retrouve avec la commande : | ||
| + | |||
| + | <code bash> | ||
| + | uname -n | ||
| + | </ | ||
| + | | ||
| + | === Changement du hostname === | ||
| + | |||
| + | <code bash> | ||
| + | hostnamectl set-hostname <nouveau nom> | ||
| + | </ | ||
| + | |||
| + | La modification peut être réalisé manuellement par : | ||
| + | |||
| + | * Mise à jour du fichier <color # | ||
| + | * Mise à jour du fichier <color # | ||
| + | * Redémarrage de la machine | ||
| + | |||
| + | ==== /etc/ethers ==== | ||
| + | |||
| + | Fichier dans lequel on peut renseigner une liste d' | ||
| + | |||
| + | ==== /etc/host ==== | ||
| + | |||
| + | Liste des hosts pour résolution DNS. | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | Nom du serveur DNS et du nom de domaine par défaut. | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | Quelques paramètres de configuration. | ||
| + | |||
| + | === Activation IP forwarding === | ||
| + | |||
| + | net.ipv4.ip_forward = 1 | ||
| + | |||
| + | <code bash> | ||
| + | sudo sysctl -w net.ipv4.ip_forward=1 | ||
| + | </ | ||
| + | |||
| + | === Protection contre les attaques === | ||
| + | |||
| + | net/ | ||
| + | net/ | ||
| + | net/ | ||
| + | net/ | ||
| + | net/ | ||
| + | |||
| + | <note tip>Les valeurs courantes peuvent être interrogées et modifiées dans\\ / | ||
| + | |||
| + | ==== / | ||
| + | |||
| + | Fichier de configuration du client DNS. Pour choisir son serveur DNS ajouter la ligne suivante en séparant les adresses par une virgule : | ||
| + | |||
| + | < | ||
| + | supersede domain-name-servers @IP1,@IP2; | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
| + | |||
| + | ===== Redhat/ | ||
| + | |||
| + | ==== Configuration adresse IP ==== | ||
| + | |||
| + | === adresse IP fixe === | ||
| + | |||
| + | <color # | ||
| + | |||
| + | < | ||
| + | TYPE=" | ||
| + | PROXY_METHOD=" | ||
| + | BROWSER_ONLY=" | ||
| + | BOOTPROTO=" | ||
| + | DEFROUTE=" | ||
| + | IPV4_FAILURE_FATAL=" | ||
| + | IPV6INIT=" | ||
| + | NAME=" | ||
| + | DEVICE=" | ||
| + | ONBOOT=" | ||
| + | PREFIX=27 | ||
| + | IPADDR=10.1.242.87 | ||
| + | GATEWAY=10.1.242.94 | ||
| + | HWADDR=" | ||
| + | DNS1=10.1.2.11 | ||
| + | DNS2=10.1.2.12 | ||
| + | </ | ||
| + | |||
| + | === DHCP === | ||
| + | |||
| + | <color # | ||
| + | |||
| + | < | ||
| + | DEVICE=" | ||
| + | BOOTPROTO=" | ||
| + | HWADDR=" | ||
| + | NM_CONTROLLED=" | ||
| + | ONBOOT=" | ||
| + | TYPE=" | ||
| + | </ | ||
| + | |||
| + | ==== Prise en compte des modifications ==== | ||
| + | |||
| + | <code bash> | ||
| + | systemctl restart network | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Dépannage ===== | ||
| + | |||
| + | ==== Changement Hostname après reboot ==== | ||
| + | |||
| + | === Problème === | ||
| + | |||
| + | Après avoir changé le hostname la valeur revient à sa valeur précédente après redémarrage. | ||
| + | |||
| + | === Solution 1 === | ||
| + | |||
| + | * Désinstaller cloud-init définitivement | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt purge cloud-init cloud-initramfs-copymods cloud-initramfs-dyn-netconf | ||
| + | </ | ||
| + | |||
| + | === Solution 2 === | ||
| + | |||
| + | * Effacer la conf cloud-init | ||
| + | |||
| + | <code bash> | ||
| + | sudo cloud-init clean | ||
| + | </ | ||
| + | |||
| + | * Réinitialiser la conf cloud-init à partir de l' | ||
| + | |||
| + | <code bash> | ||
| + | sudo cloud-init init | ||
| + | </ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ---- | ||
| + | |||
| + | [[all: | ||
