Posted: . At: 10:29 AM. This was 4 years ago. Post ID: 14427
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Another way to get information about your network interfaces on Linux.


There are many ways to get networking information on your Linux computer.

This is how to return the active network interface(s) on your Linux system.

4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'
enp0s25

Combining this command with another using backticks, it is possible to get the IP address of the active network interface easily.

4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ ip -f inet -o addr show `ip addr | awk '/state UP/ {print $2}'` | cut -d\  -f 7 | cut -d/ -f 1
192.168.1.2

This would, of course, be very useful in a script, but then you could use variables to hold the interface value and then use that in the second part of the script. Just like the example below. This will get the IP address and interface name on your Linux computer and print the result.

ipaddress.sh
1
2
3
4
5
6
7
8
9
#!/bin/sh
 
interface=$(ip addr | awk '/state UP/ {print $2}' | tr [:] ' ')
address=$(ip -f inet -o addr show $interface | cut -d\  -f 7 | cut -d/ -f 1)
if [ -z "$address" ]; then
	echo "No IP address assigned on your machine."
else
	echo "Your IP address is: $address. This is applied to the \"$interface\" networking interface."
fi

A very useful networking script.

Another very useful utility is iptraf-ng. This will print information about network connections on your network. This works in promiscuous mode, and as such cannot determine the socket statuses for other machines on the LAN. But this gives a good indication of what is going on with your network.

Using iptraf-ng on my network to see network connections.
Using iptraf-ng on my network to see network connections.

This could be a very good companion to Wireshark.

Run it like this.

4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ sudo iptraf-ng

It is menu-driven and very easy to use.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.