0

Every time I connect my Raspberry Pi in my computer's a USB port I need always to set the connection that is creates to my Linux Mint computer as shared. I do it via Network manager as screenshot shows (UI In Greek):

enter image description here

That's somewhat tedious and every time to spend 2-3 minutes to set the connection as shared in order to ssh in it. So I want once a device is plugged in a shared connection to be automatically created, therefore I won't need every time I plug the raspberry pi into a USB port to configure the network interface through network manager.

Is there a way to do this. So far once I type lsusb I get this result:

$ lsusb
Bus 002 Device 002: ID 05e3:0732 Genesys Logic, Inc. All-in-One Cardreader
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 4e53:5407  
Bus 001 Device 010: ID 0925:3881 Lakeview Research Saleae Logic
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The device that is created once I plugin the USB is the:

Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget

One.

Also dmesg shows the following:

[ 2015.792407] usb 1-3: new full-speed USB device number 8 using xhci_hcd
[ 2016.368398] usb 1-3: new high-speed USB device number 9 using xhci_hcd
[ 2016.517429] usb 1-3: New USB device found, idVendor=0525, idProduct=a4a2, bcdDevice= 5.10
[ 2016.517434] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2016.517437] usb 1-3: Product: RNDIS/Ethernet Gadget
[ 2016.517441] usb 1-3: Manufacturer: Linux 5.10.63+ with 20980000.usb
[ 2016.518553] cdc_subset: probe of 1-3:1.0 failed with error -22
[ 2016.520510] cdc_ether 1-3:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-3, CDC Ethernet Device, 12:e2:73:0a:fa:92
[ 2016.550226] cdc_ether 1-3:1.0 enp0s20f0u3: renamed from usb0
[ 2017.365925] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49 
[ 2017.532279] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49 
[ 2042.958713] IPv6: ADDRCONF(NETDEV_CHANGE): enp0s20f0u3: link becomes ready
[ 2216.944793] audit: type=1400 audit(1644678209.643:133): apparmor="DENIED" operation="capable" profile="/snap/snapd/14549/usr/lib/snapd/snap-confine" pid=10514 comm="snap-confine" capability=4  capname="fsetid"
[ 2220.764823] audit: type=1326 audit(1644678213.463:134): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=314 compat=0 ip=0x7f353fbdc89d code=0x50000
[ 2223.187662] audit: type=1400 audit(1644678215.883:135): apparmor="DENIED" operation="open" profile="snap.telegram-desktop.telegram-desktop" name="/etc/openal/alsoft.conf" pid=10514 comm="telegram-deskto" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[ 2224.579172] audit: type=1326 audit(1644678217.275:136): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579181] audit: type=1326 audit(1644678217.275:137): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579187] audit: type=1326 audit(1644678217.275:138): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579224] audit: type=1326 audit(1644678217.275:139): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579342] audit: type=1326 audit(1644678217.275:140): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579352] audit: type=1326 audit(1644678217.275:141): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=141 compat=0 ip=0x7f353fbd834b code=0x50000
[ 2224.579507] audit: type=1326 audit(1644678217.275:142): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579515] audit: type=1326 audit(1644678217.275:143): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 2224.579551] audit: type=1326 audit(1644678217.275:144): auid=4294967295 uid=1000 gid=1000 ses=4294967295 pid=10514 comm="telegram-deskto" exe="/snap/telegram-desktop/3544/usr/bin/telegram-desktop" sig=0 arch=c000003e syscall=203 compat=0 ip=0x7f3541bb26e1 code=0x50000
[ 3121.350145] usb 1-5: new high-speed USB device number 10 using xhci_hcd
[ 3121.498265] usb 1-5: New USB device found, idVendor=0925, idProduct=3881, bcdDevice= 0.01
[ 3121.498271] usb 1-5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 3122.347647] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49 
[ 3122.513998] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49 
[ 3122.680261] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=89 TC=0 HOPLIMIT=1 FLOWLBL=617835 PROTO=UDP SPT=22161 DPT=161 LEN=49 
[ 3122.880905] [UFW BLOCK] IN=enp3s0 OUT= MAC= SRC=fe80:0000:0000:0000:1be3:4633:095f:d015 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=663885 PROTO=UDP SPT=8612 DPT=8612 LEN=24 
[ 3122.880917] [UFW BLOCK] IN=enp3s0 OUT= MAC= SRC=fe80:0000:0000:0000:1be3:4633:095f:d015 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=837265 PROTO=UDP SPT=8612 DPT=8610 LEN=24 
[ 3122.880928] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=255464 PROTO=UDP SPT=8612 DPT=8612 LEN=24 
[ 3122.880938] [UFW BLOCK] IN=br-c2a79e951b81 OUT= MAC= SRC=fe80:0000:0000:0000:0042:f4ff:fe99:0011 DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=341915 PROTO=UDP SPT=8612 DPT=8610 LEN=24 
[ 3122.880946] [UFW BLOCK] IN=vethc930aa4 OUT= MAC= SRC=fe80:0000:0000:0000:0814:60ff:fee9:705f DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=674828 PROTO=UDP SPT=8612 DPT=8612 LEN=24 
[ 3122.880953] [UFW BLOCK] IN=vethc930aa4 OUT= MAC= SRC=fe80:0000:0000:0000:0814:60ff:fee9:705f DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=1048135 PROTO=UDP SPT=8612 DPT=8610 LEN=24 
[ 3122.880960] [UFW BLOCK] IN=enp0s20f0u3 OUT= MAC= SRC=fe80:0000:0000:0000:1eaf:0969:516b:39cb DST=ff02:0000:0000:0000:0000:0000:0000:0001 LEN=64 TC=0 HOPLIMIT=1 FLOWLBL=326809 PROTO=UDP SPT=8612 DPT=8612 LEN=24 

And the distribution that I run is Linux Mint 19. I suppose udev is the approach I must follow, but I do not know how.

But what I want is once I plugin my raspberry pi in Gadget mode to set the connection as

Edit 1

For now, I managed to set a udev rule in order to have a name to it:

SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0525", ATTRS{idProduct}=="a4a2", NAME="rpi0"

But what I did I managed to rename the interface from usb0 to rpi0. But I am stuck on how I can specify to the netowkr manager to have specific settings for the interface I plugin.

What I want it once I plugin the raspberry pi not to attempt to autoconnect by creating the file /etc/NetworkManager/conf.d/rpi0.conf

[main]
no-auto-default=rpi0

But still every time I try to connect a new network connection is created.

Is there a way to share my connection and bypass network manager as a whole?

1 Answer 1

0

You'll have to manage it via udev rules and disallow network nagagher to manage it at all.

Step1: Set static ip to rasbnerry pi

NOTE: this was tested in raspberry pi zero W in Gadget mode with ssh enabled.

Foremost, you should temporary set the network settings as shared for one last time and set a static ip to the raspberry pi by adding into the /etc/dhcpcd.conf the following settings:

interface usb0
static ip_address=10.42.0.62/24
static routers=10.42.0.1
static domain_name_servers=1.1.1.1

But first before you do that ensure that usb0 interface is the one used by raspberry pi for internet connection via usb by running ifconfig. It is recommended to set the settings seen in ifconfig because are relatively safe. In my case ifconfig for usb0 was:

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.42.0.62  netmask 255.255.255.0  broadcast 10.42.0.255
        inet6 fe80::2f8c:1871:13b2:dc30  prefixlen 64  scopeid 0x20<link>
        ether ce:bb:5c:2b:f2:46  txqueuelen 1000  (Ethernet)
        RX packets 230  bytes 19437 (18.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 891  bytes 56964 (55.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Step 2 set a specifig network interface name, and ip and to the pc thar raspberry pi is connected to.

You'll need to use the udev as a means of managing the interface. In my case I created a file named /etc/udev/rules.d/99_rpi_net_renamer.rules:

SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="0525", ATTRS{idProduct}=="a4a2", NAME="rpi0", RUN+="/sbin/ifconfig rpi0 down", RUN+="/sbin/ifconfig rpi0 10.42.0.61/24 broadcast 10.42.0.255",RUN+="/sbin/ifconfig rpi0 up"

What I did was based upon lsusb I listed all the devices:

lsusb
Bus 002 Device 002: ID 05e3:0732 Genesys Logic, Inc. All-in-One Cardreader
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 4e53:5407  
Bus 001 Device 010: ID 0925:3881 Lakeview Research Saleae Logic
Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In order to find the raspberry pi I was plugging it and unplugging it from the usb port and in the meantime I was comparing the various outputs of lsusb by running it again and again. In my case the device was:

Bus 001 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget

So in the udev rule I placed a record:

SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYY", NAME="rpi0", RUN+="/sbin/ifconfig rpi0 down", RUN+="/sbin/ifconfig rpi0 10.42.0.61/24 broadcast 10.42.0.255",RUN+="/sbin/ifconfig rpi0 up"

Where the XXXX was 0525 and YYYY was a4a2. As a rule of thumb in lsusb you should look for records in the following format:

Bus 001 Device 009: ID XXXX:YYYY Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget

The XXXX and YYYY is the ATTRS{idVendor} and ATTRS{idProduct} respectively.

Step 3: Disable management from network manager.

In my case, I placed the following rules in /etc/NetworkManager/conf.d/rpi0.conf:

[main]
no-auto-default=rpi0

[keyfile]
unmanaged-devices=rpi0

Step 4: finalizing and apply changes.

In order to apply the changes, run:

sudo udevadm control --reload-rules && sudo udevadm trigger
sudo service network manager restart

Afterwards, unplug and plug again the Raspberry Pi in order to see whether changes work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .