0% found this document useful (0 votes)
175 views

Configuring Static IP Address Using DHCP

The document discusses how to configure a static IP address on Ubuntu Server and Desktop systems. On Ubuntu Server, Netplan configuration files in YAML format are used to configure network interfaces. The file is edited to set "dhcp4: no" and add static IP address, gateway, and DNS server settings for an interface like ens3. On Ubuntu Desktop, the network settings GUI is used to change the interface to manual configuration and enter static IP details. In both cases, running ip addr verifies the new static IP assignment.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views

Configuring Static IP Address Using DHCP

The document discusses how to configure a static IP address on Ubuntu Server and Desktop systems. On Ubuntu Server, Netplan configuration files in YAML format are used to configure network interfaces. The file is edited to set "dhcp4: no" and add static IP address, gateway, and DNS server settings for an interface like ens3. On Ubuntu Desktop, the network settings GUI is used to change the interface to manual configuration and enter static IP details. In both cases, running ip addr verifies the new static IP assignment.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Configuring Static IP address using DHCP

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’s unique MAC address. The steps for configuring a
DHCP reservation vary from router to router, and it’s advisable to consult the vendor’s
documentation.

Netplan
Starting with 17.10 release, Netplan is the default network management tool on Ubuntu,
replacing the configuration file /etc/network/interfaces that had previously been used to
configure the network on Ubuntu.

Netplan uses configuration files in YAML syntax. To configure a network interface with
Netplan, you need to create a YAML description for that interface, and Netplan will generate the
required configuration files for your chosen renderer tool.

Netplan currently supports two renderers NetworkManager and Systemd-networkd.


NetworkManager is mostly used on Desktop machines while the Systemd-networkd is used on
servers without a GUI.

Configuring Static IP address on Ubuntu Server


The newer versions of Ubuntu uses ‘Predictable Network Interface Names’ that, by default, start
with en[letter][number].

The first step is to identify the name of the ethernet interface you want to configure. To do so use
the ip link command, as shown below:

ip link

The command will print a list of all the available network interfaces. In this case, 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 configuration files are stored in the /etc/netplan directory and have the extension
.yaml. You’ll probably find one or two YAML files in this directory. The file may differ from
setup to setup. Usually, the file is named either 01-netcfg.yaml, 50-cloud-init.yaml, or
NN_interfaceName.yaml, but in your system it may be different.

Open the YAML configuration file with your text editor :

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


/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: yes

Before changing the configuration, let’s explain the code in a short.

Each Netplan Yaml file starts with the network key that has at least two required elements. The
first required element is the version of the network configuration format, and the second one is
the device type. The device type can be ethernets, bonds, bridges, or vlans.

The configuration above also includes the renderer type. Out of the box, if you installed
Ubuntu in server mode, the renderer is configured to use networkd as the back end.

Under the device’s type (in this case ethernets), you can specify one or more network
interfaces. In this example, we have only one interface ens3 that is configured to obtain IP
addressing from a DHCP server dhcp4: yes.

To assign a static IP address to ens3 interface, edit the file as follows:

 Set DHCP to dhcp4: no.


 Specify the static IP address 192.168.121.199/24. Under addresses: you can add one
or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
 Specify the gateway gateway4: 192.168.121.1
 Under nameservers, set the IP addresses 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 editing Yaml files, make sure you follow the YAML code indent standards. If there are
syntax errors in the configuration, the changes will not ne applied.

Once done save and close the file and apply the changes with:

sudo netplan apply

Verify the changes by typing:

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’s it! You have assigned a static IP to your Ubuntu server.

Configuring Static IP address on Ubuntu Desktop #


Setting up a static IP address on Ubuntu Desktop computers requires no technical knowledge.

1. In the Activities screen, search for “network” and click on the Network icon. This will
open the GNOME Network configuration settings. Click on the cog icon.

2. The Network interface settings dialog box will be opened:

3. In “IPV4” Method" section, select “Manual” and enter your static IP address, Netmask
and Gateway. Once done, click on the “Apply” button.

Now that you have set up a static IP Address, open your terminal either by using the Ctrl+Alt+T
keyboard shortcut or by clicking on the terminal icon and verify the changes by typing:

ip addr

The output 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

You might also like