Skip to content

Instantly share code, notes, and snippets.

@Gadgetoid
Created December 26, 2015 11:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gadgetoid/319ecf8e3c5d3660e298 to your computer and use it in GitHub Desktop.
Save Gadgetoid/319ecf8e3c5d3660e298 to your computer and use it in GitHub Desktop.
Static IP raspbian jessie USB gadget
# In /etc/network/interfaces
iface usb0 inet static
dns-nameservers 8.8.8.8 8.8.4.4
address 10.0.16.16
netmask 255.255.0.0
gateway 10.0.16.32
# In /etc/dhcpcd.conf
denyinterfaces usb0
I'm not sure if the "dns-nameservers" line actually works, I've been having trouble with /etc/resolv.conf being trounced.
@Gadgetoid
Copy link
Author

You can also keep dhcp up and running and include a fallback IP address, like so:

#denyinterfaces usb0
profile static_usb0
static ip_address=10.0.16.16
static routers=10.0.16.1
static domain_name_servers=8.8.8.8 8.8.4.4

interface usb0
fallback static_usb0

This seems to work better for me than outright blocking the DHCP client. /etc/resolv.conf gets correctly populated and you can still hook up to something that has a DHCP server ( OSX running Internet Connection Sharing ) and have it play nice.

@Gadgetoid
Copy link
Author

To get a static Mac address, so that a host computer can assign a static IP, add:

g_ether.dev_addr=5a:77:1e:af:8e:9e g_ether.host_addr=72:8d:1f:c4:e8:ca

to the end of /boot/cmdline.txt

On Mac OS you can then edit /etc/bootptab and make it look like so:

%%

raspberrypi 1 5a:77:1e:af:8e:9e 192.168.2.16 boot

This will force the DHCP server on the Mac ( used for Internet Connection Sharing ) to assign the Pi the IP 192.168.2.16.

@Gadgetoid
Copy link
Author

  • sudo apt-get install rpi-update
  • sudo BRANCH=next rpi-update
  • add 'dtoverlay=dwc2’ to /boot/config.txt
  • add ‘dwc2’ and ‘g_ether’ to /etc/modules

Edit /etc/dhcpcd.conf and add:

profile static_usb0
static ip_address=10.0.16.16
static routers=10.0.16.1
static domain_name_servers=8.8.8.8 8.8.4.4

interface usb0
fallback static_usb0

Edit /boot/cmdline.txt and add to the end of the line:

g_ether.dev_addr=5a:77:1e:af:8e:9e g_ether.host_addr=72:8d:1f:c4:e8:ca

@scruss
Copy link

scruss commented Feb 19, 2017

Any particular reason for the sudo BRANCH=next rpi-update? rpi-update is pretty much sidelined except for some extreme hardware voodoo.

@Gadgetoid
Copy link
Author

It was necessary at the time, but now definitely not! I use this gist mostly for my own reference, but it's definitely worth noting that I think rpi-update should burn in the fire of a billion suns. It's a great convenience tool if you understand what it does, but otherwise it's a bit of a support nightmare :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment