When you change an IP address using ifconfig
, it might be temporary and could revert back to its previous state after a network service restart or system reboot. This happens because ifconfig
changes the IP address only in the current runtime configuration. For a permanent change, you need to update the network configuration files.
Making IP Address Changes Permanent
To make the IP address change permanent, you should modify the network configuration files. The specific file and its location can vary depending on your Linux distribution.
For Debian-based systems (e.g., Ubuntu):
Edit the /etc/network/interfaces
file:
- Open the file in a text editor:
sudo nano /etc/network/interfaces
- Find the configuration for your interface (e.g.,
eth0
orens33
) and update it with the new IP address:
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
- Save the file and exit the text editor.
- Restart the networking service to apply the changes:
sudo systemctl restart networking
For Red Hat-based systems (e.g., CentOS, Fedora, RHEL):
Edit the interface configuration file located in /etc/sysconfig/network-scripts/
:
- Open the specific interface configuration file in a text editor (replace
eth0
with your interface name):
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Update the configuration with the new IP address:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
- Save the file and exit the text editor.
- Restart the networking service to apply the changes:
sudo systemctl restart network
Using the ip
Command for Temporary Changes
If you want to change the IP address temporarily using the ip
command, you can do so as follows:
ip addr add 192.168.1.10/24 dev eth0
ip link set dev eth0 up
However, like with ifconfig
, these changes will not persist after a reboot or network service restart.
Verifying Changes
After making changes, verify the new IP address:
ifconfig eth0
Or using the ip
command:
ip addr show eth0
Conclusion
To ensure that your IP address changes are persistent across reboots, modify the appropriate network configuration files for your Linux distribution and restart the networking service. This will prevent the system from reverting to the old IP address.