How To Change IP Address on Linux – devconnected
How To Change IP Address on Linux – devconnected
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
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.
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.
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
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>
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.
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
# Content of /etc/network/interfaces
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
In order for the changes to be applied, you will need to restart your networking service (managed by ifupdown)
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
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
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.
Awesome!
Make sure to execute the “ip” command again to verify that your changes were applied.
$ ip a
$ ifconfig
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.
However, changing settings using the nmcli tool won’t make your changes persistent over multiple reboots.
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.
Now that your changes are effective, you can check your IP address by running the “ifconfig” or “ip” commands.
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 on
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
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
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
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
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.
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