27
December
2019
10:12

Static IP address in Ubuntu and Linux Mint, setup

27 December 2019 10:12

When a computer network uses the DHCP protocol, computers receive IP addresses from a DHCP server. IP addresses may change. It is often required that the computer's IP address be fixed.

For example, this is needed to organize port forwarding from the Internet to a computer on a local (home or work) computer network. The obvious way is to configure MAC address binding on the router and reserve IP addresses on the DHCP server. But this is not always convenient, for example, at work: to bind an IP address, you need to have access to the router’s control panel or ask the local system administrator to do the IP-MAC binding.

I want to tell you about my method of setting a static IP address and specifying any DNS servers in Linux Mint or Ubuntu.

Ways to manage a network in Linux

5 ways:
1)/etc/network/interfaces and networking service- the classic way, setting up a network using text configuration files.
2)Network Manager service and applet nm-applet- graphical method, called from the desktop from the system tray by clicking on the icon with the Ethernet or Wi-Fi network symbol.
3)nmcli- the same as method No. 2, but managing the Network Manager service from the command line. Will not be considered.
4)netplan as a replacement for /etc/network/interfaces- a new method that uses text configuration files in YAML (Yet Another Markup Language) format.
5)networkd service(part of SystemD) - see cat /etc/systemd/networkd.conf в данной статье не будет рассмотрен. По умолчанию демон networkd отключен. Команды для просмотра статуса службы: networkctl, networkctl status, networkctl status --all.

Graphical method with the Network Manager applet

The easiest way to configure a static IP address or dynamic IP address is graphically, using the Network Manager applet (it can be called either from the system tray or with the command nm-applet). This method works if:

  • in file /etc/NetworkManager/NetworkManager.conf указано managed=true and netplan is not used,
  • or in file /etc/netplan/000-installer-config.yaml указано renderer: NetworkManager and netplan is used.

Checking the IP address management method - NM or netplan

If the NetPlan service is running, then this article is not suitable. Checking that NetworkManager is being used:

service NetworkManager status

On the system "by default" it should be displayed:
Active: active (running)

Setting up a static IP address

1.Find out the name of the network card in your Linux operating system, whether NetPlan is used and the IP address.

To find out network card name, run one of the following commands:

ip link
networkctl
nmcli device show | grep GENERAL.DEVICE

If the PC has an Ethernet network card, the command output will show its name. For example:enp2s0 или enp1s3.
The name of the network card is needed for further steps.

To find out is NetPlan used?:

sudo systemctl start systemd-networkd
sudo netplan status --all

If "Online state: offline" and status of network cards "unmanaged", then netplan is not used for network management and you can continue reading this article and the instructions it contains. Otherwise, see the article netplan as a replacement for /etc/network/interfaces.

To find out IP address:

ip addr

IP-The address is needed to determine in which subnet the IP address is issued. For example, 192.168.0.100/24 ​​means that the network issues addresses in the 192.168.0.x space, where x is from 1 to 254. The /24 suffix corresponds to the network mask 255.255.255.0.

2.If we want to manage the IP address using configuration files, disable the applet built into the system "NetworkManager". which interferes with network configuration management from text configuration files:

If Netplan is not used, continue.

Before modifying configuration files, make backup copies of them using the command cp.

sudo nano /etc/NetworkManager/NetworkManager.conf

We leave the first two lines:

[main]
plugins=ifupdown,keyfile

Place a comment with a hash symbol at the beginning of the line dns=dnsmasq if such a string exists.

Important! In the [ifupdown] section you need to change the parameter "managed=true" to "managed=false":

[ifupdown]
managed=false#disable the NetworkManager applet

Save and exit: Ctrl+S, Ctrl+X.

3.Now we fix the configuration file /etc/network/interfaces:

sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp2s0
allow-hotplug enp2s0
iface enp2s0 inet static
address 192.168.0.71
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 77.88.8.3
dns-search local

Replace enp2s0 with the real name of the network card that you found out in step #1. For example, enp4s0.

!!!!!!! In line dns-nameservers you can specify a non-standard DNS server. For example, secure DNS from Yandex 77.88.8.3. Detailed description -Yandex.DNS.

Save and exit: Ctrl+S, Ctrl+X.

4.Clear previous IP addresses and restart network services:

sudo ip addr flush dev enp2s0

Replace enp2s0 with the real name of the network card that you found out in step #1. For example, enp4s0.

5.Restarting network services

sudo service NetworkManager restart
sudo service networking restart
sudo service resolvconf restart

!!!Setting up the computer's static IP address is complete.


If we need to return a dynamic IP address (by default), read the next paragraph.

Setting up a dynamic IP address

To enable receiving an address from a DHCP server, correct the same file "interfaces":

# This file describes the network interfaces available on your system
#and how to activate them. For more information, see interfaces(5).

#The loopback network interface
auto lo
iface lo inet loopback

#The primary network interface`
auto enp2s0
allow-hotplug enp2s0
iface enp2s0 inet dhcp

Save and exit: Ctrl+S, Ctrl+X.

Clear previous IP addresses and restart network services:_

sudo ip addr flush dev enp2s0

Restarting services to apply the settings:

sudo service NetworkManager restart
sudo service networking restart
sudo service resolvconf restart

!!!Setting up the computer's dynamic IP address is complete.

Add: Reset network management configuration

If you need to return the NetworkManager applet to the system tray (status line) and transfer control to it,
you need to do the following:

1) Return the file /etc/network/interfaces to the original form:

sudo nano `/etc/network/interfaces` 
source /etc/network/interfaces.d/*

Save and exit: Ctrl+S, Ctrl+X.

2) Edit the file /etc/NetworkManager/NetworkManager.conf, indicating in the section "ifupdown" parameter "managed=true":

sudo nano /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=true

Ctrl+S, Ctrl+X

3) clear the IP address and restart network services:

sudo ip addr flush dev enp2s0
sudo service NetworkManager restart
sudo service networking restart
sudo service resolvconf restart

In this case, the IP address can be changed graphically: click on the network icon on the system panel and select “Network settings” and the “gear” button.

!!!We have returned network management to the NetworkManager applet.


Last change: 05/07/2026



Related publications