You are not logged in.
Hello everybody,
I have a small gadget that, when connected to my desktop PC, presents itself as a network interface.
In order to ssh into it I need to run dhcpcd each time, because the gadget includes a DHCP. I am always given the same IP, 10.11.99.2, and the gadget also has a fixed IP, 10.11.99.1
I would like to have dhcpcd run automatically when the network interface is plugged in my machine. I use netctl for my wireless adapter, and I am aware of ifplugd, but this is for when the cable is connected, which is not the same thing.
Output from dmesg when I plug:
[ 2519.935716] usb 1-6: new high-speed USB device number 7 using xhci_hcd
[ 2520.085410] cdc_ether 1-6:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-6, CDC Ethernet Device, 36:bb:dc:12:dd:21
[ 2520.099509] cdc_ether 1-6:1.0 enp0s20f0u6: renamed from usb0
Is there any way to automate this? I am sure there is, but I am not sufficiently skilled with arch to come up with a solution on myself.
Thanks in advance for the help and the patience!
Ciao,
V
Last edited by wilcomir (2018-01-06 12:15:39)
Offline
Offline
Welcome to the forums wilcomir
One option is to write a udev rule that detects the device and runs dhcpcd.
Last edited by Slithery (2018-01-03 22:24:01)
Offline
Hi guys,
thanks for the quick answer.
I wrote a rule, but apparently I am still missing something:
$ cat /etc/udev/rules.d/myrule.rules
KERNEL=="enp*", ATTR{address}=="36:bb:dc:12:dd:21", ACTION="add", RUN+="/usr/bin/dhcpcd enp0s20f0u6"
On plug, I get this:
$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[296.515621] add /devices/pci0000:00/0000:00:14.0/usb1/1-6 (usb)
KERNEL[296.522451] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0 (usb)
KERNEL[296.523340] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/usb0 (net)
KERNEL[296.523389] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/usb0/queues/rx-0 (queues)
KERNEL[296.523415] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/usb0/queues/tx-0 (queues)
KERNEL[296.523643] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0 (usb)
KERNEL[296.523942] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.1 (usb)
KERNEL[296.524022] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.1 (usb)
KERNEL[296.524109] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6 (usb)
UDEV [296.531964] add /devices/pci0000:00/0000:00:14.0/usb1/1-6 (usb)
UDEV [296.534099] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0 (usb)
UDEV [296.535366] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.1 (usb)
UDEV [296.536454] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.1 (usb)
KERNEL[296.536559] move /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/enp0s20f0u6 (net)
UDEV [296.573200] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/enp0s20f0u6 (net)
UDEV [296.573653] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/usb0/queues/rx-0 (queues)
UDEV [296.573673] add /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/usb0/queues/tx-0 (queues)
UDEV [296.574075] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0 (usb)
UDEV [296.574870] bind /devices/pci0000:00/0000:00:14.0/usb1/1-6 (usb)
UDEV [296.575818] move /devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/enp0s20f0u6 (net)
And also:
$ udevadm info -a -p /sys/class/net/enp0s20f0u6
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-6/1-6:1.0/net/enp0s20f0u6':
KERNEL=="enp0s20f0u6"
SUBSYSTEM=="net"
DRIVER==""
ATTR{addr_assign_type}=="0"
ATTR{addr_len}=="6"
ATTR{address}=="36:bb:dc:12:dd:21"
ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"
ATTR{carrier_changes}=="0"
ATTR{dev_id}=="0x0"
ATTR{dev_port}=="0"
ATTR{flags}=="0x1002"
ATTR{gro_flush_timeout}=="0"
ATTR{ifalias}==""
ATTR{ifindex}=="6"
ATTR{iflink}=="6"
ATTR{link_mode}=="0"
ATTR{mtu}=="1500"
ATTR{name_assign_type}=="4"
ATTR{netdev_group}=="0"
ATTR{operstate}=="down"
ATTR{proto_down}=="0"
ATTR{tx_queue_len}=="1000"
ATTR{type}=="1"
When I plug my device, I wait some time and check ip addr but apparently dhcpcd is not run... Any clues? Also, can you confirm I can use RUN+="/usr/bin/dhcpcd %k" in case the name changes because I use another USB port?
Thanks.
Ciao,
V
Offline
Did you test, reload and try a trigger?
Offline
Don't go through the bother of udev or ifplugd.
dhcpcd can handle arrival and departure of interfaces just fine - ie hotplugging.
You just have to run dhcpcd using the init system (I believe arch uses systemd) and not tie it to a specific interface.
Offline
or just use networkd
Offline
Hi everybody,
as suggested by rsmarples, I just run
$ sudo systemctl enable dhcpcd.service
and it was enough for me.
I am sorry, I am sure that my requirements were not very clear in the beginning, thus leading to unnecessary complications for my easy case.
Offline