How to Change Hostname and IP Address in Linux
Linux is a versatile operating system that allows users to customize various settings, including the hostname and IP address. In this tutorial, we will guide you through the process of changing the hostname and IP address in Linux.
Changing Hostname
The hostname is a label assigned to a device on a network. To change the hostname in Linux, follow these steps:
- Open a terminal window.
- Enter the following command to edit the hostname file:
sudo nano /etc/hostname
Replace the current hostname with the desired hostname and save the file.
- Next, edit the hosts file by entering the following command:
sudo nano /etc/hosts
Replace the current hostname with the new hostname in this file as well.
Changing IP Address
IP address is a unique numerical label assigned to each device connected to a network. Here's how you can change the IP address in Linux:
- Open a terminal window.
- Enter the following command to edit the network configuration file:
sudo nano /etc/network/interfaces
Locate the line that begins with "iface" followed by the network interface (e.g., eth0) and the word "inet." Change the IP address after "address" to the new IP address.
- Save the file and restart the network service by entering the following command:
sudo systemctl restart networking
Verifying Changes
To verify that the changes have been successfully applied, you can use the following commands:
- To check the hostname:
hostname
- To check the IP address:
ifconfig
Conclusion
Changing the hostname and IP address in Linux is a simple process that can be done through the terminal. By following the steps outlined in this tutorial, you can customize your system to suit your needs. Remember to verify the changes to ensure they have been applied correctly.