How To Change Your IP Address in Linux Shell

Your computer’s IP (Internet Protocol) Address is like a personal identification number that is assigned to you when you enter a building, or it is like your cell phone number. Your computer’s IP Address is exclusive to your computer but it can also change if you have a router that is configured to acquire an IP address dynamically. This means that every time the network connection is interrupted, another IP Address will be assigned to you. You can manually change your IP address in a Linux shell for the current session or set a permanent one to use on your computer.

1. Display IP Address

First launch a Linux Shell prompt on your computer that operates on Linux distribution. Type the networking command “# ifconfig eth0” and you will get the details of your connection and Ethernet interface. You can view information about your computer’s IP address, Subnet Mask, Broadcast address and packet details after entering the Linux networking command. The objective of viewing your IP address on your computer first is so you can create another IP address that is different from the one that the computer is currently using.

2. Change IP Address

Now that you know what IP Address is currently being used by the computer you can think of a different one to use. You can use the same ifconfig command to enter the new IP address in the shell prompt. Enter the command and the new IP address followed by the netmask value so your command line will look like the following:

# ifconfig eth0 192.168.X.X netmask up

Enter any value in place of the Xs in the command line. Type the command line to display the connection and Ethernet status again to see if the new IP address is successfully being used by your computer.

# ifconfig eth0

The new IP address will be valid for the existing session only and will change when you log off and log in again.

3. Permanently change IP address

If you want to permanently change and keep the new IP address on your computer you can edit the details in the Linux shell. Enter the command line:

cat /etc/sysconfig/network-scripts/ifcfg-eth0

The output will show you the networking information that you can edit with the new IP address. You will have to change the BOOTPROTO to none and make sure ONBOOT is set to yes. The changes you will make are:

The objective here is to stop the machine from automatically assigning an IP address so you can provide one manually. Use the command “# service network restart” after making changes to the IP address so the service can restart and the changes can take effect.


Share this article!

Follow us!

Find more helpful articles: