Welcome! Log In Create A New Profile

Advanced

Use front USB connector as Ethernet service port with DHCP

Posted by tme 
tme
Use front USB connector as Ethernet service port with DHCP
February 20, 2023 12:33PM
With multiple boxes around, it may be hard to remember the hostname or IP address of each box, and be certain which box one is connected to. One solution is to connect directly with a cable to the box's front USB connector.

This post describes how to set up the box such that plugging a USB-to-Ethernet adapter into the front USB port and connecting it to a PC with an Ethernet cable gives access to the box through ssh, https, etc at a fixed address, say 192.168.100.100. The only things needed are a USB-to-Ethernet adapter (see attached picture) and an Ethernet cable.


1. Make the USB network interface start automatically

Plug the USB-to-Ethernet adapter into the front USB connector and use 'dmesg' to get its name as a network interface:
$ dmesg | tail -4 
[498079.883797] asix 1-1:1.0 (unnamed net_device) (uninitialized): PHY [usb-001:005:10] driver [Asix Electronics AX88772A] (irq=POLL)
[498079.898637] Asix Electronics AX88772A usb-001:005:10: attached PHY driver (mii_bus:phy_addr=usb-001:005:10, irq=POLL)
[498079.911504] asix 1-1:1.0 eth2: register 'asix' at usb-d0050000.usb-1, ASIX AX88772 USB 2.0 Ethernet, 01:23:45:67:89:ab
[498079.955400] asix 1-1:1.0 enx0123456789ab: renamed from eth2

Unplug the sdspter, make a copy of '/etc/network/interfaces' and add some lines to it:
$ sudo cp -a /etc/network/interfaces /etc/network/interfaces.orig

$ sudo nano /etc/network/interfaces

$ tail -5 /etc/network/interfaces 
rename /enx*=usb0
allow-hotplug usb0
iface usb0 inet static
    address 192.168.100.100/24
    gateway 192.168.1.1
The kernel's proposed name for the interface ('enx0123456789ab') must match the pattern ('enx*') for renaming it to 'usb0' to work. The slash ('/') just before 'enx*' is not part of the pattern.

Plug in the USB-to-Ethernet adapter and verify that it becomes network interface 'usb0' with address 192.168.100.100:
$ sudo ifconfig
[...]
usb0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.100.100  netmask 255.255.255.0  broadcast 192.168.100.255
        ether 01:23:45:67:89:ab  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Unplug the adapter.


2. Install and configure the DHCP server

DHCP is the service that provide a connected PC with a suitable IP address. Install the server:
$ sudo apt install -y isc-dhcp-server
[...]
Generating /etc/default/isc-dhcp-server...
Launching both IPv4 and IPv6 servers (please configure INTERFACES in /etc/default/isc-dhcp-server if you only want one or the other).
Starting ISC DHCPv4 server: dhcpdcheck syslog for diagnostics. ... failed!
 failed!
invoke-rc.d: initscript isc-dhcp-server, action "start" failed.
[...]

The reported error may be ignored. Make a copy of '/etc/dhcp/dhcpd.conf' and modify it:
$ sudo cp -a /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.orig

$ sudo nano /etc/dhcp/dhcpd.conf

$ diff /etc/dhcp/dhcpd.conf.orig /etc/dhcp/dhcpd.conf
7,8c7,8
< option domain-name "example.org";
< option domain-name-servers ns1.example.org, ns2.example.org;
---
> option domain-name "local";
> option domain-name-servers 192.168.1.1;
107a108,112
> 
> subnet 192.168.100.0 netmask 255.255.255.0 {
>   range 192.168.100.10 192.168.100.99;
>   option routers 198.192.1.1;
> }


3. Make the DHCP service start automatically on 'usb0'

Make a copy of '/etc/default/isc-dhcp-server' and modify it:
$ sudo cp -a /etc/default/isc-dhcp-server /etc/default/isc-dhcp-server.orig

$ sudo nano /etc/default/isc-dhcp-server

$ tail -4 /etc/default/isc-dhcp-server
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#	Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="usb0"
INTERFACESv6=""

Make 'udev' restart the DHCP server when the USB-to-Ethernet adapter is plugged in:
$ sudo nano /etc/udev/rules.d/85-ifupdown.rules

$ cat /etc/udev/rules.d/85-ifupdown.rules
# Handle allow-hotplug interfaces
SUBSYSTEM=="net", ACTION=="add", RUN+="/etc/init.d/isc-dhcp-server restart"

$ sudo udevadm control --reload-rules && sudo udevadm trigger


4. Verification

On the PC, to avoid routing issues, disable any wireless network interface and unplug any Ethernet cables. Plug the USB-to-Ethernet adapter into the box and connect an Ethernet cable between it and the PC.

Open a new local terminal/command window on the PC and check that the PC's IP address is '192.168.100.xx':
$ ifconfig | grep 'inet ' | grep 100
        inet 192.168.100.10  netmask 255.255.255.0  broadcast 192.168.100.255

Check that 'ping' works:
$ ping -c 1 192.168.100.100
PING 192.168.100.100 (192.168.100.100) 56(84) bytes of data.
64 bytes from 192.168.100.100: icmp_seq=1 ttl=64 time=0.735 ms

--- 192.168.100.100 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.735/0.735/0.735/0.000 ms

Check that 'ssh' works:
$ ssh root@192.168.100.100
The authenticity of host '192.168.100.100 (192.168.100.100)' can't be established.
ED25519 key fingerprint is SHA256:fQNAwY0Yy9NsXLyIUMQKByMp7oNOYF1C4O5kPE0iNrM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.100.100' (ED25519) to the list of known hosts.
root@192.168.100.100's password:
Reestablish the PC's wireless and/or cabled network again and repeat the verification.


5. Trouble shooting

The service port has been tested and verified on Netgear Stora, RN102 and RN104. If the verification failed, read through the above steps carefully, and verify that each step was followed exactly. If still confused:
  • Check the green and orange LEDs on the Ethernet connectors for line contact and communication.
  • On the PC, check that Ethernet is configured to obtain its address automatically through DHCP.
  • On the box, messages from the DHCP server may give a hint. They are written to '/var/log/syslog' or Busybox' 'syslogd' in RAM:
      $ logread | tail  
  • On the box, 'dmesg' may give a hint:
      $ sudo dmesg | tail  

Above, it's assumed that the box is connected to a router with LAN-address 192.168.1.1, and that the router runs a DNS server translating human readable addresses like 'google.com' into IP addresses like '8.8.8.8'. If this is not the case, minor adjustments might be needed.

Note to Windows users:
'putty' may be used in stead of 'ssh' to access the box, both when configuring it and when accessing it through the service port. And, on the PC, use 'ipconfig' in stead of 'ifconfig'.

Good luck!

Regards,
Trond Melen
Attachments:
open | download - signal-2023-02-20-193213.jpeg (472.7 KB)
Re: Use front USB connector as Ethernet service port with DHCP
February 20, 2023 03:46PM
Hi Trond,

Very nice! it will come handly for some circumtances that a USB-Ethernet adapter is desired.

One thing I'd question is: the name enx* always the pattern, or a different adapter will give you a different name pattern? I have one lying around somewhere, might try to see what it will look like.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
tme
Re: Use front USB connector as Ethernet service port with DHCP
February 20, 2023 07:30PM
Hi bodhi,

The two adapters in the picture are fairly different, but they are both named 'enx0123456789ab' by the kernel where '01:23:45:67:89:ab' is their MAC addresses. I assume it's universal until someone reports something else. I have a third one in order (about $8 from China) so I can report about one more in, say, 3 weeks.

Regards,
Trond Melen
Re: Use front USB connector as Ethernet service port with DHCP
February 21, 2023 03:11PM
Added to Wiki thread.

Quote

Wifi - Access Point - USB Ethernet

Create an 802.11n AP (Access Point) with create_ap
Create an 802.11n AP (Access Point) (old style with manual steps)
Basic Wifi setup for Pogo V3 OXNAS and another example
Use front USB connector as Ethernet service port with DHCP

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
tme
Re: Use front USB connector as Ethernet service port with DHCP
March 18, 2023 02:23PM
Hi bodhi,

Quote

One thing I'd question: is the name enx* always the pattern, or a different adapter will give you a different name pattern?

As stated above, USB-to-Ethernet adapters seems to always be named 'enx0123456789ab' by the Linux kernel where '01:23:45:67:89:ab' is their MAC addresses. This is also the case for the USB 3.0 gigabit adapter (picture attached) I recently received from China.

Regards,
Trond Melen
Attachments:
open | download - signal-2023-03-18-201739.jpeg (249.6 KB)
Re: Use front USB connector as Ethernet service port with DHCP
March 18, 2023 02:44PM
Thanks Trond!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Use front USB connector as Ethernet service port with DHCP
March 20, 2023 08:49AM
This is an awesome tip!!! @OP would the same approach work for a usb ttl adaptor??

im looking to create a portable wireless one with two usb-ttl adaptors in it for connecting to network kit so i can debug away from the noise of the comms room
tme
Re: Use front USB connector as Ethernet service port with DHCP
March 25, 2023 09:51AM
Hi Gravelrash,

Quote

This is an awesome tip!!!

Thanks!

I'm not sure exactly what kind of debugging you want. If the box you want to debug is on a network you cannot access outside the machine room, I suggest you connect the Ethernet cable to a wireless router. As long as you're within the reach of the wireless router, you may access it through the WiFi interface on your PC. If you connect the box to the WAN port of the router (i.e. the port normally connected to an Internet Service Provider), the router will get its IP address from the box' DHCP server.

Are you mentioning a TTL adapter because you want access to the serial console? If so, I suppose you should convert the TTL signals to RS232 or RS485 and, if the distance requires it, use a serial extender. If, as part of the debugging, you need to interrupt U-Boot or hit the reset button, I guess ear muffs is the simplest solution... :-)

Regards,
Trond Melen
Re: Use front USB connector as Ethernet service port with DHCP
March 25, 2023 12:39PM
You'd only need to SSH in the board has serial module converter which connects to serial port of other board (that you want to debug).

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Use front USB connector as Ethernet service port with DHCP
March 25, 2023 10:34PM
For remote serial access I have heard that one of these makes a great solution. I've ordered a few to try and will post results when I've been able to test.
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: