{"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
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 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 Starting with 17.10 release,\u00a0Netplan\u00a0is the default network management tool on Ubuntu, replacing the configuration file\u00a0 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 The newer\u00a0versions of Ubuntu\u00a0uses \u2018Predictable Network Interface Names\u2019 that start with\u00a0 The command will print a list of all the available network interfaces. In this case, the name of the interface is\u00a0 Netplan configuration files are stored in the\u00a0 Open the YAML configuration file with your\u00a0text editor:<\/p> Each Netplan Yaml file starts with the\u00a0 The configuration above also includes the\u00a0 Under the device’s type ( in this case\u00a0 Make\u00a0<\/span>sure\u00a0<\/span>you\u00a0<\/span>follow\u00a0<\/span>the\u00a0<\/span>YAML\u00a0<\/span>code\u00a0<\/span>indent\u00a0<\/span>requirements\u00a0<\/span>when\u00a0<\/span>editing\u00a0<\/span>Yaml\u00a0<\/span>files\u00a0<\/span>as\u00a0<\/span>it\u00a0<\/span>may\u00a0<\/span>not <\/span>work\u00a0<\/span>if\u00a0<\/span>the\u00a0<\/span>configuration\u00a0<\/span>includes\u00a0<\/span>a\u00a0<\/span>syntax\u00a0<\/span>error.<\/span><\/p> Once\u00a0<\/span>the\u00a0<\/span>file\u00a0<\/span>is\u00a0<\/span>saved\u00a0<\/span>and\u00a0<\/span>closed\u00a0<\/span>and\u00a0<\/span>the\u00a0<\/span>changes\u00a0<\/span>are\u00a0<\/span>applied\u00a0<\/span>with:<\/span><\/p> Verify the changes by typing:<\/p> That’s it! You have assigned a static IP to your Ubuntu server.<\/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 Setting up a static IP address on Ubuntu Desktop computers requires no technical knowledge.<\/p> 1.In the Activities screen, search for \u201cnetwork\u201d and click on the Network icon. This will open the GNOME Network configuration settings. Click on the cog icon.<\/p>Configuring Static IP address using DHCP<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
Netplan<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\/etc\/network\/interfaces<\/code>\u00a0that had previously been used to configure the network on Ubuntu.<\/p>Configuring Static IP address on Ubuntu Server<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
en[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>ens3<\/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>\/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>sudo nano \/etc\/netplan\/01-netcfg.yaml\n<\/span><\/code><\/pre>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\tLet'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
network<\/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>renderer<\/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>ethernets<\/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\tTo 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
dhcp4: yes<\/code><\/li>192.168.121.199\/24<\/code>. Under\u00a0addresses:<\/code>\u00a0you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.<\/li>gateway4: 192.168.121.1<\/code><\/li>nameservers<\/code>, specify the nameservers\u00a0addresses: [8.8.8.8, 1.1.1.1]<\/code><\/li><\/ul>network:<\/span>\n version:<\/span> 2<\/span>\n renderer:<\/span> networkd\n ethernets:<\/span>\n ens3:<\/span>\n dhcp4:<\/span> no\n<\/span> addresses:<\/span>\n<\/span> - 192.168<\/span>.121<\/span>.199<\/span>\/24<\/span>\n<\/span> gateway4:<\/span> 192.168<\/span>.121<\/span>.1<\/span>\n<\/span> nameservers:<\/span>\n<\/span> addresses:<\/span> [<\/span>8.8<\/span>.8<\/span>.8<\/span>,<\/span> 1.1<\/span>.1<\/span>.1<\/span>]<\/span><\/span><\/code><\/pre><\/div>sudo netplan apply\n<\/span><\/code><\/pre>ip addr show dev ens3\n<\/span><\/code><\/pre>3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000\n link\/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff\n inet 192.168.121.199\/24 brd 192.168.121.255 scope global dynamic ens3\n valid_lft 3575sec preferred_lft 3575sec\n inet6 fe80::5054:ff:feb0:f500\/64 scope link \n valid_lft forever preferred_lft forever\n<\/code><\/pre>Configuring Static IP address on Ubuntu Desktop<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\t\t\t\t\t\t\t\t\t\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