Here are three methods that I especially like for learning the fretboard. I often sing the names of the notes as I practice these exercises – you can can even combine guitar practice with solfège.
1- and 2-string octaves
Practice playing octaves on fewer than three strings. Work out a few different ways to make the position shifts. Ideally, you will want to learn octaves both with small shifts (a whole tone) and larger ones (a perfect forth). The larger position shifts teach you to move your hand quickly and smoothly. The smaller shifts teach you how to reorient yourself from different scale degrees.
Scale practice books can help you get started with some patterns and exercises. I liked Paul Farnen’s exercises in Bass Fretboard Basics, for example. Once you get comfortable with a single octave, you can practice multiple octaves the same way. There are lots of ways to play two octaves on four strings, for example, and getting familiar with all of them will help you break out of “boxes.”
In The Jazz Theory Book, Mark Levine recommends practicing scales by shifting through modes. Start with an ascending C Ionian scale, then come back down with the D Dorian scale, then back up with E Phrygian, down F Lydian, up G Mixolydian, down A Aeolian, up B Locrian. Then cycle back down through the modes with the directions reversed. This will teach you how to navigate a key from any scale degree or direction, which helps both with modal play and functional harmony. You can combine this with the first approach – limiting yourself to 3 or 4 strings for this exercise will force you to move around the neck more.
Finally, you can learn to visualize the different notes around the fretboard by drilling yourself on their locations. To begin, find all of the A notes on your neck, one string at a time: E string, 5th fret; E string, 17th fret; A string, open; A string, 12th fret; and so on. Continue with all of the B notes, all of the C notes, and on through the rest of the scale. If you can sing the note names as you find them, it will help you associate the muscle memory of your hands and voice with your visual knowledge of the fretboard and your intellectual knowledge of the note names. The other two exercises will help you break free of the “boxes,” and this one will help you stay oriented.