Configuring a static IP address in Linux gives your machine a permanent network identity, but sometimes you just need to know how to change ip address in linux quickly. Whether you’re troubleshooting a connection issue, setting up a server, or just want to hide your network activity, adjusting your IP address is a fundamental skill. This guide walks you through every method, from simple commands to persistent configuration, so you can take control of your Linux network settings.
Changing your IP address might sound technical, but it’s actually pretty straight forward once you know the tools. You can do it temporarily for a session or make it permanent across reboots. We’ll cover both approaches using the command line and graphical tools, so you can pick what works best for your setup.
How To Change Ip Address In Linux
Before diving into the steps, it helps to understand what an IP address is. Your IP is like a digital mailing address for your computer on a network. When you change it, you’re telling the network to send data to a new location. This can fix conflicts, bypass restrictions, or simply test new configurations.
There are two main types of IP addresses: dynamic and static. Dynamic IPs are assigned automatically by a DHCP server, while static IPs are manually set. Most home networks use dynamic IPs, but servers often need static ones. The methods below let you switch between them or set a specific address.
Check Your Current IP Address First
You need to know what you’re working with before making changes. Open a terminal and type ip addr show or ifconfig (if installed). This shows all network interfaces and their current IPs. Look for inet lines under interfaces like eth0 (wired) or wlan0 (wireless).
- ip addr show – Modern command, works on most distros
- ifconfig – Older tool, may need
sudo apt install net-tools - hostname -I – Quick list of all IP addresses
Write down your current IP, subnet mask, and gateway. You’ll need these if you want to revert or set a static address later.
Temporary IP Change Using Ip Command
The fastest way to change your IP is with the ip command. This change only lasts until you reboot or restart the network service. It’s perfect for testing or quick fixes.
- Open a terminal and become root or use
sudo. - Bring the interface down:
sudo ip link set eth0 down - Assign a new IP:
sudo ip addr add 192.168.1.100/24 dev eth0 - Bring the interface back up:
sudo ip link set eth0 up - Verify with
ip addr show eth0
Replace eth0 with your interface name and 192.168.1.100/24 with your desired IP and subnet. The /24 means subnet mask 255.255.255.0. If you need a different mask, adjust the CIDR notation.
Setting A Default Gateway
After changing your IP, you might need to set a gateway for internet access. Use: sudo ip route add default via 192.168.1.1. Replace 192.168.1.1 with your router’s IP. Check routing with ip route show.
Temporary IP Change Using Ifconfig
If your system still uses ifconfig, the process is similar. This command is older but still works on many distros.
- Bring the interface down:
sudo ifconfig eth0 down - Set the new IP:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 - Bring it up:
sudo ifconfig eth0 up - Add gateway:
sudo route add default gw 192.168.1.1
Again, this is temporary. Rebooting will reset these changes.
Permanent IP Change Using Netplan (Ubuntu 17.10+)
For a change that survives reboots, you need to edit configuration files. Modern Ubuntu uses Netplan with YAML files. This is the recommended method for persistent changes.
- Find your Netplan config file:
ls /etc/netplan/– usually01-netcfg.yamlor00-installer-config.yaml - Backup the file:
sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak - Edit with nano or vim:
sudo nano /etc/netplan/01-netcfg.yaml - Set a static IP. Example config:
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] - Apply the changes:
sudo netplan apply - Verify with
ip addr show
Indentation is critical in YAML. Use spaces, not tabs. If you get errors, run sudo netplan try to test before applying permanently.
Permanent IP Change Using /Etc/network/interfaces (Debian/Ubuntu Older)
Older Debian-based systems use /etc/network/interfaces. This is still common on Raspberry Pi OS or older Ubuntu versions.
- Open the file:
sudo nano /etc/network/interfaces - Find the section for your interface. It might look like:
auto eth0 iface eth0 inet dhcp
- Change to static:
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 - Restart networking:
sudo systemctl restart networkingorsudo service networking restart
Some systems may need sudo ifdown eth0 && sudo ifup eth0 instead of restarting the service.
Permanent IP Change Using Nmcli (NetworkManager)
If your system uses NetworkManager, you can change IPs with nmcli. This works on Fedora, CentOS, and many desktop Linux distros.
- List connections:
nmcli con show - Change to static:
sudo nmcli con mod "YourConnectionName" ipv4.addresses 192.168.1.100/24 - Set method to manual:
sudo nmcli con mod "YourConnectionName" ipv4.method manual - Set gateway:
sudo nmcli con mod "YourConnectionName" ipv4.gateway 192.168.1.1 - Set DNS:
sudo nmcli con mod "YourConnectionName" ipv4.dns "8.8.8.8 8.8.4.4" - Apply:
sudo nmcli con up "YourConnectionName"
You can also use nmtui for a text-based graphical interface. Just type sudo nmtui and navigate with arrow keys.
Change IP Using DHCP Renewal
If you just want a new dynamic IP from your router, you can release and renew the lease. This is the simplest method if you don’t need a specific address.
- Release the current IP:
sudo dhclient -r - Request a new one:
sudo dhclient - Check the new IP:
ip addr show
This works for both wired and wireless interfaces. Your router assigns a new IP from its pool. It might give you the same one if the lease hasn’t expired.
Change IP For Specific Interface With Dhclient
You can target a specific interface: sudo dhclient -r eth0 then sudo dhclient eth0. This is useful if you have multiple interfaces.
Using Graphical Tools (Desktop Users)
If you’re on a desktop environment like GNOME or KDE, you can change IPs without the terminal. This is the easiest for beginners.
- GNOME Settings: Go to Settings > Network > Wired or Wi-Fi > Click the gear icon > IPv4 tab > Change to Manual > Enter IP, netmask, gateway, DNS.
- KDE Plasma: System Settings > Connections > Select your connection > Edit > IPv4 tab > Manual method.
- XFCE: Settings > Network Connections > Select connection > Edit > IPv4 Settings.
These changes are permanent until you change them again. They modify the same configuration files under the hood.
Common Issues And Fixes
Sometimes things go wrong. Here are typical problems and solutions.
- No internet after change: Check your gateway and DNS settings. Ping your router:
ping 192.168.1.1. If that works, check DNS withping 8.8.8.8. - IP conflict: Two devices with the same IP. Use a unique address outside your DHCP range, like 192.168.1.200.
- Interface not found: Run
ip link showto list interfaces. Names likeenp3s0are common on newer systems. - Permission denied: Use
sudofor all network commands. - Netplan errors: Check indentation with
sudo netplan generateto debug.
Changing IP For Wireless Interfaces
Wireless interfaces work the same way. Replace eth0 with wlan0 or your wireless interface name. For Netplan, add the config under wifis: instead of ethernets:.
network:
version: 2
wifis:
wlan0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8]
access-points:
"YourSSID":
password: "YourPassword"
Using Systemd-Networkd
Some distros use systemd-networkd. Edit files in /etc/systemd/network/. Create a file like 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: sudo systemctl enable systemd-networkd && sudo systemctl start systemd-networkd.
Security Considerations
Changing your IP doesn’t make you anonymous. Your ISP still sees your traffic. For privacy, use a VPN or Tor. Also, avoid using IPs that belong to other devices to prevent conflicts.
If you’re on a corporate network, changing your IP might violate policies. Always check with your admin first.
Testing Your New IP
After making changes, test connectivity:
- Ping your gateway:
ping -c 4 192.168.1.1 - Ping an external site:
ping -c 4 google.com - Check your public IP:
curl ifconfig.me - Verify local IP:
ip addr show
If everything works, you’re good. If not, double-check your settings or revert to DHCP.
Reverting To DHCP
To go back to automatic IP assignment, reverse your changes. For Netplan, set dhcp4: yes and remove the static address lines. For /etc/network/interfaces, change back to iface eth0 inet dhcp. Then restart networking.
Frequently Asked Questions
Can I Change My IP Address Without Root Access?
No, most network changes require superuser privileges. You need sudo or root access to modify IP settings. Some graphical tools may prompt for your password.
Will Changing My IP Address Affect Other Devices?
Only if you create an IP conflict by using an address already in use. Choose an address outside your DHCP range to avoid issues. Your change only affects your machine.
How Do I Change My IP Address In Linux Permanently?
Edit your network configuration file (Netplan, /etc/network/interfaces, or NetworkManager) and set a static IP. Apply the changes and they will persist across reboots.
What Is The Difference Between Static And Dynamic IP?
A static IP is manually set and never changes. A dynamic IP is assigned by a DHCP server and can change over time. Static is better for servers, dynamic for regular use.
Why Would I Need To Change My IP Address?
Common reasons include fixing network conflicts, testing configurations, bypassing IP-based restrictions, or setting up a home server. It’s also useful for troubleshooting.
Now you have all the tools to change your IP address in Linux, whether you need a quick temporary fix or a permanent static setup. Start with the temporary methods to test, then move to persistent configs once you’re sure. Practice on a test machine if you’re unsure, and always backup your config files before editing. With these steps, you’re ready to manage your network like a pro.