Moving to a new IP address can be tedious and very time-consuming in many ways. In this article, we will show you two quick ways to customize all configuration files with just one command.
Please note: Make a backup of your server first. This tutorial contains commands with which you can intervene deeply in your system. Typos or other errors can cause serious errors. (Up to the complete unusability of the server)
The commands have been tested on the following operating systems:
- Debian 8
- Debian 9
The commands are most likely also available with all other offered operating systems (Debian 10, CentOS 6, Ubuntu, ...)
There are several configuration files on your server which are used by your installed packages. (These include web servers like apache2 or nginx, database servers like MySQL or MariaDB, possibly voice or game servers, etc.)
Enter the following command into your console to get an overview of all files containing the text IPADRESS:grep -rwl '/' -e 'IPADRESS' --exclude-dir 'proc' --exclude-dir 'sys'
--exclude-dir 'mysql'
--exclude-dir 'log' > /greplog.txt
Replace IPADRESS with the IP address of your server. Make sure that you have not accidentally removed any of the inverted commas (no quotation marks!).
Please note the following:
- However, this command does not change a file yet. It only serves to obtain a list of files in which the IP address of the server is entered.
- It is possible that the command will take several minutes to process, as all files on your system will be scanned. If the command takes longer than 20 minutes to execute, we recommend that you contact our customer support.
- Our customer support will be happy to create a list of the files found for you. Simply contact us via Ticket.
- For example, if your old IP address were 1.1.1.1, the command would look like this: grep -rwl '/' -e '1.1.1.1' --exclude-dir 'proc' --exclude-dir 'sys' --exclude-dir 'log' > /greplog.txt
If the command has been executed successfully, you can display a list of the files found with the following command:cat /greplog.txt
Warning: The following section makes changes to your files:
Once you have the list of files, you can start changing the IP address in the files. You have the following options:
1 - You change all files manually: You can do this for example with "nano". Enter the following command:nano /path/to/file
Use the arrow keys to navigate and adjust the locations found. To save, please press "Ctrl + X" then "y" and then the Enter key.
2 - You adjust the found files with a command provided by us: The following command adjusts the found files and replaces IPADRESS with NEWIPADRESS:grep
-rwl '/' -e 'IPADRESS' --exclude-dir 'proc' --exclude-dir 'sys'
--exclude-dir 'log' --exclude-dir 'mysql' | xargs sed -i 's/IPADRESS/NEWIPADRESS/g'
Please note the following:
- Variant 2 also edits files that can destroy services like MySQL. We recommend variant 1.
- Do not forget to replace IPADRESS with your old IP address and NEWIPADRESS with your new IP address in the back part of the command. If you forget this, it can cause errors in your system. If you have noticed that you have made a mistake, we recommend that you do not enter any further commands and contact our customer support.
- It is possible that the command will take several minutes to process as it will run through all the files on your system. If the command takes longer than 20 minutes to execute, we recommend contacting our customer support.
- For example, if your old IP address was 1.1.1.1 and your new IP address 2.2.2.2, the command would look like this: grep -rwl '/' -e '1.1.1.1' --exclude-dir 'proc' --exclude-dir 'sys' --exclude-dir 'log' | xargs sed -i 's/1.1.1.1/2.2.2.2/g'
If you have performed one of the two variants, please restart your server via the customer center or the "reboot" command. This may be because you are using a database where the old IP address is still registered. In this case, perform step 3 (below). If you are sure that you do not have a database server running and your services are still not available, please contact our customer support.
Sources: