{"id":4575,"date":"2019-11-29T11:01:55","date_gmt":"2019-11-29T03:01:55","guid":{"rendered":"https:\/\/www.mondoze.com\/guide\/?post_type=kb&p=4575"},"modified":"2022-10-07T08:11:18","modified_gmt":"2022-10-07T00:11:18","slug":"how-to-configure-static-ip-address-on-ubuntu-18-04","status":"publish","type":"kb","link":"https:\/\/www.mondoze.com\/guide\/kb\/how-to-configure-static-ip-address-on-ubuntu-18-04","title":{"rendered":"How to Configure Static IP Address on Ubuntu 18.04"},"content":{"rendered":"\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t

In this tutorial, we'll explain how to set up a static IP address on Ubuntu 18.04.<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t

IP addresses are assigned dynamically by your router DHCP server. In\u00a0<\/span>different\u00a0<\/span>situations\u00a0<\/span>such\u00a0<\/span>as\u00a0<\/span>configuring\u00a0<\/span>port\u00a0<\/span>forwarding\u00a0<\/span>or\u00a0<\/span>running\u00a0<\/span>a\u00a0<\/span>media\u00a0<\/span>server <\/span>on\u00a0<\/span>your\u00a0<\/span>network,\u00a0<\/span>it\u00a0<\/span>may\u00a0<\/span>be\u00a0<\/span>necessary\u00a0<\/span>to\u00a0<\/span>set\u00a0<\/span>a\u00a0<\/span>static\u00a0<\/span>IP\u00a0<\/span>address\u00a0<\/span>on\u00a0<\/span>your\u00a0<\/span>Ubuntu\u00a0<\/span>computer.<\/span><\/span><\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t

Configuring Static IP address using DHCP<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t

The easiest and the recommended way to assign a static IP address to a device on your LAN is by setting up a Static DHCP on your router. Static DHCP or DHCP reservation is a feature found on most routers which makes the DHCP server to automatically assign the same IP address to a specific network device, every time the device requests an address from the DHCP server. This works by assigning a static IP to the device unique MAC address. The steps for configuring a DHCP reservation varies from router to router and it’s advisable to consult the vendor’s documentation.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t

Netplan<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t

Starting with 17.10 release,\u00a0Netplan\u00a0is the default network management tool on Ubuntu, replacing the configuration file\u00a0\/etc\/network\/interfaces<\/code>\u00a0that had previously been used to configure the network on Ubuntu.<\/p>

Netplan uses configuration files with YAML syntax. To configure a network interface with Netplan you simply create a\u00a0YAML\u00a0description for that interface and Netplan generates the required configuration files for your chosen renderer tool.<\/p>

Netplan currently supports two renderers NetworkManager and Systemd-networkd. NetworkManager\u00a0<\/span>is\u00a0<\/span>mostly\u00a0<\/span>used\u00a0<\/span>on\u00a0<\/span>desktop\u00a0<\/span>machines,\u00a0<\/span>while\u00a0<\/span>System-network <\/span>is\u00a0<\/span>used\u00a0<\/span>without\u00a0<\/span>a\u00a0<\/span>GUI\u00a0<\/span>on\u00a0<\/span>servers.<\/span><\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t

Configuring Static IP address on Ubuntu Server<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t

The newer\u00a0versions of Ubuntu\u00a0uses \u2018Predictable Network Interface Names\u2019 that start with\u00a0en[letter][number]<\/code>. by default. The first step is to identify the name of the ethernet interface you want to configure. You can use the\u00a0ip link command\u00a0as shown below:<\/span><\/p>

ip link\n<\/span><\/code><\/pre>

The command will print a list of all the available network interfaces. In this case, the name of the interface is\u00a0ens3<\/code>:<\/p>

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000\n    link\/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff\n<\/code><\/pre>

Netplan configuration files are stored in the\u00a0\/etc\/netplan<\/code>\u00a0directory and have the extension\u00a0.yaml<\/code>. You\u2019ll probably find one or two YAML files in this directory. The file may differ from setup to setup. Usually, the file is named either\u00a001-netcfg.yaml<\/code>,\u00a050-cloud-init.yaml<\/code>\u00a0or\u00a0NN_interfaceName.yaml<\/code>, but in your system it may be different.<\/p>

Open the YAML configuration file with your\u00a0text editor:<\/p>

sudo nano \/etc\/netplan\/01-netcfg.yaml\n<\/span><\/code><\/pre>
\/etc\/netplan\/01-netcfg.yaml<\/div>
network:<\/span>\n  version:<\/span> 2<\/span>\n  renderer:<\/span> networkd\n  ethernets:<\/span>\n    ens3:<\/span>\n      dhcp4:<\/span> yes<\/code><\/pre><\/div>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t

Let's\u00a0explain\u00a0the\u00a0code\u00a0in\u00a0a\u00a0short\u00a0time\u00a0before\u00a0changing\u00a0the\u00a0configuration.<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t

Each Netplan Yaml file starts with the\u00a0network<\/code>\u00a0key that has at least two required elements. The first required element is the version of network configuration format and the second one is the device type. Device types values can be\u00a0ethernets<\/code>,\u00a0bonds<\/code>,\u00a0bridges<\/code>, and\u00a0vlans<\/code>.<\/p>

The configuration above also includes the\u00a0renderer<\/code>\u00a0type. Out of the box, if you installed Ubuntu in server mode the renderer is configured to use\u00a0networkd<\/code>\u00a0as the back end.<\/span><\/p>

Under the device’s type ( in this case\u00a0ethernets<\/code>) we can specify one or more network interfaces. In this example we have only one interface\u00a0ens3<\/code>\u00a0that is configured to obtain IP addressing from a DHCP server\u00a0dhcp4: yes<\/code>.<\/p>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t

To assign a static IP address to\u00a0ens3\u00a0interface edit the file as follows:<\/h4>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t
\n\t\t\t\t