Hoe Statisch IP-adres te Configureren op Ubuntu 18

Deze tutorial zal u alle stappen tonen die nodig zijn om een statisch IP-adres op Ubuntu Linux te configureren.

Deze tutorial is getest op Ubuntu 18.04.

1. Detecteer de Netwerkinterface op Linux

Eerst moet u controleren of de Ubuntu Linux de netwerkinterface heeft gedetecteerd.

# lshw -C network

Noteer de logische naam van de netwerkinterface.

In ons voorbeeld heeft het systeem een netwerkinterface met de naam ENS160 gedetecteerd.

*-network
description: Ethernet interface
product: VMXNET3 Ethernet Controller
vendor: VMware
physical id: 0
bus info: pci@0000:03:00.0
logical name: ens160
version: 01
serial: 00:0c:29:b1:46:b1
size: 10Gbit/s
capacity: 10Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm pciexpress msi msix bus_master cap_list rom ethernet physical logical tp 1000bt-fd 10000bt-fd
configuration: autonegotiation=off broadcast=yes driver=vmxnet3 driverversion=1.4.14.0-k-NAPI duplex=full ip=10.0.2.220 latency=0 link=yes multicast=yes port=twisted pair speed=10Gbit/s
resources: irq:18 memory:fd5fc000-fd5fcfff memory:fd5fd000-fd5fdfff memory:fd5fe000-fd5fffff ioport:4000(size=16) memory:fd500000-fd50ffff

2. Back-up van de Netwerkconfiguratiebestanden

Maak een back-up van uw huidige netwerkconfiguratie.

# mkdir /backup
# cp /etc/netplan /backup -R

3. Configureer het Statische IP-adres

Ga naar de Netplan-directory en vermeld de beschikbare configuratiebestanden.

# cd /etc/netplan
# ls

50-cloud-init.yaml

Meestal vindt u een bestand met de naam 01-netcfg.yaml of een bestand met de naam 50-cloud-init.yaml.

Laten we in ons voorbeeld aannemen dat u een bestand met de naam 50-cloud-init.yaml hebt gevonden.

Bewerk het netwerkconfiguratiebestand.

# cd /etc/netplan
# vi 50-cloud-init.yaml

Dit is de standaardinhoud van het netwerkconfiguratiebestand:

Copy

Hier is het nieuwe bestand met onze configuratie.

Copy

In ons voorbeeld is de netwerkinterface ENS160 geconfigureerd om het IP-adres 192.168.100.100/24, de gateway 192.168.100.1 en de DNS-server te gebruiken van Google 8.8.8.8 en 8.8.4.4.

Important!

The Netplan configuration files use the YAML configuration language

YAML is a human-friendly data serialization standard for all programming languages.
YAML is extremely sensitive to indentation errors.

Schakel de nieuwe netwerkconfiguratie in.

# netplan generate
# netplan apply

4. Controleer de Netwerkconfiguratie

Gebruik de opdracht IFCONFIG om de configuratie van de netwerkinterface te controleren.

# ifconfig

Hier is de huidige configuratie van de netwerkinterface.

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.255.255
inet6 fe80::20c:29ff:feb1:46b1 prefixlen 64 scopeid 0x20 ether 00:0c:29:b1:46:b1 txqueuelen 1000 (Ethernet)
RX packets 572572 bytes 258895818 (258.8 MB)
RX errors 0 dropped 319 overruns 0 frame 0
TX packets 132383 bytes 11603906 (11.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Controleer de DNS-configuratie.

# systemd-resolve --status

Hier is de huidige DNS-configuratie.

Link 2 (ens160)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 8.8.8.8
8.8.4.4

Controleer de standaard routeconfiguratie.

# netstat -nr

Dit is de huidige configuratie van de routeringstabel.

Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.100.1 0.0.0.0 UG 0 0 0 ens160
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160