You are on page 1of 3

apt-get update -y

Add an Additional IP Address Permanently


The process to configure an IP address on an Ubuntu 18.04 server is
different than the older method used in the older version of Ubuntu. Ubuntu
18.04 uses Netplan utility to configure networking.
You can add an additional IP address permanently to your system by editing
the file /etc/netplan/50-cloud-init.yaml.
First, you can see your existing IP address with the following command:
ip addr
You should see the following output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
qlen 1000
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
   inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP
group default qlen 1000
   link/ether 08:00:27:c8:48:62 brd ff:ff:ff:ff:ff:ff
   inet 192.168.0.101/24 brd 192.168.0.255 scope global enp0s3
      valid_lft forever preferred_lft forever
   inet6 fe80::a00:27ff:fec8:4862/64 scope link
      valid_lft forever preferred_lft forever

You can also see your existing network configuration with the following
command:

cat /etc/netplan/50-cloud-init.yaml

You should see your existing network configuration in the following output:

# This file is generated from information provided by


# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.0.101/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8]

In the above output, you should see that the IP address 192.168.0.101 is
assigned to the interface.
Here’s a brief explanation of each parameter:

 enp0s3: A device name to be configured.


 dhcp4:  Used to enable or disable dhcp4.
 dhcp6: Used to enable or disable dhcp6.
 addresses: The IP address of the device.
 gateway4: The IP address of your gateway.
 nameservers: The IP address of your DNS server.

Next, we will add an additional IP address 192.168.0.100 to the server.


To do so, open your file /etc/netplan/50-cloud-init.yaml in your preferred
text editor:

nano /etc/netplan/50-cloud-init.yaml

After adding an additional IP address, your file should look something like
this:

network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.0.101/24, 192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8]

Save and close the file when you are finished. Then, enable the new
configuration with the following command:

netplan apply

Now, check your new IP address with the following command:

ip addr

You should see both IP addresses in the following output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP
group default qlen 1000
link/ether 08:00:27:c8:48:62 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.0.100/24 brd 192.168.0.255 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fec8:4862/64 scope link
valid_lft forever preferred_lft forever

You might also like