How To Change Ip On Linux : Network Interface Configuration Steps

Adjusting your IP on Linux involves modifying network interface settings through either the command line or graphical tools. If you’re wondering how to change ip on linux, you’ve come to the right place. This guide covers everything from temporary changes to permanent configurations, using both terminal commands and GUI methods. Whether you’re a beginner or a seasoned admin, these steps will help you take control of your network settings quickly.

Changing your IP address on Linux is a common task for troubleshooting, privacy, or setting up a server. The process varies slightly depending on your distribution and network manager. Let’s break it down step by step, starting with the simplest methods.

Why Change Your IP On Linux

There are several reasons you might need to change your IP address. Maybe you’re dealing with a network conflict, or you want to test a new configuration. Some users do it for privacy when connecting to public networks. Others need a static IP for hosting services like a web server or SSH access.

Whatever your reason, Linux gives you full control. You can change the IP temporarily for a session, or make it permanent so it survives reboots. The method you choose depends on your specific needs and your Linux distribution.

Common Scenarios For Changing IP

  • Fixing network connectivity issues
  • Avoiding IP conflicts on a local network
  • Setting up a static IP for a server
  • Testing network applications
  • Enhancing privacy on public Wi-Fi

How To Change Ip On Linux Using The Command Line

The command line is the most direct way to change your IP on Linux. It works on almost all distributions, including Ubuntu, Debian, Fedora, and CentOS. You’ll need superuser privileges, so use sudo for most commands.

First, identify your network interface. Run ip link show or ifconfig -a to list all interfaces. Common names are eth0, enp0s3, or wlan0 for wireless. Note the interface you want to modify.

Changing IP Temporarily With Ip Command

The ip command is modern and preferred over the older ifconfig. To change your IP temporarily, use this syntax:

sudo ip addr add 192.168.1.100/24 dev eth0

This adds a new IP address to the interface. To remove the old one, use:

sudo ip addr del 192.168.1.50/24 dev eth0

Replace the IP addresses and subnet mask with your desired values. The /24 means a subnet mask of 255.255.255.0. Changes made this way are lost after a reboot.

Setting A Default Gateway

After changing your IP, you might need to update the default gateway. Use this command:

sudo ip route add default via 192.168.1.1

Replace 192.168.1.1 with your router’s IP. This ensures your traffic routes correctly to the internet.

Using Ifconfig For Older Systems

Some older distributions still use ifconfig. The command is similar:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

Then set the gateway with:

sudo route add default gw 192.168.1.1

Note that ifconfig is deprecated, so stick with ip if possible.

Permanent IP Changes Using Netplan (Ubuntu 18.04+)

For modern Ubuntu systems, Netplan is the default network configuration tool. It uses YAML files to define network settings. To make a permanent IP change, edit the Netplan configuration file.

First, find the file in /etc/netplan/. It’s usually named 01-netcfg.yaml or 00-installer-config.yaml. Use a text editor with sudo:

sudo nano /etc/netplan/01-netcfg.yaml

Here’s an example configuration for 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]

After editing, apply the changes with:

sudo netplan apply

Your new IP is now permanent and will survive reboots. Test it with ip addr show eth0.

Common Netplan Mistakes

  • Incorrect YAML indentation (spaces, not tabs)
  • Forgetting to set dhcp4: no
  • Using the wrong interface name
  • Not specifying DNS servers

Changing IP On Older Ubuntu Or Debian Systems

For systems using /etc/network/interfaces, the process is different. This method is common on Debian and older Ubuntu versions. Edit the interfaces file with:

sudo nano /etc/network/interfaces

Add or modify the entry for your interface:

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 with:

sudo systemctl restart networking

Or use sudo /etc/init.d/networking restart on older systems.

Using NetworkManager For GUI And CLI

NetworkManager is the default on many desktop distributions like Ubuntu, Fedora, and Linux Mint. It provides both a GUI and a command-line tool called nmcli. This is the easiest way for beginners to change IP.

Changing IP With Nmcli

First, list your connections:

nmcli connection show

Note the connection name, like “Wired connection 1”. Then modify it:

nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.100/24

Set the method to manual:

nmcli connection modify "Wired connection 1" ipv4.method manual

Add the gateway and DNS:

nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.1.1

nmcli connection modify "Wired connection 1" ipv4.dns 8.8.8.8

Finally, restart the connection:

nmcli connection down "Wired connection 1" && nmcli connection up "Wired connection 1"

Using The GUI Network Settings

If you prefer a graphical interface, most Linux desktops have a network settings app. Click on the network icon in the system tray, then select “Settings” or “Network Connections”.

Choose your connection and click the gear icon. Under the IPv4 tab, switch from “Automatic (DHCP)” to “Manual”. Enter your desired IP, netmask, gateway, and DNS. Save and apply the changes.

This method is intuitive and doesn’t require memorizing commands. It’s perfect for desktop users who just want a quick change.

Changing IP On Fedora And RHEL Systems

Fedora and Red Hat Enterprise Linux use NetworkManager by default, but they also support traditional configuration files. For a permanent change, you can edit files in /etc/sysconfig/network-scripts/.

Find the file for your interface, like ifcfg-eth0. Edit it with:

sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0

Set these parameters:

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

Then restart the network service:

sudo systemctl restart network

On newer Fedora versions, you might also use NetworkManager’s nmcli as described earlier.

Changing IP Temporarily With Dhclient

If you want to get a new IP from your router’s DHCP server, you can release and renew the lease. This is useful when you just need a different address without manual configuration.

Release the current IP:

sudo dhclient -r eth0

Then request a new one:

sudo dhclient eth0

Your router will assign a new IP from its pool. This method is quick and works on most networks.

When To Use Dhclient

  • You don’t need a specific IP
  • Your network supports DHCP
  • You want to troubleshoot connectivity
  • You’re on a public network

Changing IP For Wireless Interfaces

Wireless interfaces work the same way as wired ones, but you might need to reconnect to the network after changing the IP. Use wlan0 or whatever your wireless interface is named.

For example, with nmcli:

nmcli connection modify "MyWiFi" ipv4.addresses 192.168.1.200/24

Then reconnect. Note that some routers restrict static IPs to certain addresses, so check your router’s DHCP range.

Verifying Your New IP

After making changes, always verify the new IP is active. Use these commands:

ip addr show eth0

Or:

ifconfig eth0

Check connectivity with:

ping 8.8.8.8

If you can’t ping, double-check your gateway and DNS settings. Also ensure no other device on the network is using the same IP.

Troubleshooting Common Issues

  • IP conflict: Use a different address
  • No internet: Check gateway and DNS
  • Changes not persisting: Use the right config file
  • Interface not found: Verify interface name

Using Systemd-Networkd For Permanent Config

Some distributions use systemd-networkd for network management. This is common on Arch Linux and some minimal setups. Create a configuration file in /etc/systemd/network/.

For example, create 20-wired.network:

[Match]
Name=eth0

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8

Then enable and start systemd-networkd:

sudo systemctl enable systemd-networkd

sudo systemctl start systemd-networkd

This method is clean and modern, but requires some setup.

Changing IP With A Script

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

#!/bin/bash
INTERFACE="eth0"
IP="192.168.1.100"
GATEWAY="192.168.1.1"
sudo ip addr flush dev $INTERFACE
sudo ip addr add $IP/24 dev $INTERFACE
sudo ip route add default via $GATEWAY

Save it as changeip.sh, make it executable with chmod +x changeip.sh, and run it with sudo. You can modify the variables for different scenarios.

Security Considerations

Changing your IP doesn’t automatically make you anonymous. Your traffic is still visible to your ISP and network admins. For privacy, consider using a VPN or Tor. Also, be careful when setting static IPs to avoid conflicts with other devices.

Always use trusted DNS servers. Public ones like Google (8.8.8.8) or Cloudflare (1.1.1.1) are reliable. Avoid unknown DNS servers that could redirect your traffic.

FAQ: How To Change IP On Linux

Can I change my IP without sudo?

No, most network changes require root privileges. You can use sudo or log in as root. Some GUI tools might ask for your password.

Will changing my IP affect other devices?

Only if you use an IP already in use. Always check for conflicts. Using DHCP is safer for avoiding issues.

How do I change IP on Linux permanently?

Use Netplan, /etc/network/interfaces, or NetworkManager. The method depends on your distribution. See the sections above for details.

What is the difference between static and dynamic IP?

A static IP never changes, while a dynamic IP is assigned by DHCP and can change. Static IPs are better for servers, dynamic for casual use.

Can I change my public IP on Linux?

Your public IP is assigned by your ISP. Changing it requires restarting your modem or using a VPN. Local network changes only affect your private IP.

Final Thoughts On Changing IP On Linux

Now you know multiple ways to change your IP on Linux. The command line gives you speed and flexibility, while GUI tools offer simplicity. Choose the method that fits your workflow and distribution.

Remember to test your changes and troubleshoot if needed. With practice, you’ll be able to adjust network settings in seconds. Linux gives you full control, so don’t be afraid to experiment.

If you run into issues, check your configuration files for typos. Indentation errors in YAML are a common problem. Also ensure your interface name is correct, as it can vary between systems.

For most users, NetworkManager or Netplan are the best choices. They handle persistence automatically and integrate with the desktop. Advanced users might prefer raw configuration files or scripts.

Keep this guide bookmarked for future reference. Changing IP on Linux is a fundamental skill that will serve you well in networking and system administration. Happy configuring!