3.4K
With Ubuntu 18.04 onwards, configuring IP addresses stands different from the older versions. When comparing with the previous versions the Ubuntu is using a new utility called Netplan – another order line arrange design utility, to arrange an IP address. Netplan has been presented by Ubuntu engineers in Ubuntu 17.10 where we no longer use the “interfaces” file to configure IP address but does the task using a YAML file with all default arrangement documents found under /etc/netplan/ directory. In this blog, we will check on how to design static and dynamic IP address in Ubuntu 18.04 LTS server. Netplan’s design documents utilize the YAML format where all /{lib,etc,run}/netplan/*.yaml are considered. Lexicographically later records (paying little mind to in which index they are) alter (new mapping keys) or override (same mapping keys) past ones. A document in /run/netplan totally shadows a record with the same name in /etc/netplan, and a file in both of those directories shadows a file with a similar name in /lib/netplan. Distribution installers, cloud instantiation, image works for specific devices, or some other method to convey a working framework put its ideal system arrangement into YAML setup file(s). During initial boot, the netplan “network renderer” runs yaml files under netplan directory and saves the configuration to /run to assign control of devices to the specified networking daemon.
Note: Again, all IPs and domains are random and are used for this example only, you will have different values on your instance. This particular setup has two live IPs: 192.168.0.2 and 172.16.0.2. What if you need to also add 172.16.0.3 and 172.16.0.4 Ips? You would simply add them to the ‘addresses’ line like so: addresses: [ 192.168.0.2/32, 172.16.0.2/16, 172.16.0.3/16, 172.16.0.4/16] Make sure to use the correct format, using the CIDR notation.
Please make sure to use proper indentation or it won’t work. YAML requires this.
As you can see, enp0s3 and enp0s8 are the two network cards that are configured to accept IPs from the DHCP server. Note: Before making any changes in this file, let us backup it. $ sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
Also, we do not use a different line to define netmask (255.255.255.0) in Ubuntu version 18.04. For instance, in the old Ubuntu versions, we configure IP and netmask like below, address = 192.168.225.50 netmask = 255.255.255.0 With netplan, we combine those respective two lines with a single line as shown below: addresses : [192.168.225.50/24] 3. After adding the range. Save and close the file. Apply the network configuration using command: $ sudo netplan apply We can run the below mentioned to investigate and check what is the problem in the configuration. $ sudo netplan –debug apply Sample output reference,
With Ubuntu 18.04 onwards, configuring IP addresses stands different from the older versions. When comparing with the previous versions the Ubuntu is using a new utility called Netplan – another order line arrange design utility, to arrange an IP address. Netplan has been presented by Ubuntu engineers in Ubuntu 17.10 where we no longer use the “interfaces” file to configure IP address but does the task using a YAML file with all default arrangement documents found under /etc/netplan/ directory. In this blog, we will check on how to design static and dynamic IP address in Ubuntu 18.04 LTS server. Netplan’s design documents utilize the YAML format where all /{lib,etc,run}/netplan/*.yaml are considered. Lexicographically later records (paying little mind to in which index they are) alter (new mapping keys) or override (same mapping keys) past ones. A document in /run/netplan totally shadows a record with the same name in /etc/netplan, and a file in both of those directories shadows a file with a similar name in /lib/netplan. Distribution installers, cloud instantiation, image works for specific devices, or some other method to convey a working framework put its ideal system arrangement into YAML setup file(s). During initial boot, the netplan “network renderer” runs yaml files under netplan directory and saves the configuration to /run to assign control of devices to the specified networking daemon. - Designed devices get taken care of by systemd-networkd as a matter of course, except if expressly set apart as oversaw by a particular renderer (NetworkManager)
- Devices that are not mentioned by the network config are not worked upon.
- Usable in initramfs (not many conditions and quick)
- No persistent generated config, just only the unique YAML config
- Parser holds-up several config documents to permit applications like libvirt or lxd to acheive required network config (virbr0, lxdbr0), or to alter the global default policy to use NetworkManager for everything.
- Flexibility to change backend or policy later or adjust to removing NetworkManager is retained, as the generated configuration is transitory.
- Go to the netplan directory: cd /etc/netplan
- In the netplan directory, you can see what files you have, typically it will be something like 01-netcfg.yaml. Now open the file using your favorite editor, we will use vim: vim 01-netcfg.yaml
Note: Again, all IPs and domains are random and are used for this example only, you will have different values on your instance. This particular setup has two live IPs: 192.168.0.2 and 172.16.0.2. What if you need to also add 172.16.0.3 and 172.16.0.4 Ips? You would simply add them to the ‘addresses’ line like so: addresses: [ 192.168.0.2/32, 172.16.0.2/16, 172.16.0.3/16, 172.16.0.4/16] Make sure to use the correct format, using the CIDR notation. - What if you need to use two different gateways because your IP blocks are using different gateways?
Please make sure to use proper indentation or it won’t work. YAML requires this. - After you are done, save the file and then restart and apply the network: netplan apply
- Check to ensure all IPs show: ip addr
How to Configure a Static IP Address In Ubuntu 18.04 LTS Server
The default network configuration file is:$ ls /etc/netplan/ 50-cloud-init.yamlLet’s check the contents of this file:
As you can see, enp0s3 and enp0s8 are the two network cards that are configured to accept IPs from the DHCP server. Note: Before making any changes in this file, let us backup it. $ sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak - Now, Open the default network configuration file in any of the editors.
- IP address for enp0s3 : 192.168.225.50
- IP address for enp0s8 : 192.168.225.51
- Gateway : 192.168.225.1
- Netmask : 255.255.255.0
- DNS servers : 8.8.8.8 and 8.8.4.4.
Also, we do not use a different line to define netmask (255.255.255.0) in Ubuntu version 18.04. For instance, in the old Ubuntu versions, we configure IP and netmask like below, address = 192.168.225.50 netmask = 255.255.255.0 With netplan, we combine those respective two lines with a single line as shown below: addresses : [192.168.225.50/24] 3. After adding the range. Save and close the file. Apply the network configuration using command: $ sudo netplan apply We can run the below mentioned to investigate and check what is the problem in the configuration. $ sudo netplan –debug apply Sample output reference,
