Automatic network start on USB-Netdevice insert
From Gentoo Linux Wiki
There are devices connecting the computer to ethernet via USB. It would be nice to raise the network, after the USB netdevice is plugged into the computer
Contents |
[edit] Getting the right kernel module
First have a look into the kernel modules, if there is the appropriate module servicing your device. The USB network device modules are located in:
| Linux Kernel Configuration: USB network devices |
Device Drivers --->
Network device support --->
USB Network Adapters --->
<select all modules>
|
There select all devices as modules drivers. Compile and install the modules
You may find further information in the Gentoo linux kernel guide.
[edit] First Network device start
If you successfully installed the device driver modules, have a look what udev thinks of your device. Today almost all Gentoo installations have udev activated. Have a look in the Gentoo udev guide, if you're not shure.
Now plug in your device. lsusb should list the device and its name and hardware. (This is an example with AX88187 hardware)
| Code: lsusb |
Bus 001 Device 016: ID 0b95:1780 ASIX Electronics Corp. AX88178 |
If you have udev activated and a device driver module, the system logs should list your device, too.
| Code: /var/log/messages |
kernel: usb 1-3: new high speed USB device using ehci_hcd and address 16 kernel: usb 1-3: configuration #1 chosen from 1 choice kernel: eth1: register 'asix' at usb-0000:00:12.2-3, ASIX AX88178 USB 2.0 Ethernet, 00:11:6b:f0:44:b0 |
| Code: dmesg |
usb 1-3: new high speed USB device using ehci_hcd and address 16 usb 1-3: configuration #1 chosen from 1 choice eth1: register 'asix' at usb-0000:00:12.2-3, ASIX AX88178 USB 2.0 Ethernet, 00:11:6b:f0:44:b0 |
[edit] Rename the network device
You may leave the network device name to "eth1" and skip this section. I like to rename the device. There are 2 ways to rename it, net config and udev.
[edit] Rename in /etc/conf.d/net
The Gentoo net config file allows to rename a network device. Simply add
| Code: /etc/conf.d/net |
rename_eth1="usb0" |
Be careful, always use the device eth1 for your USB device. Else you rename a different device, which you won't want to do.
[edit] Rename in /etc/udev/rules.d/70-persistent-net.rules
The other way renames every USB device with a certain hardware ID to "usb0". You have to change the entry in the persistent net rules from udev from "eth1" to "usb0".
Upon your first insert of the USB device, udev has made an entry in the persistent net list. Look for the entry with the same device ID of your USB device (e.g. "USB device 0x0b95:0x1780 (usb)") and change the entry 'NAME=' from "eth1" to "usb0".
If you don't have an entry for your device, check if your device is detected and known to the system. Have a look in the previous section. Also check, that persistent net rules are activated in your system config
| Code: /etc/conf.d/udev |
persistent_net_disable="no" |
Afterwards it may look like this:
| Code: /etc/udev/rules.d/70-persistent-net.rules |
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:6b:f0:44:b0", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="usb0"
|
This however only works for your actual USB device with a certain device ID. You have to redo this step for every USB net device.
[edit] Automatic network start
To have an automatic start of connectivity use sys-apps/ifplugd or sys-apps/netplug. The net example configuration (/etc/conf.d/net.example) lists both. Just
You may add a dhcp entry to the network config. Using dhcp should be default handling if no entry is listed in the config file.
| Code: /etc/conf.d/net |
config_usb0=( "dhcp" ) |
[edit] finish
Now your network connection should appear as net device "usb0" and instantly connect to your network if your net cable is plugged in. "ifconfig" lists your device.
| Code: ifconfig |
usb0 Protokoll:Ethernet Hardware Adresse 00:11:6b:f0:44:b0
inet Adresse:192.168.2.171 Bcast:192.168.2.255 Maske:255.255.255.0
inet6 Adresse: fe80::211:6bff:fef0:44b0/64 Gültigkeitsbereich:Verbindung
UP BROADCAST RUNNING MULTICAST MTU:7200 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
Kollisionen:0 Sendewarteschlangenlänge:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
|
You may change your MTU of your device, if you own a gigabit net adapter. Add in to the network config file
| Code: /etc/conf.d/net |
mtu_usb0="7200" |
