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:
- Check your current network interface name:
Run the following command to list all network interfaces:
ip addr show
- Take down the network interface:
Before changing the IP address, you need to bring down the network interface. Replaceinterface_name
with the name of your network interface obtained from the previous step.
sudo ip link set dev interface_name down
- Change the IP address:
Replacenew_ip_address
andnetmask
with your desired IP address and netmask.
sudo ip addr add new_ip_address/netmask dev interface_name
- 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.