Check if the LAN cable is disconnected on Linux

How to determine if the Ethernet cable is unplugged in Linux.

If the network interface name is eth0

cat /sys/class/net/eth0/carrier

It can be judged by the value displayed in. 0 is the disconnection state. 1 is live. Therefore, if you monitor this, you can easily determine whether to connect or disconnect the cable.

However, inotify cannot be used with sysfs or procfs. So if you decide by yourself https://stackoverflow.com/questions/26672414/inotify-add-watch-fails-on-sys-class-net-eth0-operstate You need to get the event using netlink, as in.

However, if there are multiple network interfaces, I do not know which interface the LAN cable was disconnected from. In this case, it is necessary to determine by combining with the value of / sys / class / net / eth0 / carrier mentioned above.

I thought there might be a better way, but I couldn't find a way to say this.

For the time being, I decided to make the tea muddy by this method.

Recommended Posts

Check if the LAN cable is disconnected on Linux
What to do if the inode is exhausted on EC2 Linux
[2020July] Check the UDID of the iPad on Linux
Wake on lan on Linux
Check capacity on Linux
Check if the string is a number in python
Check if it is Unix in the scripting language
Check if it is Unix in the scripting language
What is the Linux kernel?
Install the JDK on Linux
Check TTL on Linux router
Paste the link on linux
[Blender] Script to check if the selected one is a mesh
On Linux, the time stamp of a file is a little past.
Determine if the library is installed.
[Linux] Who is the background job! ??
[Golang] Check if a specific character string is included in the character string
The NVM Checksum Is Not Valid, a solution to the problem that Intel's wired LAN is not recognized on Linux
[Java] [Linux] Investigating how the implementation of Java child processes on Linux is realized
Find out where the java entity is on Linux (CentOS this time)
Status check command used (sometimes) on linux
Check if the URL exists in Python
The one who is not on DVD
Notes on using OpenCL on Linux on the RX6800
Compiling the Linux kernel (Linux 5.x on Ubuntu 20.04)
If branch depending on whether there is a specific element in the list
Check when the HTML obtained by Requests on Google App Engine is garbled
I want to be notified when the command operation is completed on linux!
Check if the characters are similar in Python
The origin of Manjaro Linux is "Mount Kilimanjaro"
Python> Run-time argument> Check if -d is attached
It's a Mac. What is the Linux command Linux?
The .pyd file is the DLL itself on Windows
(For myself) Flask_AWS_3 (Check if SQL is working)
(Linux beginner) What is the magic word aux?
Until the Sphinx documentation is published on GitHub
Set the startup script on Linux (RasPi, Edison)
What is the difference between Unix and Linux?
Create a python script to check if the link at the specified URL is valid 2
Create a python script to check if the link at the specified URL is valid
How to check in Python if one of the elements of a list is in another list
The Linux emulator "iSH" that runs on the iPad is a hot topic in me
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux