Content area
Full text
Changing the IP address of a Linux system from dynamic to static is not difficult, but requires a little care and a set of commands that you likely rarely use. This post provides a bash script that will run through the process, collect the needed information and then issue the commands required to make the changes while asking as little as possible from the person running it.
The bulk of the script focusses on making sure that the correct settings are used. For example, it collects the 36-charater universally unique identifier (UUID) from the system so that you never have to type it in or copy and paste it into place.
After asking only a question or two, the script runs a series of nmcli (Network Manager) commands that will change the IP address if requested and set the address to be static. Notice that a number of the fields in the commands that it will run as shown below are variables derived from earlier commands in the script.
sudo nmcli connection modify $UUID IPv4.address $IP/$sz
sudo nmcli connection modify $UUID IPv4.gateway $router
sudo nmcli connection modify $UUID IPv4.method manual
sudo nmcli connection down $UUID
sudo nmcli connection up $UUID
If a new IP address is requested, the script will check the format of the address requested and make sure that it is compatible with the current network.
Prior to running the commands shown above, the script collects the variables used to make sure...





