How To Change Ip Address On Linux – Temporary Network Address Assignment

Giving your Linux computer a fixed IP address prevents connection issues on your local network, but sometimes you need to know how to change ip address on linux for troubleshooting or network reconfiguration. Whether you’re setting up a server, bypassing a conflict, or just testing a new subnet, changing your IP in Linux is straightforward once you understand the tools. This guide covers both temporary and permanent methods using the command line and GUI, so you can pick what works best for your setup.

Linux offers several ways to manage network settings, from simple commands like ip to editing configuration files. The approach depends on your distribution and whether you need a dynamic or static address. Let’s break it down step by step, starting with the quickest methods for immediate changes.

How To Change Ip Address On Linux

This section covers the core techniques to modify your IP address. You’ll learn commands that work on most distributions, plus how to make changes stick after a reboot. Focus on the method that matches your experience level and network requirements.

Using The Ip Command For Temporary Changes

The ip command is the modern replacement for ifconfig and is available on almost all Linux systems. It changes your IP address instantly but resets after a restart. This is ideal for testing or quick fixes.

  1. First, check your current network interface name with ip addr show. Look for something like eth0, enp3s0, or wlp2s0.
  2. To assign a new IP, use: sudo ip addr add 192.168.1.100/24 dev eth0. Replace the IP and interface with your own.
  3. Remove the old IP if needed: sudo ip addr del 192.168.1.50/24 dev eth0.
  4. Verify the change with ip addr show eth0.

Remember, this change is not permanent. If you reboot or restart networking, the old IP returns. Use this method for temporary adjustments or when you’re experimenting with different addresses.

Setting A Static IP With Netplan (Ubuntu 18.04+)

Ubuntu and its derivatives use Netplan for network configuration. It’s a YAML-based system that generates backend configs for NetworkManager or systemd-networkd. Here’s how to set a static IP permanently.

  1. Locate your Netplan file in /etc/netplan/. It’s usually named 01-netcfg.yaml or 00-installer-config.yaml.
  2. Edit it with sudo: sudo nano /etc/netplan/01-netcfg.yaml.
  3. Modify the file to look like this (adjust values to your network):
network:
  version: 2
  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]
  1. Apply the changes: sudo netplan apply.
  2. Check with ip addr show eth0 to confirm.

Netplan is strict about YAML syntax, so use spaces instead of tabs and ensure correct indentation. A common mistake is missing a colon or space, which causes errors. If you get an error, run sudo netplan try first to test before applying permanently.

Configuring Static IP On Older Ubuntu Or Debian

For systems using /etc/network/interfaces (like Debian or older Ubuntu), the process is different. This method is still common on servers and minimal installations.

  1. Open the interfaces file: sudo nano /etc/network/interfaces.
  2. Find your interface section and replace it with:
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
  1. Restart networking: sudo systemctl restart networking or sudo service networking restart.
  2. Verify with ifconfig or ip addr.

This method is reliable and well-documented. Some distributions also require you to disable NetworkManager if it conflicts. You can check with systemctl status NetworkManager.

Using NetworkManager (GUI And CLI)

Desktop users often prefer NetworkManager for its simplicity. You can change IPs through the GUI or the nmcli command-line tool. This works on Fedora, Ubuntu, and most modern distros.

Graphical Method

  1. Click the network icon in the system tray and select “Settings” or “Network Settings”.
  2. Choose your connection (wired or wireless) and click the gear icon.
  3. Go to the “IPv4” tab and change “Automatic (DHCP)” to “Manual”.
  4. Enter your desired IP, netmask, and gateway. Add DNS servers if needed.
  5. Click “Apply” and then toggle the connection off and on.

Command Line With Nmcli

  1. List connections: nmcli con show. Note the connection name (e.g., “Wired connection 1”).
  2. Modify the connection: sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24.
  3. Set method to manual: sudo nmcli con mod "Wired connection 1" ipv4.method manual.
  4. Add gateway: sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1.
  5. Add DNS: sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4".
  6. Apply changes: sudo nmcli con up "Wired connection 1".

NetworkManager is forgiving and allows easy switching between static and dynamic IPs. It’s the best choice for laptops that move between networks.

Changing IP On Red Hat And Fedora (Older Method)

Red Hat-based systems traditionally use /etc/sysconfig/network-scripts/ifcfg-* files. While newer versions use NetworkManager, these files still work for manual configuration.

  1. Edit the interface file: sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0.
  2. Change or add these lines:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
ONBOOT=yes
  1. Restart networking: sudo systemctl restart network (or sudo service network restart).
  2. Verify with ifconfig.

This method is less common now but still appears on CentOS 7 and older Fedora versions. For newer systems, stick with NetworkManager.

Changing IP With Systemd-Networkd

Some distributions, like Arch Linux or minimal setups, use systemd-networkd. It’s lightweight and integrates with systemd. Here’s how to set a static IP.

  1. Create a network file: sudo nano /etc/systemd/network/20-wired.network.
  2. Add the following content:
[Match]
Name=eth0

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
  1. Enable and start systemd-networkd: sudo systemctl enable --now systemd-networkd.
  2. Restart the service: sudo systemctl restart systemd-networkd.
  3. Check with ip addr.

This method is clean and efficient, but it might conflict with NetworkManager if both are running. Disable NetworkManager if you use this approach.

Using Ifconfig (Legacy Method)

While deprecated, ifconfig is still installed on many systems. It works similarly to ip but is less flexible. Install it if missing with sudo apt install net-tools (Debian/Ubuntu) or sudo dnf install net-tools (Fedora).

  1. Check current config: ifconfig.
  2. Assign a new IP: sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0.
  3. Add a gateway: sudo route add default gw 192.168.1.1.
  4. Verify with ifconfig eth0.

This method is temporary and not recommended for new setups. Use ip instead for better control and consistency.

Changing IP For Wireless Interfaces

Wireless interfaces follow the same principles but often require additional steps like connecting to the network first. Use iwconfig or nmcli to manage wireless connections.

  1. List wireless interfaces: iwconfig.
  2. Connect to a network: sudo nmcli dev wifi connect "SSID" password "password".
  3. Then change the IP using any method above, replacing the interface name (e.g., wlan0).

Wireless IP changes are identical to wired ones once connected. The main difference is that DHCP is more common for Wi-Fi, but static IPs work fine for trusted networks.

Verifying Your New IP Address

After making changes, always verify. Use these commands to confirm:

  • ip addr show – shows all interfaces and their IPs.
  • ip route show – displays the routing table, including the default gateway.
  • ping -c 4 8.8.8.8 – tests internet connectivity.
  • ping -c 4 google.com – tests DNS resolution.

If you can’t ping external sites, check your gateway and DNS settings. A common issue is forgetting to set the default route.

Troubleshooting Common Issues

Even with clear steps, problems arise. Here are frequent issues and fixes:

  • No network after change: Check if the interface is up with ip link set eth0 up. Ensure no typos in IP or gateway.
  • Duplicate IP address: Use arp-scan or nmap to check for conflicts. Choose an IP outside your DHCP range.
  • Changes not persisting: Verify you edited the correct config file. For Netplan, run sudo netplan generate before apply.
  • Permission denied: Use sudo for all network commands. Some distros require root for network changes.
  • NetworkManager overriding settings: Disable it with sudo systemctl stop NetworkManager and sudo systemctl disable NetworkManager if using static config files.

These solutions cover 90% of issues. If problems persist, check your router’s settings or consult distribution-specific forums.

Best Practices For IP Management

To avoid headaches, follow these tips:

  • Use a static IP outside your DHCP range to prevent conflicts.
  • Document your IP assignments in a spreadsheet or text file.
  • Test changes during maintenance windows to minimize disruption.
  • Keep a backup of your config files before editing.
  • Use dhclient to revert to DHCP if needed: sudo dhclient eth0.

These habits save time and prevent network outages. Linux gives you full control, but with that comes responsibility to manage addresses carefully.

Automating IP Changes With Scripts

If you frequently change IPs, write a script. Here’s a simple bash example for temporary changes:

#!/bin/bash
INTERFACE="eth0"
NEW_IP="192.168.1.200"
sudo ip addr flush dev $INTERFACE
sudo ip addr add $NEW_IP/24 dev $INTERFACE
sudo ip route add default via 192.168.1.1
echo "IP changed to $NEW_IP"

Save it as change_ip.sh, make it executable with chmod +x change_ip.sh, and run it with sudo ./change_ip.sh. Adjust variables as needed.

For permanent changes, you can write a script that modifies Netplan or interfaces files and then applies them. This is useful for testing multiple network configurations.

Frequently Asked Questions

How Do I Change My IP Address On Linux Without Restarting?

Use the ip addr add command to assign a new IP instantly. No restart needed. For a permanent change, edit config files and apply with netplan apply or restart networking.

Can I Change My IP Address On Linux To A Random One?

Yes, but it must be valid for your network. Use sudo ip addr add 192.168.1.150/24 dev eth0 with any unused IP. For privacy, use tools like macchanger for MAC addresses, not IPs.

What Is The Command To Check My Current IP On Linux?

Run ip addr show or ifconfig. The output shows all interfaces and their IPs. For public IP, use curl ifconfig.me.

Why Can’t I Change My IP Address On Linux?

Common reasons include: lack of sudo privileges, incorrect interface name, or NetworkManager overriding manual settings. Check permissions and disable NetworkManager if needed.

Does Changing IP On Linux Affect Other Devices?

Only if you use an IP already assigned to another device. Always check for conflicts using arp-scan or your router’s DHCP list. Otherwise, it’s safe.

Changing your IP on Linux is a fundamental skill that gives you control over network connectivity. Whether you use the ip command for quick tests or Netplan for permanent setups, the process is logical and repeatable. Practice on a non-critical system first, and always verify your changes. With these methods, you can handle any network reconfiguration task confidently.