YouTube Icon

Code Playground.

How to Configure Static IP Address on Ubuntu 20.04

CFG

How to Configure Static IP Address on Ubuntu 20.04

This article discloses how to set up a static IP address on Ubuntu 20.04. 

Regularly, in most organization designs, the IP address is alloted progressively by the switch DHCP worker. Setting a static IP address might be required in various circumstances, for example, designing port sending or running a media worker . 

Configuring Static IP address using DHCP

The simplest and prescribed approach to allocate a static IP address to a gadget on your LAN is to design a Static DHCP on your switch. Static DHCP or DHCP reservation is an element found on most switches which makes the DHCP worker to naturally dole out a similar IP address to a particular organization gadget, each time the gadget demands a location from the DHCP worker. This works by allotting a static IP to the gadget's novel MAC address. 

The means for arranging a DHCP reservation shift from switch to switch. Counsel the merchant's documentation for more data. 

Netplan 

Ubuntu 17.10 and later uses Netplan as the default network the board instrument. The past Ubuntu variants were utilizing ifconfig and its

/etc/network/interfaces

to design the organization. 

Netplan arrangement records are written in YAML sentence structure with a .yaml document augmentation. To arrange an organization interface with Netplan, you have to make a YAML depiction for the interface, and Netplan will produce the necessary design records for the picked renderer instrument. 

Netplan upholds two renderers, NetworkManager and Systemd-networkd. NetworkManager is generally utilized on Desktop machines, while the Systemd-networkd is utilized on workers without a GUI. 

Configuring Static IP address on Ubuntu Server

On Ubuntu 20.04, the framework distinguishes network interfaces utilizing 'unsurprising organization interface names'. 

The initial move toward setting up a static IP address is distinguishing the name of the ethernet interface you need to arrange. To do as such, utilize the ip connect order, as demonstrated as follows: 

ip link

The order prints a rundown of all the accessible organization interfaces. In this model, the name of the interface is ens3: 

Output

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff

Netplan design documents are put away in the/and so forth/netplan catalog. You'll presumably discover at least one YAML records in this registry. The name of the document may vary from arrangement to arrangement. Ordinarily, the document is named either 01-netcfg.yaml, 50-cloud-init.yaml, or NN_interfaceName.yaml, yet in your framework it might be unique. On the off chance that your Ubuntu cloud occasion is provisioned with cloud-init, you'll have to impair it. To do so make the accompanying

sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

To dole out a static IP address on the organization interface, open the YAML setup record with your content tool : 

sudo nano /etc/netplan/01-netcfg.yaml
/etc/netplan/01-netcfg.yaml

 

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes

Prior to changing the design, we should clarify the code in a short. 

Each Netplan Yaml document begins with the organization key that has at any rate two required components. The initially required component is the variant of the organization design, and the subsequent one is the gadget type. The gadget type can be ethernets, bonds, spans, or vlans. 

The arrangement above additionally has a line that shows the renderer type. Out of the case, in the event that you introduced Ubuntu in worker mode, the renderer is designed to utilize networkd as the back end. 

Under the gadget's sort (ethernets), you can determine at least one organization interfaces. In this model, we have just a single interface ens3 that is designed to acquire IP tending to from a DHCP worker dhcp4: yes. 

To allocate a static IP address to ens3 interface, alter the document as follows: 

  • Set DHCP to dhcp4: no.
  • Indicate the static IP address. Under addresses: you can include at least one IPv4 or IPv6 IP tends to that will be doled out to the organization interface. 
  • Determine the door. 
  • Under nameservers, set the IP locations of the nameservers. 
/etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 192.168.121.221/24
      gateway4: 192.168.121.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

When altering Yaml documents, ensure you adhere to the YAML code indent principles. On the off chance that the sentence structure isn't right, the progressions won't be applied. 

When done, spare the record and apply the progressions by running the accompanying order: 

sudo netplan apply

Confirm the progressions by composing: 

ip addr show dev ens3
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.221/24 brd 192.168.121.255 scope global dynamic ens3
       valid_lft 3575sec preferred_lft 3575sec
    inet6 fe80::5054:ff:feb0:f500/64 scope link 
       valid_lft forever preferred_lft forever

That is it! You have appointed a static IP to your Ubuntu worker. 

Configuring Static IP address on Ubuntu Desktop 

Setting up a static IP address on Ubuntu Desktop PCs requires no specialized information. 

In the Activities screen, look for "settings" and snap on the symbol. This will open the GNOME settings window. Contingent upon the interface you need to adjust, click either on the Network or Wi-Fi tab. To open the interface settings, click on the gear-tooth symbol close to the interface name. 

In "IPV4" Method" tab, select "Manual" and enter your static IP address, Netmask and Gateway. When done, click on the "Apply" button. 

To confirm the changes, open your terminal either by utilizing the Ctrl+Alt+T console easy route or by tapping on the terminal symbol and run: 

ip addr

The yield will show the interface IP address: 

Output

...
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 50:5b:c2:d8:59:7d brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.221/24 brd 192.168.31.255 scope global dynamic noprefixroute wlp1s0
       valid_lft 38963sec preferred_lft 38963sec
    inet6 fe80::45e3:7bc:a029:664/64 scope link noprefixroute 

Conclusion

We've told you the best way to arrange a static IP address on Ubuntu 20.04. 

In the event that you have any inquiries, if you don't mind leave a remark underneath.




CFG