Main Menu

Search

Showing posts with label IP Addresses. Show all posts
Showing posts with label IP Addresses. Show all posts

LINUX: "ip addr" or "ip a" Command To List All Network Interfaces & IP Addresses In Linux (How To Doc)

Below "ip addr" or "ip a" commands can be used to list all network interfaces & IP addresses in Linux.
ip addr | grep -i global

ip a | grep -i global

Below is example output of above commands showing network bonds and their IP addresses.

# ip a | grep global
inet 192.168.20.6/24 brd 192.168.20.255 scope global bond1
inet 192.168.21.6/24 brd 192.168.21.255 scope global bond2
inet 192.168.23.6/24 brd 192.168.23.255 scope global bond0

Products to which Article Applies

All Linux Operating Systems

LINUX: GREP Command To Extract IP Addresses From Command Output Or File (How To Doc)

Below grep command can be used to extract IP addresses from a file.
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' <filename>

To extract IP addresses from command output below grep command can be used.

<command> | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

For example, below is grep command to extract IP addresses from "ip addr" command output.

ip addr | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

Below is sample output of above command.

10.10.10.137
10.20.11.12


Products to which Article Applies

All Linux Operating Systems


Additional Reference

https://www.shellhacks.com/regex-find-ip-addresses-file-grep/

LINUX: Ping Command To Ping Range of Sequential IP Addresses or Hostnames at the Same Time Simultaneously (How To Doc)

Below Ping command can be used to ping range of Sequential IP addresses at the same time simultaneously. In below ping command the sequential IP addresses we are pinging are 10.10.10.1 till 10.10.10.10. i variable defined in below command is the last octet of the IP addresses in sequence.
# for i in {1..10}; do ping -c 1 -t 1 10.10.10.$i > /dev/null 2>&1 && echo "Ping Status of  10.10.10.$i : Success" || echo "Ping Status of  10.10.10.$i : Failed" ; done

Below is example snippet of above command.

# for i in {1..10}; do ping -c 1 -t 1 10.10.10.$i > /dev/null 2>&1 && echo "Ping Status of  10.10.10.$i : Success" || echo "Ping Status of  10.10.10.$i : Failed" ; done
        Ping Status of  10.10.10.1 : Success
        Ping Status of  10.10.10.2 : Success
        Ping Status of  10.10.10.3 : Success
        Ping Status of  10.10.10.4 : Success
        Ping Status of  10.10.10.5 : Success
        Ping Status of  10.10.10.6 : Success
        Ping Status of  10.10.10.7 : Failed
        Ping Status of  10.10.10.8 : Success
        Ping Status of  10.10.10.9 : Success
        Ping Status of  10.10.10.10 : Failed

In case you want to test the ping to the hostnames you can use the same command as follows:

# for i in {1..5}; do ping -c 1 -t 1 testhost$i > /dev/null 2>&1 && echo "Ping Status of  testhost$i : Success" || echo "Ping Status of  testhost$i : Failed" ; done

In above command we assume the hostname starts with testhost1 and goes till testhost5. Below is sample output of above command.

        Ping Status of  testhost1 : Success
        Ping Status of  testhost2 : Success
        Ping Status of  testhost3 : Success
        Ping Status of  testhost4 : Success
        Ping Status of  testhost5 : Failed

Products to which Article Applies



All Linux Operating Systems.


Additional References


https://smallbusiness.chron.com/ping-ip-addresses-lan-68381.html
https://etherealmind.com/tech-notes-ping-sweep-ip-subnet/