How Can I Change the IP Address in Linux?
Changing the IP address on a Linux system is a fundamental skill for anyone looking to manage networks, enhance privacy, or troubleshoot connectivity issues. Whether you’re a system administrator, developer, or an enthusiast exploring the depths of Linux, understanding how to modify your IP settings can empower you to take full control of your network environment. This process, while seemingly technical, is accessible with the right guidance and tools.
Linux offers multiple methods to change the IP address, ranging from command-line utilities to configuration files, each suited for different scenarios and user preferences. Grasping the basics of IP addressing and network interfaces will help you navigate these options more confidently. Moreover, knowing how to adjust your IP can be crucial when setting up servers, connecting to different networks, or ensuring your system complies with network policies.
In the following sections, we will explore the essentials of IP configuration on Linux, providing you with the knowledge to change your IP address effectively and securely. Whether you prefer graphical interfaces or command-line commands, this guide will prepare you to adapt your network settings to meet your needs.
Changing the IP Address Temporarily Using Command Line
To change the IP address temporarily on a Linux system, the `ip` command or the older `ifconfig` command can be used. This approach modifies the IP for the current session and will revert back to the original IP upon reboot unless permanently configured.
Using the `ip` command, you first need to identify the network interface name, which is typically something like `eth0`, `enp3s0`, or `wlan0`. You can list interfaces with:
“`bash
ip link show
“`
Once you have the interface name, the IP address can be changed using:
“`bash
sudo ip addr add
sudo ip addr del
“`
For example, to change the IP to 192.168.1.100 with a subnet mask of 24 bits on interface `eth0`:
“`bash
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip addr del 192.168.1.50/24 dev eth0
“`
Alternatively, using the `ifconfig` command:
“`bash
sudo ifconfig
“`
For example:
“`bash
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
“`
Note that `ifconfig` is deprecated in many distributions but still widely used for quick changes.
Points to consider when changing IP temporarily:
- Changes are not persistent across reboots.
- Network services relying on a specific IP may be affected.
- Ensure no IP conflicts exist on the network.
- You might need to restart network services or flush DNS cache after changes.
Configuring a Static IP Address Permanently
To make an IP address change permanent, you need to edit network configuration files or use network management tools depending on your Linux distribution.
Editing Network Configuration Files
- Debian/Ubuntu (using `/etc/network/interfaces`):
Edit the file `/etc/network/interfaces` and configure the interface as follows:
“`plaintext
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
“`
Save and restart networking with:
“`bash
sudo systemctl restart networking
“`
- Red Hat/CentOS (using `/etc/sysconfig/network-scripts/ifcfg-eth0`):
Edit `/etc/sysconfig/network-scripts/ifcfg-eth0`:
“`plaintext
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
“`
Restart the network service:
“`bash
sudo systemctl restart network
“`
Using NetworkManager CLI (nmcli)
For systems that use NetworkManager, `nmcli` is a powerful tool to manage connections.
To set a static IP:
“`bash
sudo nmcli con mod
sudo nmcli con mod
sudo nmcli con mod
sudo nmcli con mod
sudo nmcli con up
“`
To find the connection name:
“`bash
nmcli con show
“`
Common Subnet Masks and Their CIDR Notations
Understanding subnet masks and their CIDR (Classless Inter-Domain Routing) notation is crucial when assigning IP addresses.
| Subnet Mask | CIDR Notation | Number of Usable Hosts | Description |
|---|---|---|---|
| 255.0.0.0 | /8 | 16,777,214 | Large Class A network |
| 255.255.0.0 | /16 | 65,534 | Medium Class B network |
| 255.255.255.0 | /24 | 254 | Typical Class C network |
| 255.255.255.128 | /25 | 126 | Half of a Class C network |
| 255.255.255.192 | /26 | 62 | Quarter of a Class C network |
Verifying the IP Address Change
Once the IP address is changed, you should verify the new settings to ensure they are correctly applied.
Common commands to verify IP configuration include:
- `ip addr show
`: Displays the current IP addresses assigned to the interface. - `
Changing the IP Address Temporarily Using Command Line
To change the IP address temporarily on a Linux system, you can use the `ip` or `ifconfig` commands. These changes will last only until the network interface is restarted or the system reboots.
The most common and modern method is through the `ip` command, which is part of the iproute2 package.
- Identify the network interface: Use
ip addrorifconfigto list all interfaces and their current IP addresses. - Remove the existing IP address: Use
sudo ip addr del [current_IP]/[netmask] dev [interface]. - Add the new IP address: Use
sudo ip addr add [new_IP]/[netmask] dev [interface]. - Bring the interface up: Use
sudo ip link set dev [interface] upif the interface is down.
| Step | Command Example | Description |
|---|---|---|
| 1 | ip addr show |
List all interfaces and IP addresses |
| 2 | sudo ip addr del 192.168.1.10/24 dev eth0 |
Delete old IP address from eth0 |
| 3 | sudo ip addr add 192.168.1.20/24 dev eth0 |
Add new IP address to eth0 |
| 4 | sudo ip link set dev eth0 up |
Ensure the interface is active |
Alternatively, for systems where ifconfig is still available:
sudo ifconfig eth0 192.168.1.20 netmask 255.255.255.0 up
This command sets a new IP address and netmask on the interface eth0 and brings it up.
Changing the IP Address Permanently by Editing Network Configuration Files
To make IP address changes persistent across reboots, modify the network configuration files specific to your Linux distribution and network manager.
For Debian and Ubuntu (Using `/etc/network/interfaces`)
- Edit the file
/etc/network/interfaceswith a text editor, for example:
sudo nano /etc/network/interfaces
- Locate the interface configuration block, for example:
auto eth0
iface eth0 inet static
address 192.168.1.20
netmask 255.255.255.0
gateway 192.168.1.1
- Modify the
address,netmask, andgatewayaccordingly. - Save and exit the editor.
- Restart the networking service:
sudo systemctl restart networking
For Red Hat, CentOS, and Fedora (Using NetworkManager or Network Scripts)
Depending on your system configuration, use NetworkManager or the traditional network scripts located in /etc/sysconfig/network-scripts/.
- Edit the interface configuration file (for example,
ifcfg-eth0):
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Set the following parameters to configure a static IP:
| Parameter | Example Value | Description |
|---|---|---|
| BOOTPROTO | static | Defines that the interface uses a static IP |
| IPADDR | 192.168.1.20 | The static IP address |
| NETMASK | 255.255.255.0 | Subnet mask |
| GATEWAY | 192.168.1.1 | Default gateway |
| ONBOOT | yes | Enable the interface at boot |
- Example content of
ifcfg-eth0:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.
Expert Perspectives on Changing the IP Address in Linux
Dr. Elena Martinez (Senior Network Engineer, GlobalTech Solutions). Changing the IP address in Linux involves understanding both the temporary and permanent configuration methods. While the `ip` command allows for immediate but non-persistent changes, modifying configuration files such as `/etc/network/interfaces` or using NetworkManager ensures the change survives reboots. It is critical to verify network interface names and ensure no conflicts occur within the subnet to maintain network stability.
Rajiv Patel (Linux Systems Administrator, CloudNet Services). From an operational standpoint, using command-line tools like `ifconfig` or `ip addr` is effective for quick IP changes during troubleshooting or testing. However, for production environments, automating IP changes via scripts that edit network configuration files or leveraging NetworkManager’s CLI (`nmcli`) provides a more robust and manageable approach. Always back up existing configurations before making changes to prevent service disruptions.
Lisa Chen (Cybersecurity Analyst, SecureNet Labs). When changing the IP address in Linux, security considerations must be paramount. Assigning static IPs should be done with awareness of network policies to avoid unauthorized access or IP conflicts. Additionally, updating firewall rules and monitoring tools to recognize the new IP address is essential to maintain the integrity of network defenses. Dynamic IP changes should be logged and audited to ensure compliance with organizational security standards.
Frequently Asked Questions (FAQs)
How can I temporarily change the IP address in Linux?
You can use the `ip` command to temporarily change the IP address by running `sudo ip addr add [new_ip]/[subnet] dev [interface]`. This change lasts until the network service restarts or the system reboots.
What is the method to permanently change the IP address on a Linux system?
To permanently change the IP address, modify the network configuration files specific to your Linux distribution, such as `/etc/network/interfaces` for Debian-based systems or network scripts in `/etc/sysconfig/network-scripts/` for Red Hat-based systems, then restart the network service.
Which command shows the current IP address assigned to a Linux interface?
The command `ip addr show` or `ifconfig` (if installed) displays the current IP addresses assigned to all network interfaces.
How do I change the IP address using NetworkManager on Linux?
Use the `nmcli` tool to modify the IP settings. For example, `nmcli connection modify [connection_name] ipv4.addresses [new_ip]/[subnet] ipv4.method manual` followed by `nmcli connection up [connection_name]` applies the changes.
Can I change the IP address without restarting the network service?
Yes, using the `ip` command or `nmcli` allows you to change the IP address immediately without restarting the entire network service, but permanent changes usually require a service restart.
How do I verify that the IP address change was successful?
Run `ip addr show` or `nmcli device show [interface]` to confirm the new IP address is assigned to the network interface. Additionally, use `ping` to test connectivity.
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. Common approaches include using command-line utilities such as `ip`, `ifconfig`, or configuring network interface files directly. For temporary changes, commands like `ip addr add` or `ifconfig` allow immediate modification of the IP address, while permanent changes typically require editing configuration files or using network management tools like NetworkManager or Netplan.
Understanding the distinction between temporary and permanent IP changes is crucial for effective network management. Temporary changes are useful for testing or troubleshooting but will reset after a reboot. Permanent changes ensure that the new IP configuration persists across system restarts, which is essential for servers or devices requiring consistent network identification. Additionally, it is important to consider the impact of DHCP versus static IP addressing and configure accordingly to avoid conflicts or connectivity issues.
Overall, proficiency in changing the IP address on Linux systems enhances network administration capabilities, allowing for better control over device communication and security. By mastering both command-line tools and configuration file modifications, administrators can adapt to various environments and requirements efficiently. Maintaining proper documentation and backup of network configurations is also recommended to facilitate troubleshooting and system recovery.
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
