How to set a static IP address in the B2

322 views
Skip to first unread message

Mark Fishman

unread,
Jun 18, 2021, 9:44:03 AM6/18/21
to Brennan Forum
DISCLAIMER:
A static IP address is different from a reserved/fixed DHCP address. The former is configured statically WITHIN THE DEVICE, the latter is a reservation within the DHCP server (usually inside your home router) so that the same address is always assigned to the same device. A reserved DHCP address is easier, and especially easier to undo, and causes less confusion if you relocate your B2 to a different network, or change your router. These instructions are for cases where a reserved address doesn't work.

In other words, this is not a recommendation, it's an explanation.

(NOTE: I have done this on my own B2, for testing purposes only. It worked for me. I don't know if a Brennan software update would overwrite it, although the files edited should NOT be changed by the Brennan software. If you can't get your B2 on the network after making the edits, have a plan for undoing them. See comment about "The Sorcerer's Apprentice".)

If you're a technical person, this is a (mildly) funny story:
Vinton Cerf gave a talk about the early days of the Internet at my workplace. He told us that the fundamental service model of the Internet, known as the internet protocol, is "some of the packets, some of the time, in some order." Usually that's not good enough, so they invented the transmission control protocol, which has the service model of "all of the packets, all of the time, in the correct order." (This of course is why you will almost always see references to "TCP/IP".)


I have appended a glossary of some of the terms used in these instructions. Unless you are already aware of the meaning of an abbreviation or word, please consult that first. If I put it at the top of the instructions, I'm sure someone would complain that the instructions are too long, and wouldn't read them anyway. Yes, I'm that cynical (a word which, by the way, is properly pronounced "realistic"). If you aren't comfortable using vi in a shell window, STOP NOW.

These instructions generally follow the "Sorcerer's Apprentice" principle that you should know how to reverse any changes you make BEFORE you actually make them. I learned how important that can be from Mickey when I was very young.


How to give your Brennan a STATIC (not dynamically assigned AT ALL) IP address:

That has to be configured INSIDE the B2, in the operating system networking configuration. The only piece of information you need from the router is what range ("pool") of IP addresses it uses for DHCP addresses, because we need to tell the B2 to use an address OUTSIDE that range. My router currently uses the whole available address range, but I can change the DHCP range so there are addresses outside the pool. If yours does, too, but won't allow you to change it, just pick an address to use from the higher part of the range to reduce the likelihood that there'll be an assignment collision. (Home networks usually have fewer devices than there are possible addresses.)

Maybe a Brennan employee will jump in to tell you what you have to do to set a static IP address in the B2, and if (s)he does, try it that way. Otherwise, the safest way to try this is to make a duplicate of your B2's existing SD card so you can get back in if this mucks things up.

There are two files that have to be edited: /etc/network/interfaces and /etc/resolv.conf.

Using the duplicate card, then, SSH into your B2 at whatever IP address it has for the moment. cd to /etc/network. Edit the interfaces file -- my B2 appears to have only vi for a text editor, but all the important commands fit on a coffee cup, so finding a short cheatsheet shouldn't be hard.

As delivered from Brennan, my copy of /etc/network/interfaces has THIS SECTION for wireless connections:
# Configure wireless lan
iface wlan0 inet dhcp
        udhcpc_opts -t 5 -T 5 >/dev/null 2>&1
        post-up /etc/init.d/S49ntp restart >/dev/null 2>&1

You probably want to change it to
# Configure wireless lan
iface wlan0 inet static
        address [the address you have selected to use goes here, no brackets]
        netmask 255.255.255.0 [NB this is probably correct -- do not include this stuff in brackets]
        gateway [probably the LAN address of your router, seen from inside your network, again no brackets]
        dns-nameserver [put at least one nameserver IP address here, again no brackets -- you can get it from your existing config or the router]
        post-up /etc/init.d/S49ntp restart >/dev/null 2>&1


EXAMPLE:
Here's my "new" /etc/network/interfaces file (with the original lines for the wireless dhcp cnfiguration commented out by inserting # and a space at the beginning of the lines, instead of just deleting them). OBVIOUSLY you should use addresses that work on YOUR Network with YOUR router, not necessarily the same numbers that I am using in this EXAMPLE:

# Configure Loopback
auto lo
iface lo inet loopback
# Configure ethernet
iface eth0 inet dhcp
        post-up /etc/init.d/S49ntp restart >/dev/null 2>&1
# Configure wireless lan
# iface wlan0 inet dhcp
#       udhcpc_opts -t 5 -T 5 >/dev/null 2>&1
iface wlan0 inet static
        address 192.168.0.105
        netmask 255.255.255.0
        gateway 192.168.0.1
        dns-nameserver 208.59.247.45
        post-up /etc/init.d/S49ntp restart >/dev/null 2>&1




Save the file and reboot. If your B2 doesn't get the address you have chosen, or can't be reached on the network, shut it down and swap the original card back in. Which is why it's always best to work with a copy. *(see note at end if you're in real trouble.)

For the example that I have shown, I left everything in the file that was there before, commenting out only the two lines referring to dhcp for wlan0. I put in the lines I described to you earlier (USING MY NETWORK'S INFO!), saved the file, and rebooted. Hey! I now have a new IP address, and it's the one I specified! and my router shows it in the client list.

At this point, though, my B2's internet radio function could not look up the URLs of radio stations, because those are outside my LAN. The /etc/resolv.conf file (which contains the nameserver information also) is needed AFTER boot for the B2 to resolv(e) hostnames outside the LAN. When you're using DHCP, a temporary file is created using the info supplied duringthe DHCP negotiation, /tmp/resolv.conf, and there's a symbolic link in /etc that points to it. The link uses the name /etc/resolv.conf.

So here's the fix (also tested): 
 cd /etc
 mv resolv.conf resolv.conf.dhcp

The mv (move) command renames (moves) the existing symbolic link to have a diffrent name so the name we want is free for us to use on a new file. If you're comfortable with creating symbolic links on Linux, you could have simply removed it instead of renaming it, but if you ever want to go back again you'd have to re-create the link.

Now you have to create a new file named resolv.conf, and put the following two lines in it:
nameserver [IP address of the primary DNS from your router's info]
nameserver [IP address of the secondary DNS from your router's info]

Save the file. No need to reboot if you already did that but it won't hurt. And yay! Internet Radio works again.

Note: presumably if you really want more than one nameserver entry in your /etc/network/interfaces file, you could have more than one line that starts dns-nameserver. It doesn't seem to be used after boot, though, unless it's during a web-upgrade of the B2 software, but as the first one specified is your ISP's primary DNS server the odds of it being down for any significant length of time are very small without bigger problems than not being able to upgrade your B2.


DEFINITIONS (of some terms and abbreviations used):

 - MAC [Media Access Control] address: the hardware identification of the network adapter, whether wired or wireless, in a device. A MAC address is six pairs of hexadecimal digits, of which the first three pairs identify the hardware manufacturer and the last three identify the specific piece of hardware from that manufacturer.
 - IP [Internet Protocol] address: the software address used on the network and assigned to the MAC address, either statically by configuration within the device's operating software or dynamically by a DHCP server (e.g., in a router). Version 4 of IP specifies four fields of three decimal digits each, separated by periods (full stops), xxx.yyy.zzz.nnn, for a corresponding MAC address.
 - DHCP [Dynamic Host Configuration Protocol]: a negotiation process by which a device acquires temporary use ("lease") of a unique IP address, as well as being informed of the appropriate DNS server and gateway addresses that it should use when sending packets.
 - DHCP pool or DHCP range: the set of adresses from which a DHCP server will assign IP addresses to devices. It doesn't have to be the entire set of possible addresses on your network segment, it can be a subset.
 - netmask: a method of segmenting the IP address space so that only a portion of the address (usually but not necessarily the last of the four numerical fields) is allowed to vary within a particular set of devices that share an electrically common wire (using only crossover cables or hubs, not switches or routers). The most common netmask for home networks using IP version 4 is 255.255.255.0, which allows up to 255 unique addresses within the segment.
 - LAN [Local Area Network]: a network segment on which all devices have IP addresses that share the "masked" portion of their address and could communicate without the need for a router.
 - WAN [Wide Area Network]: any network segment not part of the LAN to which your device is connected.
 - router: software (often in standalone hardware) that directs packets between network segments according to the IP addresses in the packet headers, so that packets intended for devices on one LAN stay there and packets intended for devices outside that LAN become visible on an appropriate other network segment, e.g., the public Internet.
 - Gateway: the IP address to which packets should be sent, if it isn't intended for other devices on the local network segment. Your B2 is on the LAN side of your router. The B2 sends network traffic to the router, which also knows about the other devices on your LAN, your home network. So the gateway address that the B2 and other computers inside your home network use is the inside-your-home address of the router. The router itself also sits on a WAN, i.e., your ISP's network. It has an IP address on that network, and it sends its traffic to a router somewhere outside your home. So the router itself has a default gateway on the WAN. That is probably what your router is telling you. For example, the router I have says its Gateway is 216.15.114.1, which is reported on the WAN tab of the router web pages, but my Windows computer tells me (ipconfig /all) that its Default Gateway is 192.168.0.1, which is the LAN address of my router.
 - DNS [Domain Name System]: a method of matching human-friendly device names to their computer-friendly IP addresses. The computer servers that respond with an IP address when a name is queried are called nameservers. Since you can't look up the nameservers by name until you know where to send the requests, the primary DNS and secondary DNS (only used if the primary fails to respond in a specific time) servers to be used by your device are specified as IP addresses.
 - SSH [Secure SHell]: an encrypted connection for text-mode (console, terminal) communications between a client and server. Windows 10 includes an ssh text-mode client as part of the operating system so you don't have to download it, only enable it as an optional feature; PuTTY and Bitvise SSH Client are free, have graphical/text interfaces, and work on other versions of Windows. Linux and macOS include ssh command-line programs.



 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I've been thinking about how one might access the Raspberry Pi computer inside the B2 if it's not on a network. If the Raspberry Pi in the B2 boots the same way that my Raspberry Pi 4 does, then it seems to me that if one connects a TV or monitor to the HDMI port, and a keyboard to one of the USB jacks, before powering up, the underlying Linux OS in the Pi should find them and just give you an old-fashioned text console. As long as you've saved a backup copy of the /etc/network/interfaces file under another name, you could put it back even without being able to get on the network. I still need to test that.

Again, though, if you've been working with a spare SD card or have problems, just put the original back; or if you have a Linux system (even a live Linux USB stick that you can boot your "other" computer from) available, you could just edit the SD card directly without using ssh. /etc is on a partition that Windows can't read, so the Linux system is needed.

Peter Lowham

unread,
Jun 18, 2021, 10:54:45 AM6/18/21
to Brennan Forum
Hi Mark,

I set up a keyboard and HDMI connection to the B2 a while ago. Yes, you do get start-up messages on the screen, and the keyboard is sensed, but you are locked inside the B2 application, and the application processes the keyboard strokes in the same way that it processes the front panel knob.  I didn't do very much digging, but I did not find a way of breaking out of the B2 application.  So, I did not get access to the Linux level.

So if anyone is attempting this static IP address set up, Mark's advice to use a second SD card is critical.  That way, yuo can recover your B2 if you make a mistake in following these instructions.  If you do make a mistake and do find yourself locked out of the B2, then the only other way to recover the situation will be to re-flash the SD card with the B2's base image file and start again.

Regards,
Peter.

Mark Fishman

unread,
Jun 18, 2021, 11:09:52 AM6/18/21
to Brennan Forum
My very last paragraph does point out that if you have another computer that can run Linux -- even if only by booting a "live" Linux distro or rescue system from a USB stick -- you can take the SD card out of the B2, mount the appropriate partition of the SD card, and edit the files directly, then umount and put the card back in the B2. That's why the minimal safety procedure is to copy the files you need to edit and keep the originals.

Working on a copy of the SD card is simpler for most people.

BTW, for those so inclined and who are even mildly familiar with Linux, I recommend having a copy of the System Rescue CD around, as a general toolbox. (https://www.system-rescue.org/)

Mark Fishman

unread,
Jun 18, 2021, 1:38:53 PM6/18/21
to Brennan Forum
Peter is, of course, absolutely correct: the keyboard/monitor approach will not work on a B2. So scrap my very next-to-last paragraph (at the very end, below the tildes): it's useless. The very last paragraph does work, though.

The rest of the instructions are correct: ESPECIALLY the bit about having a copy of your SD card before you start, and working with the copy.

Thanks (again), Peter. -- m.


On Friday, June 18, 2021 at 10:54:45 AM UTC-4 peter....@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages