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'
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"
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"
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"
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.
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!

This guide explores essential Linux tools for monitoring and troubleshooting disk I/O performance, a crucial metric impacting server speed and application responsiveness. Disk I/O performance directly affects how quickly data is read from and written

For new Linux users, identifying connected devices is crucial, especially USB drives. This guide provides several command-line methods to determine a USB device's name, essential for tasks like formatting. While USB drives often auto-mount (e.g., /

One of the most common problems with Linux systems, especially those with limited disk space, is the exhaustion of root partition (/) space. When this problem occurs, you may encounter the following error: No space left on device Don’t panic! This just means that your root directory (/partition) is full, which is a common problem, especially on systems with limited disk space or servers running 24/7. When this happens, you may encounter the following problems: The package cannot be installed or upgraded. System startup failed. The service cannot be started. Unable to write to logs or temporary files. This article walks you through practical steps to identify problems, clean up space safely, and prevent them from happening again. These instructions are suitable for beginners

This article explores top-notch Notepad alternatives for Linux users. Notepad , while excellent on Windows, lacks a Linux version. This guide offers a diverse range of options to suit various needs and preferences. Top Notepad Alternatives for

Several days ago, I encountered a 32-bit CentOS 8 distribution and decided to test it on an older 32-bit system. Post-boot, I discovered a network connectivity issue; the connection would drop, requiring manual restoration after each reboot. This pr

Let's clarify what constitutes a bad sector or bad block: it's a portion of a hard drive or flash memory that's become unreadable or unwritable, typically due to physical damage to the disk surface or malfunctioning flash memory transistors. Accumul

The cp command, short for "copy," is a fundamental tool in Linux and other Unix-like systems for duplicating files and directories. While efficient for local file transfers, for network-based copies, scp (secure copy) is preferred due to i

When using the rm command to delete a file or directory in Linux system, if you encounter the following error: rm: cannot remove 'file-or-directory': Device or resource busy Don't worry, this is a common problem, which means that the file or directory you are trying to delete is currently being used by the system or running process. Cause of error The "Device or Resource Busy" message indicates that the file or directory is in use. To avoid damaging the system or causing data loss, Linux prevents deleting files in use. Common reasons include: Your terminal is currently in the directory you want to delete. The program or process is using the file or directory.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
