Linux/Network/Change ip

From Iveze
< Linux‎ | Network
Jump to: navigation, search

If a server is moved to another network, the static ip often needs to be modified. This must be done before connecting the network cable, with hardware monitor and keyboard. First find out which ip range is used by dhcp and choose an unused address outside the dhcp range. Then edit the ifcfg file, which is often called ifcfg-eth0, but sometimes it has a different name. Then it is the one that is not called ifcfg-lo.

vi /etc/sysconfig/network-scripts/ifcfg-eth0
In that file you will find several lines containing ip adresses. They must be changed to fit the new network.

IPADDR="The ip outside the dhcp range"
NETWORK="The ipaddr with a 0 on the fourth position"
GATEWAY="The ip of the router to the internet"
DNS1="The ip of the first dns server"
DNS2="The ip of the second dns server"
SEARCH="The workgroup name of smb servers in your network"

After saving the changes the network needs to be restarted.

Centos 6:

/etc/init.d/network restart

Centos 7:

systemctl restart network

Now the network cable can be connected and ssh used to operate the server.