How to change ip address in linux with command.

In Linux, you can change your IP address using the ifconfig or ip command. Here’s how you can do it using the ip command:

  1. Check your current network interface name:
    Run the following command to list all network interfaces:
   ip addr show
  1. Take down the network interface:
    Before changing the IP address, you need to bring down the network interface. Replace interface_name with the name of your network interface obtained from the previous step.
   sudo ip link set dev interface_name down
  1. Change the IP address:
    Replace new_ip_address and netmask with your desired IP address and netmask.
   sudo ip addr add new_ip_address/netmask dev interface_name
  1. Bring up the network interface:
    After changing the IP address, bring the interface back up.
   sudo ip link set dev interface_name up

For example, if you want to change the IP address of the interface eth0 to 192.168.1.100 with a netmask of 255.255.255.0, the commands would look like this:

sudo ip link set dev eth0 down
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set dev eth0 up

Remember to replace eth0 with your actual interface name and adjust the IP address and netmask as per your network configuration.

Leave a comment