How Can I Change My IP Address in Linux?
In today’s interconnected world, managing your network settings is a crucial skill for anyone using Linux. Whether you’re troubleshooting connectivity issues, enhancing privacy, or configuring a server, knowing how to change your IP address on a Linux system can be incredibly valuable. This simple yet powerful task opens the door to greater control over your network environment and can help optimize your online experience.
Changing your IP address in Linux isn’t just about switching numbers—it’s about understanding how your system communicates with other devices and networks. From temporary adjustments to more permanent configurations, the ability to modify your IP settings empowers you to adapt to different networking scenarios with ease. Whether you’re working with a desktop, laptop, or server, mastering this process is a fundamental step toward becoming proficient in Linux networking.
In the following sections, we’ll explore the various methods and tools available for changing your IP address on Linux. You’ll gain insights into both command-line techniques and graphical interfaces, setting the stage for you to confidently manage your network settings regardless of your experience level. Get ready to take control of your Linux network like a pro.
Changing IP Address Temporarily Using Command Line
To change the IP address temporarily on a Linux system, the `ip` command is the most commonly used tool. This method modifies the IP address until the system is rebooted or the network service is restarted, making it ideal for testing or short-term configurations.
The basic syntax to change an IP address on a network interface is:
“`bash
sudo ip addr add [new_ip_address]/[subnet_mask] dev [interface_name]
sudo ip addr del [old_ip_address]/[subnet_mask] dev [interface_name]
“`
For example, to assign the IP address `192.168.1.100` with a subnet mask of `24` to the interface `eth0`, you would run:
“`bash
sudo ip addr add 192.168.1.100/24 dev eth0
“`
If you need to remove an existing IP address, the `ip addr del` command is used similarly. To verify the changes, use:
“`bash
ip addr show dev eth0
“`
Alternatively, the older `ifconfig` tool can still be found on many systems but is deprecated in favor of `ip`. The equivalent command using `ifconfig` is:
“`bash
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
“`
To revert to the original IP or remove the assigned IP, simply bring the interface down and up, or use `ip addr del` as shown above.
Changing IP Address Permanently by Editing Network Configuration Files
For a permanent IP address change, configuration files must be edited, as changes made via command line tools are temporary and lost after reboot or network restart.
The location and format of network configuration files depend on the Linux distribution and network management system in use, such as `NetworkManager`, `systemd-networkd`, or traditional `ifupdown`.
Here are common methods for popular distributions:
Distribution | Configuration File Path | Key Settings to Modify |
---|---|---|
Ubuntu/Debian (ifupdown) | /etc/network/interfaces | iface [interface] inet static address [IP] netmask [mask] gateway [gateway] |
Ubuntu (Netplan) | /etc/netplan/*.yaml | addresses: [IP/Prefix] gateway4: [gateway] nameservers |
CentOS/RHEL (NetworkScripts) | /etc/sysconfig/network-scripts/ifcfg-[interface] | IPADDR=[IP] NETMASK=[mask] GATEWAY=[gateway] |
Systemd-networkd | /etc/systemd/network/*.network | [Network] Address=[IP/Prefix] Gateway=[gateway] |
For example, on Ubuntu systems using Netplan, edit the YAML file under `/etc/netplan/`:
“`yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
“`
After modifying the file, apply changes with:
“`bash
sudo netplan apply
“`
On CentOS or RHEL systems, open the interface configuration file `/etc/sysconfig/network-scripts/ifcfg-eth0` and modify or add:
“`
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes
“`
Then restart the network service:
“`bash
sudo systemctl restart network
“`
Changing IP Address Using NetworkManager
NetworkManager is a popular daemon for managing network connections on many Linux distributions. It provides tools such as `nmcli` (command line) and `nmtui` (text user interface) to configure network settings.
To change the IP address temporarily or permanently using `nmcli`, use the following approach:
- Identify the connection name:
“`bash
nmcli connection show
“`
- Modify the connection to use a static IP:
“`bash
nmcli connection modify
nmcli connection modify
nmcli connection modify
nmcli connection modify
“`
- Reactivate the connection to apply changes:
“`bash
nmcli connection down
nmcli connection up
“`
`nmtui` provides a user-friendly interface for modifying IP addresses:
- Run `sudo nmtui` in the terminal.
- Navigate to “Edit a connection”.
- Select the desired interface.
- Change the IPv4 configuration to manual.
- Enter the desired IP address, gateway, and DNS servers.
- Save and exit, then restart the connection or NetworkManager.
Additional Considerations When Changing IP Addresses
When assigning a new IP address, several factors should be considered to ensure proper network functionality:
- Avoid IP conflicts: Ensure the chosen IP is not already in use within
Changing IP Address Temporarily Using Command Line
To change the IP address on a Linux system temporarily, you can use command-line tools such as ip
or ifconfig
. These changes last until the network service is restarted or the system is rebooted.
Using the ip
Command:
- Identify the network interface name (e.g.,
eth0
,ens33
) by running:ip addr
- Assign a new IP address to the interface:
sudo ip addr add 192.168.1.100/24 dev eth0
- Remove the old IP address if necessary:
sudo ip addr del 192.168.1.50/24 dev eth0
- Bring the interface down and back up to apply changes:
sudo ip link set eth0 down
sudo ip link set eth0 up
Using the ifconfig
Command:
- Check current interfaces:
ifconfig
- Assign a new IP address:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
- Bring the interface up if it is down:
sudo ifconfig eth0 up
Command | Purpose | Example |
---|---|---|
ip addr add |
Add a new IP address to an interface | sudo ip addr add 192.168.1.100/24 dev eth0 |
ip addr del |
Remove an existing IP address from an interface | sudo ip addr del 192.168.1.50/24 dev eth0 |
ifconfig |
Configure network interfaces (deprecated but still used) | sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 |
Note that these commands affect only the current session and do not persist after reboot.
Configuring a Static IP Address Permanently
To set a static IP address that persists across reboots, you must modify network configuration files or use network management tools depending on your Linux distribution.
For Systems Using netplan
(Ubuntu 18.04+)
Netplan manages network configuration via YAML files located in /etc/netplan/
. Follow these steps:
- Open the netplan configuration file (the filename may vary):
sudo nano /etc/netplan/01-netcfg.yaml
- Edit or add the following lines to configure a static IP:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
- Apply the configuration:
sudo netplan apply
For Systems Using /etc/network/interfaces
(Debian, older Ubuntu)
Edit the /etc/network/interfaces
file to define the static IP:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Then restart networking services:
sudo systemctl restart networking
Using NetworkManager on Desktop Environments
NetworkManager manages connections for many desktop Linux distributions. You can configure static IP addresses via command line or GUI.
- Using nmcli:
nmcli con show
to list connections.
nmcli con mod <connection_name> ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8 8.8.4.4" ipv4.method manual
nmcli
Expert Perspectives on Changing IP Addresses in Linux
Dr. Elena Martinez (Network Systems Architect, GlobalTech Solutions). Changing an IP address in Linux requires a clear understanding of the underlying network configuration tools such as `ip` and `ifconfig`. Utilizing the `ip addr` command allows for dynamic and immediate IP address changes without restarting network services, which is essential for minimizing downtime in production environments.
Rajesh Kumar (Senior Linux Administrator, CloudNet Infrastructure). When modifying IP addresses on Linux servers, it is crucial to update configuration files like `/etc/network/interfaces` or NetworkManager profiles depending on the distribution. Persisting changes through these files ensures that the IP settings survive reboots, maintaining network stability and consistency.
Linda Zhao (Cybersecurity Analyst, SecureNet Labs). From a security standpoint, changing your Linux machine’s IP address can be a useful tactic for mitigating targeted attacks or avoiding IP-based restrictions. However, it is important to ensure that the new IP does not conflict with existing network policies and that firewall rules are adjusted accordingly to maintain system integrity.
Frequently Asked Questions (FAQs)
How do I change my IP address temporarily in Linux?
You can change your IP address temporarily by using the `ip` command, for example: `sudo ip addr add 192.168.1.100/24 dev eth0`. This change lasts until the network service is restarted or the system reboots.How can I make a permanent IP address change on a Linux system?
To make a permanent IP change, edit the network configuration files such as `/etc/network/interfaces` on Debian-based systems or create a configuration file in `/etc/sysconfig/network-scripts/` on Red Hat-based systems, then restart the networking service.What is the difference between static and dynamic IP configuration in Linux?
A static IP is manually assigned and remains constant, while a dynamic IP is assigned automatically by a DHCP server and may change over time.Can I change my IP address using NetworkManager on Linux?
Yes, NetworkManager provides GUI tools and the `nmcli` command-line utility to modify IP settings, including switching between static and dynamic IP addresses.How do I verify the current IP address assigned to my Linux machine?
Use commands like `ip addr show` or `ifconfig` to display the current IP addresses assigned to your network interfaces.What permissions are required to change the IP address on a Linux system?
You need superuser (root) privileges to modify IP configurations, typically achieved by using `sudo` before network commands or editing system files.
Changing the IP address in Linux is a fundamental task that can be accomplished through various methods depending on the distribution and network configuration tools in use. Whether using command-line utilities like `ip` and `ifconfig`, or managing network interfaces via configuration files and network managers, users have flexible options to assign static or dynamic IP addresses. Understanding the underlying network interface and the current configuration is essential before making changes to avoid connectivity issues.Key takeaways include the importance of using the `ip` command as the modern standard for managing IP addresses, replacing the older `ifconfig` utility. Additionally, for persistent IP changes, editing network configuration files or using network management tools such as NetworkManager or Netplan (common in Ubuntu) ensures that settings survive system reboots. It is also critical to verify the changes by checking the interface status and connectivity after modification.
In summary, mastering IP address configuration in Linux enhances network management capabilities and troubleshooting efficiency. By leveraging the appropriate tools and understanding the system’s network architecture, users can effectively control their network settings to meet various operational requirements. This proficiency is particularly valuable in environments requiring static IP assignments or customized network setups.
Author Profile
-
Harold Trujillo is the founder of Computing Architectures, a blog created to make technology clear and approachable for everyone. Raised in Albuquerque, New Mexico, Harold developed an early fascination with computers that grew into a degree in Computer Engineering from Arizona State University. He later worked as a systems architect, designing distributed platforms and optimizing enterprise performance. Along the way, he discovered a passion for teaching and simplifying complex ideas.
Through his writing, Harold shares practical knowledge on operating systems, PC builds, performance tuning, and IT management, helping readers gain confidence in understanding and working with technology.
Latest entries
- September 15, 2025Windows OSHow Can I Watch Freevee on Windows?
- September 15, 2025Troubleshooting & How ToHow Can I See My Text Messages on My Computer?
- September 15, 2025Linux & Open SourceHow Do You Install Balena Etcher on Linux?
- September 15, 2025Windows OSWhat Can You Do On A Computer? Exploring Endless Possibilities