Introduction:
Changing the IP address in Linux is a fundamental skill for system administrators and enthusiasts alike. Whether you’re troubleshooting network issues, setting up a new server, or simply optimizing your network configuration, knowing how to change IP addresses efficiently is essential. In this comprehensive guide, we’ll walk you through the various methods and best practices for changing IP addresses in Linux, empowering you to take control of your network configuration with confidence.
How to Change IP Address in Ubuntu: A Step-by-Step Guide
Prerequisites
sudo permissions
Login to Linux Terminal
Use a tool like Putty to log into the Terminal console
Check the Current IP
The system must have a network tools utility installed, if not then run the below command to install
apt install net-tools
run ifconfig -a command
ifconfig -a
For my network, the current adapter is eth0
. It could be different for your system
- Note the current network adapter name
eth0: flags=4163 mtu 1500
inet 10.0.0.41 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::215:5dff:fe05:3283 prefixlen 64 scopeid 0x20
ether 00:15:5d:05:32:83 txqueuelen 1000 (Ethernet)
RX packets 5432265 bytes 489778611 (489.7 MB)
RX errors 0 dropped 1454839 overruns 0 frame 0
TX packets 1183678 bytes 4957049089 (4.9 GB)
In the above example, the IP address is 10.0.0.41 and the Subnet mask is 255.255.255.0
Subnet Calculation
Now, from the above example, the subnet mask is 255.255.255.0 which means it is a 24-bit network so the subnet would be 10.0.0.0/24 (range 10.0.0.0-10.0.0.255)
Read more Top Linux Commands for Seamless Operations
Make configuration changes
Netplan tool: Netplan is the default network management tool for the latest Ubuntu versions. Configuration files for Netplan are written using YAML and end with the extension .yaml
.
** go to net plan directory
cd /etc/netplan
ls
** check for the below file
00-installer-config.yaml
** Edit the file with your favourite editor
nano 00-installer-config.yaml
The editor will show the configuration below:
In the addresses section change the IP address with the Subnet Suffix
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
addresses:
- 10.0.0.41/24
nameservers:
addresses:
- 10.0.0.2
- 10.0.0.1
search: []
routes:
- to: default
via: 10.0.0.1
version: 2
Apply and test the changes
Now, test the configuration to make sure it won’t break anything if test is successful it will ask to apply
sudo netplan try
That’s it on How to Change IP Address in Ubuntu
- What is Active Directory? A Complete Guide for IT Professionals - 18 November 2024
- Enterprise Virtualization Platforms Comparison: A Technical Deep Dive - 29 October 2024
- Docker Swarm: The Complete Guide to Container Orchestration - 28 October 2024