search
HomeSystem TutorialLINUXShare several methods to change IP address in Linux system

Share several methods to change IP address in Linux system

Feb 09, 2024 pm 08:42 PM
linuxlinux tutoriallinux systemlinux commandshell scriptembeddedlinuxGetting started with linuxlinux learning

Currently, IP addresses in most systems are automatically assigned, but in some cases, we may need to change them manually. Today we share several methods to modify the system IP address.

As a system administrator, changing the IP address of a machine is a very common task. IP addresses in most systems are currently assigned automatically, but in some cases we may need to change them manually.

Today we share several methods to modify the system IP address.

Before taking action, we can use the following command to view the current IP address:

ip a

The above command will also display the network port (interface) name while displaying the IP address. The network port name will be used when modifying the IP address.

Use the ip command to set the IP address

We introduced the ip command in a previous article, which can view the IP address of the local machine. This command is available on most Linux distributions. Use the ip command to set the IP address. You can use the following command:

ip addr add [ip_address] dev [interface]

For example, to add an IP address to the network port eth1, you can use the following command:

sudo ip addr add 192.168.56.21/24 dev eth1

Now, there are two IP addresses in the network port eth1, one is originally configured, and the other is newly added using the command:

Linux 系统中更改 IP 地址的几种方法分享

As shown in the picture above, if you delete the old IP address, there will be only one IP address left.

Set static IP address

The IP address set through the above method will be modified after the system restarts, and the IP address is dynamic.

If you are using an older version of Ubuntu (version number less than 17.10), you can change the IP to static and permanent by editing the file /etc/network/interfaces.

sudo nano /etc/network/interfaces

If the file content is as follows, it means that the IP address of the system is set by the DHCP client:

auto eth0iface eth0 inet dhcp

We can set a static IP address by modifying the above file. For example, if you want to set the IP address to 192.168.56.20, you can modify the content of the above file to:

auto enp0s3iface enp0s3 inet staticaddress 192.168.56.20netmask 255.255.255.0gateway
 192.168.40.31

The above content is easy to understand for users who often use Linux systems. For the modification to take effect, you need to run the following command:

$ sudo systemctl restart networking.service

Tip: On RedHat-based systems, the file used to configure the network interface is /etc/sysconfig/networking-scripts/ifcfg-*

Use Netplan for network configuration (for Ubuntu)

Ubuntu has a tool for network configuration called Netplan.

We configure the IP address on Ubuntu 20.04 as an example, using NetworkManager as the renderer for the network configuration.

You can view the current IP address in the Netplan configuration file. The file is in YAML format. If it does not exist, you can create it:

sudo nano /etc/netplan/config.yaml

If the IP address is dynamic, you will see the dhcp4 parameter set to true.

If you have currently configured a static IP, you will see the following content:

---network: version: 2 renderer: networkd ethernets: eth1: addresses: 
- 192.168.56.66/24 nameservers: addresses: - 8.8.8.8 routes: - to: default via: 10.0.2.2

Set a new address by modifying the IP address above. In addition, you can also keep the old IP address and add another one to the above network port (eth1).

After configuring, test it before applying:

sudo netplan try

After confirming the changes, make the configuration take effect:

sudo netplan apply

Then check whether the configuration has taken effect:

Linux 系统中更改 IP 地址的几种方法分享

One of the advantages of using Netplan is that the configuration modification is permanent. After the machine is restarted, the configuration will still take effect, that is, the configured IP is static .

Change the system IP address using the graphical interface (for desktop users)

Using a graphical interface to manage IP addresses is the easiest way. On Ubuntu systems, the network settings contain all the necessary configurations.

Open Settings in the GNOME Dashboard, find the Network option, and then select the settings icon in the available network of the system, as shown in the following figure:

Linux 系统中更改 IP 地址的几种方法分享

In the newly opened window, select the IPv4 tab, then under IPv4 method, select the Manual (manual) option and enter the new IP address:

Linux 系统中更改 IP 地址的几种方法分享

Then restart the network connection and check the IP address:

Linux 系统中更改 IP 地址的几种方法分享

As you can see from the screenshot above, the IP address has been changed.

The ip command is available on all Linux systems; Netplan is a new way to manage your network and is a very simple method for Ubuntu systems.

The above is the detailed content of Share several methods to change IP address in Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
5 Best Free PDF to Word Doc Converters for Linux5 Best Free PDF to Word Doc Converters for LinuxMay 16, 2025 am 10:00 AM

Portable Document Format (PDF) remains a widely used file format due to its consistent standards across different platforms and devices, compatibility, and compact size.Numerous powerful tools are available for viewing PDF files, catering to various

How to Install Linux Mint 22 Mate on Your ComputerHow to Install Linux Mint 22 Mate on Your ComputerMay 16, 2025 am 09:44 AM

Linux Mint 22, codenamed “Wilma”, was officially launched as a significant update to Linux Mint on July 25, 2024. Linux Mint 22 is an LTS (Long Term Service) release, built upon Ubuntu 24.04, and will receive support until April 2029.As anticipated,

How to Hack Your Own Linux System to Strengthen SecurityHow to Hack Your Own Linux System to Strengthen SecurityMay 16, 2025 am 09:39 AM

Passwords serve as the primary security measure across various systems, including Linux, where the root password grants full control over the system. They are essential for securing BIOS, login, disks, applications, and more.Linux is widely regarded

6 Best Linux Software and Apps with Data Encryption6 Best Linux Software and Apps with Data EncryptionMay 16, 2025 am 09:33 AM

Data encryption is an essential component of modern cybersecurity, enabling the encoding of data to render it unreadable to unauthorized users. To enhance your online security, consider choosing software that incorporates this vital feature as a stan

How to Install Linux Mint 22 XFCE on Your ComputerHow to Install Linux Mint 22 XFCE on Your ComputerMay 16, 2025 am 09:28 AM

Linux Mint 22, with the codename “Wilma”, has been officially launched and is ready for download. Built on Ubuntu 24.04, it offers support until 2029 and comes in three flavors: Cinnamon, MATE, and XFCE.This guide will take you through the steps to i

16 Best Open Source Cloud Storage Software for Linux in 202416 Best Open Source Cloud Storage Software for Linux in 2024May 16, 2025 am 09:15 AM

The term "cloud" evokes a sense of vastness and expansiveness. In the technology sector, "the cloud" denotes a virtual platform that delivers services to end-users, encompassing data storage, application hosting, and the virtualiz

How to Install Linux Mint 22 Cinnamon on Your ComputerHow to Install Linux Mint 22 Cinnamon on Your ComputerMay 16, 2025 am 09:10 AM

Linux Mint is a contemporary, user-friendly, and community-driven GNU/Linux desktop distribution, built on the well-known Ubuntu Linux distribution. It's an excellent choice for users transitioning from Windows or macOS to the Linux environment.Linux

4 Best Tools to Create PDF Forms on Linux4 Best Tools to Create PDF Forms on LinuxMay 16, 2025 am 09:08 AM

Introduction: In this article, you will find the best applications for creating PDF files (also known as interactive tables) on Linux. If you need powerful tools to create and edit PDF files on Linux, you have many applications to choose from. These applications are able to perform basic editing operations such as merging pages, cropping pages, adding comments, and sometimes even providing advanced features. However, not all PDF editors can create PDF forms—that is, editable PDF files with interactive fields that can be filled in by other users. Such documents are useful in situations like you need to create a questionnaire, an admission form, or a sales contract, etc. The following list includes solutions that can run on various Linux distributions,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool