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

How To Change IP Address on Linux – devconnected

The document provides a comprehensive guide on how to change the IP address on Linux systems, detailing methods such as using the 'ifconfig' command, 'ifupdown', and Network Manager. It explains the prerequisites for changing IP addresses, the steps for making changes temporarily or permanently, and how to verify the changes. Additionally, it covers managing networking on Linux and the importance of avoiding IP address conflicts.

Uploaded by

samir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

How To Change IP Address on Linux – devconnected

The document provides a comprehensive guide on how to change the IP address on Linux systems, detailing methods such as using the 'ifconfig' command, 'ifupdown', and Network Manager. It explains the prerequisites for changing IP addresses, the steps for making changes temporarily or permanently, and how to verify the changes. Additionally, it covers managing networking on Linux and the importance of avoiding IP address conflicts.

Uploaded by

samir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

TRENDING   HOW TO LIST SERVICES ON LINUX 

Home  Linux System Administration  Advanced  How To Change IP Address on Linux

Advanced Linux System Administration

How To Change IP Address on Linux


RECENT COMMENTS
written by Schkn

San
Very good

Thanks a l
informatio

dropintosa
My favorit
twice, befo

Zain Ul Ba
Informativ

Deekshith
Very Usefu

As a network administrator, you are probably managing various Linux machines over different subnets of your
company infrastructure.  March 2021

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 1/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

As network topology changes, you may need to change the IP address already implemented on some machines.  February 2021
READ ALSO 
Also, if you switched from DHCP to static IP addressing, you will also need to change the IP address on some of your  January 2021
computers.
 December 2020
Luckily for you, Linux has multiple ways of changing your IP address, whether you want it to be dynamic or static.
 November 2020
You will see how it is possible to have multiple IP addresses for a single machine and how you can assign IP addresses
to virtual network adapters.  October 2020

 September 2020
Table of Contents
1. Prerequisites  August 2020
2. Change IP Address using ifconfig
2.1. From DHCP to Static  July 2020
3. Change IP Address Permanently using ifupdown
3.1. Network Files on Debian & Ubuntu  April 2020
3.2. Network Files on CentOS & Red Hat
4. Change IP Address using Network Manager  March 2020
5. Change IP Address Permanently using Network Manager
6. Modify IP Address using Graphical Interface  February 2020
7. How networking is managed on Linux
8. Conclusion  January 2020

Prerequisites  December 2019

Before changing your IP address, make sure to have a look at your current IP address.  November 2019

To find your current IP address, you can use the “ip” command with the “a” option for address.  October 2019

 September 2019
$ ip a

 August 2019

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 2/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

As you canALSO
see from the screenshot, my host is equipped with two network adapters :  July 2019
READ 
the loopback address (or localhost) which is used to test the network connectivity of your own computer;  June 2019
the “enp0s3” interface : acting as a main network adapter, the network card has multiple IP addresses associated
 May 2019
with it (IPv4 and IPv6) followed by the IP address assigned to them.
 April 2019
In the present situation, my computer can be reached on “192.168.178.31/24” via the “192.168.178.1/24” gateway.

Change IP Address using ifconfig


On modern distributions, the “ifconfig” command has been completely deprecated and it is now advised to use the “ip”
command.

However, you should still be able to use the “ifconfig” to change your IP address.

$ which ifconfig

/usr/sbin/ifconfig

To change your IP address on Linux, use the “ifconfig” command followed by the name of your network
interface and the new IP address to be changed on your computer.

To assign the subnet mask, you can either add a “netmask” clause followed by the subnet mask or use the CIDR
notation directly.

$ ifconfig <interface_name> <ip_address> netmask <netmask_address>

Note : in order to change your IP address, you will need to be an administrator on your computer
(part of the sudo group on Debian/Ubuntu or wheel on CentOS/RedHat)

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 3/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

ForREAD
example, given the IP addresses used in the previous sections, if we want to change our IP address (to
ALSO 
192.168.178.32/24), we would run the following command

$ ifconfig enp0s3 192.168.178.32/24

$ ifconfig enp0s3 192.168.178.32 netmask 255.255.255.0

In order to verify that your IP address was correctly changed, you can run the “ifconfig” command followed by the name
of your network adapter.

$ ifconfig <interface_name>

From DHCP to Static


When manually changing your IP address, Linux automatically understands that you want to change from using a DHCP
server to static IP addressing.

This information is materialized in the “ifconfig” command : in the first screenshot, you can see that my IP address was
assigned with a “dynamic” parameter also called DHCP.

This is not the case anymore after assigning the IP address manually.

Note that your changes are not made permanent by modifying your IP settings with the “ifconfig” : they are only
modified for the current session.

Change IP Address Permanently using ifupdown


On Linux, changing your IP address using network utilities does not mean that your IP configuration will be saved on
reboots.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 4/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

Network Files on Debian & Ubuntu


READ ALSO 
In order to change your IP address on Linux, you will have to add your network configuration in the
“/etc/network/interfaces” or create this file if it does not exist already.

# Content of /etc/network/interfaces

iface eth0 inet static


address <ip_address>
netmask <network_mask>
gateway <gateway_ip>

For example, let’s say that you want to change your IP to be “192.168.178.32” with a subnet mask of “255.255.255.0” and
a default gateway of “192.168.178.1”.

To change your IP address to reflect those changes, you would edit the content of your interfaces file and add the
following content

$ vim /etc/network/interfaces

# Content of /etc/network/interfaces

iface eth0 inet static


address 192.168.178.32
netmask 255.255.255.0
gateway 192.168.178.1

In order for the changes to be applied, you will need to restart your networking service (managed by ifupdown)

# For systemd hosts

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 5/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

$ sudo systemctl restart networking.service


READ ALSO 
# For pre-systemd hosts

sudo /etc/init.d/networking restart

After restarting your networking service, you should be able to see your new IP by running the “ifconfig” or the “ip”
command.

$ ifconfig

$ ip address

Network Files on CentOS & Red Hat


In order to change your IP address on Linux, you will have to add your network configuration in the
“/etc/sysconfig/network-scripts” directory.

In the “/etc/sysconfig/network-scripts”, identify the network interface to be modified and start editing it.

$ ls -l /etc/sysconfig/network-scripts

$ nano <file>

In order to set an IP to be static on CentOS or RHEL, you want to modify the “BOOTPROTO” parameter from “dhcp” to
“static” and add your network information such as the netmask or the default gateway.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 6/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

On READ
recent ALSO
distributions such as CentOS 8 or RHEL 8, you have to use the nmcli utility in order for the changes to be

effective.

However, if you are still using the network service (for distributions such as CentOS 7 or RHEL 7), you can restart the
network service for the changes to be applied.

$ nmcli device reapply <interface_name> (on CentOS 8)

$ systemctl restart network.service (on CentOS 7/RHEL 7)

Awesome!

You successfully changed your IP address on Linux.

Make sure to execute the “ip” command again to verify that your changes were applied.

$ ip a

$ ifconfig

Change IP Address using Network Manager


On modern distributions, equipped with systemd, you may have come across the Network Manager many times.

The Network Manager is an all-in-one tool that exposes multiple utility tools in order to change connections, devices
or connectivity settings (even wireless) on your host.

One of those utilities is called “nmcli” and this is what we are going to use in order to change our IP address.

To change your IP address, use “nmcli” on the “device” section and specify that you want to “modify” the
“ipv4.address” of your network card.
https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 7/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO
$ nmcli device modify <interface_name> ipv4.address <ip_address> 

When using the “nmcli device modify” command, your Network Manager will automatically create a new connection file
in the /etc/NetworkManager/system-connections folder.

In order for the changes to be effective, you will need to “reapply” parameters to your current connection settings.

$ nmcli device reapply <interface_name>

Congratulations, you successfully changed your IP using the Network Manager!

However, changing settings using the nmcli tool won’t make your changes persistent over multiple reboots.

Change IP Address Permanently using Network Manager


https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 8/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

In order
READforALSO
changes to be persistent, you need to edit the connection files located at /etc/NetworkManager/system-

connections.

In order to change your IP address, edit the Network Manager configuration file, identify the line to be
modified and set the IP address accordingly.

Save the file and make sure to reapply the device configuration by using the “nmcli” command with the “device reapply”
options.

$ nmcli device reapply

Now that your changes are effective, you can check your IP address by running the “ifconfig” or “ip” commands.

Modify IP Address using Graphical Interface


In some cases, you may want to modify your IPv4 address by navigating through graphical windows.

On modern distributions, the network parameters can be managed by the “network” icon (which is called nm-applet)
located at the top right corner of your screen.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 9/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO 

In your network settings, click on the “gear wheel” next to the connection to be modified.

Next, in the IPv4 section of your connection settings, you can set your IP method to manual and attribute your static IP
address.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 10/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO 

To change your IP address, simply click on “Apply” and restart the networking services by using nmcli.

$ nmcli networking off

$ nmcli networking on

That’s it! You just changed your IP address on Linux.

How networking is managed on Linux


As of January 2020, on recent distributions, you may deal with several tools that are used by your distribution to
configure networking.

Most of the time, the Network Manager and ifupdown are managing networking.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 11/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO
$ sudo systemctl status NetworkManager 

$ sudo systemctl status networking

In some distributions, “ifupdown” might not be installed at all and interfaces are only managed by the
NetworkManager.

However, if the two services exist on your computer, you will be able to declare interfaces in the /etc/network/interfaces
file without the NetworkManager interfering with those settings.

If you want the Network Manager to manage interfaces declared in the interfaces file, you will have to modify the
“managed” parameter to true in the NetworkManager.conf configuration file.

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 12/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO 

Conclusion
In this tutorial, you learnt how you can successfully change your IP address on Linux : either using the Network
Manager or the ifupdown utility.

You also learnt how networking is managed and architectured on Linux and how you should configure it to avoid IP
address conflicts.

If you are interested in Linux system administration, we have a complete section dedicated to it on the website, so
make sure to check it out!

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 13/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

LINUX
READ ADMINISTRATION
ALSO NETWORK

 3 comments 4    

SCHKN

previous post next post


Network File System (NFS) Administration on How To Git Commit With Message
Linux

YOU MAY ALSO LIKE

How To List Disks on Linux How To Add Route on Linux How To Encrypt Partition on
Linux

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 14/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO 
3 COMMENTS

LINKS 13/1/2020: LINUX LITE 4.8, LINUX 5.5 RC6, COREBIRD CONTINUES AS ‘CAWBIRD’ | REPLY
TECHRIGHTS

[…] How To Change IP Address on Linux […]

DAVE REPLY

When I print or PDF this page, there’s an annoying “READ ALSO” popup that obscures enough of EVERY
page to make the printout useless. Please fix this so the popup doesn’t appear in the printout. Or tell me
how I can work around this issue to get rid of the popup myself.

BOB REPLY

Dave, I was able to resolve this by opening the html and deleting every instance of “popup”. It only took a
minute but I agree that this is very inconvenient – to make a printout virtually unusable to any ‘non-tech’
people.

LEAVE A COMMENT

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 15/16
12/2/23, 11:11 PM How To Change IP Address on Linux – devconnected

READ ALSO
Your Comment 

Name* Email* Website

Save my name, email, and website in this browser for the next time I comment.

SUBMIT

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 TWITTER

About Privacy Policy


Copyright © 2021 - devconnected. All rights reserved.
Any material cannot be used without our explicit consent (for online and offline purposes).

https://devconnected.com/how-to-change-ip-address-on-linux/#:~:text=To change your IP address on Linux%2C use the “ifconfig,use the CIDR notation directly. 16/16

You might also like