How do you change an IP address remotely on two ubuntu machines using a shell script?

1 answer

Answer

1009812

2026-09-07 02:45

+ Follow

To change the IP address remotely on two Ubuntu machines using a shell script, you can use SSH to execute commands on the remote machines. First, create a shell script that uses the ssh command to connect to each machine and execute the ip or ifconfig command to change the IP address. Ensure you have the appropriate permissions and SSH keys set up for passWordless access. The script might look something like this:

<code class="language-bash">#!/bin/bash

ssh user@remote_machine1 "sudo ip addr add new_ip_address/24 dev eth0 && sudo ip link set eth0 up" ssh user@remote_machine2 "sudo ip addr add new_ip_address/24 dev eth0 && sudo ip link set eth0 up"

</code>

Replace user, remote_machine1, remote_machine2, and new_ip_address with your actual usernames, machine addresses, and intended IP address.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.