web-dev-qa-db-fra.com

Comment définir une passerelle par défaut dans Ubuntu Server 18.04 avec NetPlan

J'ai une seule interface réseau sur ce serveur nommé ENP2S0 Cette interface avait une adresse statique 192.168.2.xxx avec passerelle 192.168.2.1 Maintenant, j'ai modifié l'adresse statique dans le fichier YAML en 192.168.1.xxx et la passerelle également en 192.168.1.1. Mais chaque fois que je redémarre le serveur, la passerelle par défaut revient à 192.168.2.1 J'ai essayé de lancer l'itinéraire Commmand pour supprimer la passerelle par défaut et définir le nouveau mais si je redémarre le serveur, il revient à 192.168.2.1

This is the yaml config file

    # This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
        enp2s0:
            addresses: [192.168.1.10/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [1.1.1.1,1.0.0.1]

Sortie de l'état NetworkCtL ENP2S0 après le redémarrage

 2: enp2s0
       Link File: /lib/systemd/network/99-default.link
    Network File: /run/systemd/network/10-netplan-enp2s0.network
            Type: ether
           State: routable (configured)
            Path: pci-0000:02:00.0
          Driver: r8169
          Vendor: Realtek Semiconductor Co., Ltd.
           Model: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (M4A
      HW Address: 48:5b:39:02:41:c9 (ASUSTek COMPUTER INC.)
         Address: 192.168.1.10
                  192.168.2.100
                  fe80::4a5b:39ff:fe02:41c9
         Gateway: 192.168.2.1
             DNS: 1.1.1.1
                  1.0.0.1

Sortie de la commande de route après le redémarrage

Tabella di routing IP del kernel
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.2.1     0.0.0.0         UG    202    0        0 enp2s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp2s0
192.168.2.0     0.0.0.0         255.255.255.0   U     202    0        0 enp2s0

Résultat du statut NetworkCtL ENP2S0 après une passerelle par défaut restaurée à 192.168.1.1

 2: enp2s0
       Link File: /lib/systemd/network/99-default.link
    Network File: /run/systemd/network/10-netplan-enp2s0.network
            Type: ether
           State: routable (configured)
            Path: pci-0000:02:00.0
          Driver: r8169
          Vendor: Realtek Semiconductor Co., Ltd.
           Model: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (M4A
      HW Address: 48:5b:39:02:41:c9 (ASUSTek COMPUTER INC.)
         Address: 192.168.1.10
                  fe80::4a5b:39ff:fe02:41c9
         Gateway: 192.168.1.1
             DNS: 1.1.1.1
                  1.0.0.1

Sortie de la commande de route après une passerelle par défaut restaurée à 192.168.1.1

Tabella di routing IP del kernel
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 enp2s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp2s0

Ceci est la sortie de la commande NetPlan --Debug Appliquer

 ** (generate:4965): DEBUG: 16:17:35.743: Processing input file /etc/netplan/01-netcfg.yaml..
** (generate:4965): DEBUG: 16:17:35.744: starting new processing pass
** (generate:4965): DEBUG: 16:17:35.744: Processing input file /etc/netplan/lo.yaml..
** (generate:4965): DEBUG: 16:17:35.744: starting new processing pass
** (generate:4965): DEBUG: 16:17:35.744: enp2s0: setting default backend to 1
** (generate:4965): DEBUG: 16:17:35.744: Configuration is valid
** (generate:4965): DEBUG: 16:17:35.744: lo: setting default backend to 1
** (generate:4965): DEBUG: 16:17:35.744: Configuration is valid
** (generate:4965): DEBUG: 16:17:35.744: Generating output files..
** (generate:4965): DEBUG: 16:17:35.744: NetworkManager: definition enp2s0 is not for us (backend 1)
** (generate:4965): DEBUG: 16:17:35.744: NetworkManager: definition lo is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:enp2s0 not found in {}
DEBUG:lo not found in {'enp2s0': {'addresses': ['192.168.1.10/24'], 'gateway4': '192.168.1.1', 'nameservers': {'addresses': ['1.1.1.1', '1.0.0.1']}}}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    enp2s0:
      addresses:
      - 192.168.1.10/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
        - 1.1.1.1
        - 1.0.0.1
    lo:
      addresses:
      - 127.0.0.1/8
  vlans: {}
  wifis: {}

DEBUG:device lo operstate is unknown, not changing
DEBUG:device enp2s0 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp2s0

@heynnema

root@ubuntu:~# cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    Sudo apt install ifupdown
root@ubuntu:~# cat /etc/netplan/*.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
        enp2s0:
            addresses: [192.168.1.10/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [1.1.1.1,1.0.0.1]
network:
    ethernets:
        lo:
            addresses: ['127.0.0.1/8']

Comment résoudre ?

1
Stefano

Change ton /etc/network/interfaces à...

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

Supprimer /etc/netplan/lo.yaml.

Change ton /etc/netplan/01-netcfg.yaml Fichier ... et soyez conscient de l'indentation spécifique et assurez aucun onglets ...

de:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
        enp2s0:
            addresses: [192.168.1.10/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [1.1.1.1,1.0.0.1]
network:
    ethernets:
        lo:
            addresses: ['127.0.0.1/8']

à:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 1.0.0.1]

Sudo netplan --debug generate # générer des fichiers de configuration

Sudo netplan apply # appliquer une nouvelle configuration

reboot # Redémarrage obligatoire

1
heynnema