Changing the IP address on Linux systems like Ubuntu 18, 20, 22, 24, Debian 10, 11 ,12 and CentOS 7, 9 is a common task for network administrators and tech enthusiasts. Whether you need to switch to a static IP, configure a new network, or simply change your IP for testing purposes, this guide will walk you through the process on each of these popular distributions.
There are several reasons you might need to change your IP address:
– **Static IP Configuration**: To set up a server or ensure consistent access to your device on a network.
– **Network Troubleshooting**: To resolve conflicts with other devices on the network.
– **Testing and Development**: To simulate different network environments.
Ubuntu 18, 20, 22, 24 and Debian 10, 11, 12 use `netplan` (for recent versions) or `interfaces` for older versions. Here’s how to change the IP address using both methods.
Edit the Netplan Configuration File
sudo nano /etc/netplan/01-netcfg.yaml
Locate the ethernets
section and update the addresses
, gateway4
, and nameservers
fields. For example:
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 Changes:
sudo netplan apply
CentOS 7 and Centos 9 use NetworkManager
for network configuration. Here’s how to change the IP address on CentOS.
nmcli
CommandList the Network Connections:
nmcli con show
Use the following command to change the IP, replacing eth0
with your interface name:
nmcli con mod eth0 ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8 8.8.4.4"
nmcli con mod eth0 ipv4.method manual
Restart the Network:
nmcli con up eth0
Edit the Network Interface Script:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
Modify or add the following lines:
BOOTPROTO=none
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
Restart the Network Service:
sudo systemctl restart network
Changing the IP address on Linux distributions like Ubuntu 18, Ubuntu 20, Ubuntu 22, Ubuntu 24, Debian 10, Debian 11, Debian 12, CentOS 7 and Centos Stream 9 is straightforward when you know the correct commands and configuration files. Whether you’re using netplan
, interfaces
, or nmcli
, this guide provides the steps needed to ensure your system is correctly configured. Regularly updating and managing your IP settings can improve network performance, security, and overall system functionality.
If you found this guide helpful, don’t forget to share it with others who might benefit from it!
Leave a Reply