Adresse IP fixe pour serveur (sans DHCP)

Comment fixer l’adresse IP d’un serveur sous Debian Linux

Etape 0 : Se connecter sur la console du serveur

Etape 1 : Quelle est l »adresse IP et le nom de l’interface réseau ? (« eth0 » ou « eno1 » …)

# ifconfig
eth0 Link encap:Ethernet HWaddr c0:3f:d5:64:05:b6 
inet adr:192.168.0.23 Bcast:192.168.0.255 Masque:255.255.255.0
adr inet6: fe80::c23f:d5ff:fe64:5b6/64 Scope:Lien
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9052 errors:0 dropped:0 overruns:0 frame:0
TX packets:6334 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000 
RX bytes:864506 (844.2 KiB) TX bytes:7192121 (6.8 MiB)
Interruption:20 Mémoire:f7c00000-f7c20000

lo Link encap:Boucle locale 
inet adr:127.0.0.1 Masque:255.0.0.0
adr inet6: ::1/128 Scope:Hôte
...

Etape 2 : Arrêter le service Réseau  (sauf si on est en ssh .. loin du serveur !)

# service networking stop

Etape 3 : Fixer l’adresse IP dans un ou plusieurs fichiers

# cp /etc/network/interfaces /etc/network/interfaces.old
# nano /etc/network/interfaces
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

#iface eth0 inet dhcp
# This is an autoconfigured IPv6 interface
#iface eth0 inet6 auto

### Adresse IP Fixe / Statique
# The primary network interface
allow-hotplug eno1
#iface eno1 inet dhcp
iface eno1 inet static
address 192.168.0.106
broadcast 192.168.0.255
netmask 255.255.255.0 
gateway 192.168.0.1

Solution testée OK sur mon NUC en janvier 2019

Etape finale : Appliquer le changement

# service networking restart  (sauf si on est en ssh .. loin du serveur !)
# reboot

The second and recommended option is to define your network interfaces separately within /etc/network/interfaces.d/ directory.

During the networking daemon initiation the /etc/network/interfaces.d/ directory is searched for network interface configurations. Any found network configuration is included as part of the /etc/network/interfaces.

Create a new network configuration file with any arbitrary file name eg. eth0 and include the eth0 IP address configuration shown below. To do this use your preferred text editor for example vim:

# cat /etc/network/interfaces.d/eth0
iface eth0 inet static
address 192.168.0.123 
netmask 255.255.255.0 
gateway 192.168.0.1

Now, remove the above lines stated from /etc/network/interfaces so you will end up with:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0