udev hotplug ethernet , show ifdown (4G Dongle)

Issues related to configuring your network
Post Reply
haris2887
Posts: 2
Joined: 2020/10/22 05:38:33

udev hotplug ethernet , show ifdown (4G Dongle)

Post by haris2887 » 2020/10/22 05:54:01

hi all.
was looking for some help regarding an issue I am having with my USB 4G ethernet dongle.
I have managed to get usb_modeswitch working correctly. All drivers etc are working correctly.

Problem description:
When I plug the USB into my VM, i must manually do an

Code: Select all

ifup eth0
in-order to bring the interface online.
I must do this every time I plug and unplug.

currently my udev rule reads (/etc/udev/rules.d/52-e8372.rules):

Code: Select all

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="/usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -J ; sleep 5s ; /usr/sbin/ifup eth0
Notice I have tried to add the

Code: Select all

ifup 
command, this does not work.

my network Scripts look like :
Image

as I suggested everything works perfectly when I issue the ifup eth0 command.
anyone have any ideas what it could be ?

aks
Posts: 3045
Joined: 2014/09/20 11:22:14

Re: udev hotplug ethernet , show ifdown (4G Dongle)

Post by aks » 2020/10/25 18:34:05

Timing (and stuff).
It's been a long time since I've had to deal with hardware.
I'm not familiar with usb_modeswitch (or whatever), but does it behave as expected (in terms of stderr, stdout & stdin)?
Some don't.
On the surface, your udev looks good - match these (hardware) attributes and do this thing.... Well in your case, do these things.
Turns out it does part of the things.
I seem to recall that only 1 thing is done - it's a"shell" thing (so only the first part up to the ;)
Which fits.
Perhaps a systemd service when the hardware becomes active?
Just a suggestion, not an answer!

Also, from notes (years ago), I had:
'SUBSYSTEM=="block",ATTRS{removable}=="1",RUN{program}="/sbin/blockdev --setro %N"' > /etc/udev/rules.d/80-readonly-removables.rules
(that's about some "solder" as a block device ... well, apparently).
I just wonder about those {} - why did I do that, no idea!)

chemal
Posts: 696
Joined: 2013/12/08 19:44:49

Re: udev hotplug ethernet , show ifdown (4G Dongle)

Post by chemal » 2020/10/26 03:10:43

You are not supposed to write a udev rule for usb_modeswitch. You just install the usb_modeswitch package and that's it.

What also doesn't work is ONBOOT=yes and usb network devices. It takes too long until they become visible.

You can use a udev rule like

Code: Select all

ACTION=="add", KERNEL=="eth0", SUBSYSTEM=="net", RUN+="/usr/sbin/ifup eth0"
to automatically bring up the interface once it has been switched and the kernel driver is attached.

Also be aware that the command you add to RUN is called directly, there is no shell involved. Something like RUN+="cmd1; cmd2" will not work. You have to say RUN+="/bin/sh -c 'cmd1; cmd2'".

haris2887
Posts: 2
Joined: 2020/10/22 05:38:33

Re: udev hotplug ethernet , show ifdown (4G Dongle)

Post by haris2887 » 2020/11/01 02:35:52

Thans Guys, That's exactly what was needed.
now works perfectly :)

Post Reply

Return to “CentOS 7 - Networking Support”