How can I view all IPs within a network segment in CentOS?

To view all IP addresses within a specific network segment, you can use the following command:

nmap -sn <网段>

Specify the desired subnet you want to view, such as `192.168.0.0/24`. This command will use the nmap tool to scan all hosts within the given subnet and display their IP addresses. Make sure nmap tool is installed in your CentOS system before running this command.

Additionally, if you simply want to list all IP addresses belonging to the current system’s network, you can use the following command:

ip addr | grep "inet " | awk '{print $2}' | cut -d'/' -f1

This command will list all IPv4 addresses and remove the CIDR suffix.

Please note that the above command must be executed with root or a user with sudo privileges.

bannerAds