-1

I have a Raspberry Pi 4 and a Raspberry Pi 0. The RPi0 is connected via the data USB port to the RPi4 (and otherwise doesn't have any connections), and the RPi4 has an Internet connection so is remotely accessible. I am trying to set up the RPi0 as a USB ethernet gadget: on the RPi4, I have Nginx set up as a reverse proxy, and the goal is so I can use the connection to the RPi4 to access a web panel hosted on the RPi0. This requires a specific IP address, 10.0.0.1, to be assigned to the usb0 interface on the RPi4, so that the panel on the RPi0 will be accessible to Nginx at http://10.0.0.2. When I do this by running the command ip addr add 10.0.0.1/255.255.255.0 dev usb0 on the RPi4, it works great, but this does not persist across restarts. By default, it seems like the address 192.168.7.2 is assigned to usb0 until I add 10.0.0.1 with that command.

I'm on Raspbian GNU/Linux 10 (buster), and I want to make this configuration persist across restarts.

So far, I've tried these (all attempted on the RPi4):

  • Adding to /etc/network/interfaces -- seemed to do absolutely nothing. I also tried creating a file in interfaces.d folder which also didn't work.

This is what I added:

allow-hotplug usb0
iface usb0 inet static
        address 10.0.0.1
        netmask 255.255.255.0
        gateway 10.0.0.1
        dns-nameservers 8.8.8.8
  • Adding to /etc/dhcpcd.conf -- also did nothing. Then I tried some guide that told me to set dhcpcd to start on startup, which broke networking altogether until I disabled it again.

I added this to the very end of that file:

interface usb0
static ip_address=10.0.0.1/24
static routers=10.0.0.1
static domain_name_servers=1.1.1.1 1.0.0.1
  • Adding to /etc/dnsmasq.d the following:

Added in a new file,

dhcp-range=usb0,10.0.0.2,10.0.0.2,2m
listen-address=10.0.0.1
  • Various guides to add a script containing the ip addr add 10.0.0.1/255.255.255.0 dev usb0 command to be run at startup -- also doesn't seem to work. I also would prefer to do it the "correct" way anyways.

Most other guides I've seen suggest using NetworkManager but I am using the lite distro without a desktop so I don't think this is an option.

How do you do this? Is there a trick to this that is specific to Raspbian?

ieatpizza
  • 151
  • 1
  • 9
  • I don't know "the answer" to your question, but until you get one, you could add your `ip addr add ...` to root's `crontab` under an `@reboot` specification. – Seamus Aug 08 '21 at 06:24
  • @Seamus that didn't work either: `@reboot ip addr add 10.0.0.1/255.255.255.0 dev usb0 ` – ieatpizza Aug 08 '21 at 06:32
  • Oh - you probably didn't spec the full file path. Do this: `sudo crontab -e` ; in the editor, add the line `@reboot sleep 10; /sbin/ip addr add 10.0.0.1/255.255.255.0 dev usb0 >> /home/pi/netchange.txt 2>&1`. This should cover all contingencies & log any errors to the named file in pi's home directory – Seamus Aug 08 '21 at 07:39
  • Based on comments you entered under my Answer, it appears you are using 2 Pi. It is unclear what you are entering and where. It appears what you asked bears little relation to your Question. NOTE all additional information belongs in your Question. – Milliways Aug 08 '21 at 09:31
  • If you've added stuff to `/etc/dhcpcd.conf` take all of your changes out of `/etc/network/interfaces`. One or the other, not both. If you want to do it in `/etc/network/interfaces` you have to add `denyinterfaces usb0` to `/etc/dhcpcd.conf`. – Dougie Aug 08 '21 at 17:37
  • @Milliways I added additional information to the question. – ieatpizza Aug 08 '21 at 19:45

1 Answers1

0

I doubt that "I need to configure a static IP address" and what you have tried in /etc/network/interfaces is 5 years out of date. Indeed /etc/network/interfaces includes a WARNING not to do this.

I doubt you have an interface usb0 but even if you did

static ip_address=10.0.0.1/24
static routers=10.0.0.1

is nonsense.

ls /sys/class/net/ will show supported interfaces.

I strongly recommend you avoid Static IP Address (at least until you determine why you want one) but if you insist then How to set up Static IP Address shows how to do it properly.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • root@pi:/home/pi# ls /sys/class/net/ bnep0 lo mon0 usb0 wlan0 – ieatpizza Aug 08 '21 at 06:49
  • I'm trying to access my RPi0 that is attached as a USB Ethernet gadget on an RPi4. As far as I know, to do that, I need to configure a static IP for the RPi0 on the RPi4. – ieatpizza Aug 08 '21 at 06:50
  • The link you posted suggests to add it to `/etc/dhcpcd.conf` which I have also tried and it did nothing. – ieatpizza Aug 08 '21 at 06:52
  • @ieatpizza You would not need to configure an address (depending on what you mean by access) but AFAIK USB Ethernet gadget is not supported. If realy wanted one you should set nogateway and choose a non conflicting IP – Milliways Aug 08 '21 at 06:56
  • I have a Nginx reverse proxy on the Pi4 to access a web service on the Pi0. The Pi 0 does support USB Ethernet gadget and the whole thing works fine when I manually run `ip addr add 10.0.0.1/255.255.255.0 dev usb0` on startup, I just don't want to keep having to do that as it restarts pretty often. – ieatpizza Aug 08 '21 at 07:34