YouTube Icon

Code Playground.

How to Configure Static IP Address on Ubuntu 18.04

CFG

How to Configure Static IP Address on Ubuntu 18.04

In this instructional exercise, we'll disclose how to set up a static IP address on Ubuntu 18.04. 

For the most part, IP addresses are relegated powerfully by your switch DHCP worker. Setting a static IP address on your Ubuntu machine might be needed in various circumstances, for example, arranging port sending or running a media worker on your organization. 

Configuring Static IP address using DHCP

The most straightforward and the prescribed method to allot a static IP address to a gadget on your LAN is by setting up a Static DHCP on your switch. Static DHCP or DHCP reservation is a component found on most switches which makes the DHCP worker to consequently 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 allocating a static IP to the gadget's interesting MAC address. The means for arranging a DHCP reservation differ from switch to switch, and it's fitting to counsel the seller's documentation. 

Netplan

Beginning with 17.10 delivery, Netplan is the default network the executives instrument on Ubuntu, supplanting the arrangement document/and so forth/organization/interfaces that had recently been utilized to design the organization on Ubuntu. 

Netplan utilizes design documents in YAML punctuation. To arrange an organization interface with Netplan, you have to make a YAML depiction for that interface, and Netplan will create the necessary design records for your picked renderer device. 

Netplan at present backings 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

The more current adaptations of Ubuntu utilizes 'Unsurprising Network Interface Names' that, naturally, start with en[letter][number]. 

The initial step is to distinguish the name of the ethernet interface you need to design. To do so utilize the ip connect order, as demonstrated as follows: 

ip link

The order will print a rundown of all the accessible organization interfaces. For this situation, the name of the interface is ens3: 

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
3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff

Netplan arrangement records are put away in the/and so forth/netplan registry and have the expansion .yaml. You'll likely discover a couple of YAML documents in this index. The document may contrast from arrangement to arrangement. Normally, the document is named either 01-netcfg.yaml, 50-cloud-init.yaml, or NN_interfaceName.yaml, however in your framework it could be extraordinary. 

Open the YAML design record with your content manager : 

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, how about we clarify the code in a short. 

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

The setup above likewise incorporates 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 (for this situation ethernets), you can indicate 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 appoint a static IP address to ens3 interface, alter the record as follows: 

Set DHCP to dhcp4: no. 

Determine the static IP address 192.168.121.199/24. Under addresses: you can add at least one IPv4 or IPv6 IP tends to that will be allocated to the organization interface. 

Determine the passage gateway4: 192.168.121.1 

Under nameservers, set the IP locations of the nameservers addresses: [8.8.8.8, 1.1.1.1] 

/etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 192.168.121.199/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. In the event that there are language structure mistakes in the arrangement, the progressions won't ne applied. 

When done spare and close the record and apply the progressions with: 

sudo netplan apply

Check the progressions by composing: 

ip addr show dev ens3
3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.199/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 allocated 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 "organization" and snap on the Network symbol. This will open the GNOME Network setup settings. Snap on the gear-tooth symbol. 

Ubuntu Network Settings 

The Network interface settings exchange box will be opened: 

Ubuntu Interface Settings 

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

Ubuntu Set static IP Address 

Since you have set up a static IP Address, open your terminal either by utilizing the Ctrl+Alt+T console easy route or by tapping on the terminal symbol and check the progressions by composing: 

ip addr

The yield will show the interface IP address: 

...
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:e9:40:f2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.106/24 brd 192.168.121.255 scope global dynamic noprefixroute ens3
       valid_lft 3523sec preferred_lft 3523sec
    inet6 fe80::5054:ff:fee9:40f2/64 scope link 
       valid_lft forever preferred_lft forever

Conclusion

You have figured out how to appoint a static IP address on your Ubuntu 18.04 machine. 

On the off chance that you have any inquiries, if it's not too much trouble leave a remark beneath.




CFG