1. Obtain the IPv4 address of a single network adapter. The method is as follows:
Method 1:
$/Sbin/ifconfig ethx | awk '/inet ADDR/{print $2}' | cut-F2-d ":"
Method 2:
$/Sbin/ifconfig ethx | awk '/inet ADDR/{print $2}' | awk-F: '{print $2 }'
Method 3:
$/Sbin/ifconfig ethx | sed-ne's /\(. * \) ADDR: \ ([[: digit:].] *\)\(. * \)/\ 2/P'
Replace X in ethx with the serial number of the NIC to be viewed, for example, eth0, eth1...
Obtain the IPv4 address of all NICs on the local machine. The method is as follows:
$/Sbin/ifconfig | awk '{if ($1 = "Inet" & $3 ~ /^ Bcast/) Print $2} '| cut-F2-d ":"
For an IPv6 network, simply modify the preceding command, for example:
$/Sbin/ifconfig | awk '/inet6/{print $3}' ---- All
$/Sbin/ifconfig ethx | awk '/inet6/{print $3}' ---- A single
Ii. Read methods in the AIX operating system:
# Ifconfig EN2 | sed-n "2,2 P" | awk '{print $2 }'
Ii. Reading methods in Linux
# Ifconfig eth0 | grep "Inet ADDR" | cut-F 2-D ":" | cut-F 1-d ""
About cut Parameters
-D is used to define the delimiter. The default Delimiter is the tab key,
-F indicates the field to be retrieved, and 2 indicates obtaining the second field separated by the separator specified by-D.
Of course, you can also use cut to get the specific characters in each line in the file, for example:
Cut-c3-5/etc/passwd
It is the third to fifth character of each line in the output/etc/passwd file.
The-C and-F parameters can be described as follows:
N nth character or field
N-from the first character or field to the end of the file
N-M from N to M characters or fields
-M: From the first character to the MB character or field