Home > System Tutorial > LINUX > How To Assign IP Address To Remote Linux Systems Via SSH

How To Assign IP Address To Remote Linux Systems Via SSH

尊渡假赌尊渡假赌尊渡假赌
Release: 2025-03-21 09:09:13
Original
583 people have browsed it

This guide demonstrates how to assign an IP address to a remote Linux system using the nmcli command. This is useful for various reasons, including network policy compliance, troubleshooting, network migration, and enhanced security.

Several scenarios necessitate remote IP address changes:

  • Network Policy Adherence: Many organizations mandate specific IP address ranges.
  • Network Troubleshooting: Altering the IP address can sometimes resolve network issues.
  • Network Migration: Moving a system to a new network requires an IP address change.
  • Security Enhancement: A new IP address makes the system harder for attackers to identify.

Using nmcli via SSH provides a convenient solution.

Assigning an IP Address with nmcli

First, identify the remote system's network interface using:

ssh user@remote_ip 'nmcli con show'
Copy after login

Replace user and remote_ip with the appropriate credentials. The output will show the network interface name (e.g., Wired connection 1).

Next, modify the IP address using:

ssh -t user@remote_ip "sudo nmcli con modify 'Interface Name' ipv4.address new_ip/subnet_mask"
Copy after login

Replace Interface Name, new_ip, and subnet_mask with the correct values (e.g., "Wired connection 1", 192.168.1.50/24). The -t flag ensures proper password prompting. You'll be prompted for the remote user's password, and then for sudo on the remote machine.

Verify the change with:

ssh user@remote_ip "ip addr show interface_name"
Copy after login

Replace interface_name with the interface's name (e.g., ens18).

Alternative (Insecure) Method:

While less secure, you can use echo and piping to avoid repeated password entry:

echo 'password' | ssh -t user@remote_ip "sudo -S nmcli con modify 'Interface Name' ipv4.address new_ip/subnet_mask"
Copy after login

Caution: This method exposes your password and is strongly discouraged. Using SSH keys is the recommended secure approach.

Automated Script:

A Bash script, nmcli_remote_ip_changer.sh, simplifies this process. It prompts for remote credentials, identifies interfaces, and applies the new IP configuration, including gateway and DNS settings. The script can be found at [GitHub Link - Replace with actual GitHub link if available]. Remember to make it executable (chmod x nmcli_remote_ip_changer.sh) before running.

Conclusion:

nmcli offers a streamlined method for managing remote Linux system IP addresses. While direct command execution is efficient, using a script like nmcli_remote_ip_changer.sh enhances usability and security when coupled with SSH key-based authentication. Prioritize secure practices to protect your systems.

How To Assign IP Address To Remote Linux Systems Via SSH How To Assign IP Address To Remote Linux Systems Via SSH

The above is the detailed content of How To Assign IP Address To Remote Linux Systems Via SSH. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template