One way to gain fretboard mastery is learning the 'One Finger Per Fret technique'. This technique applies to all stringed instruments. Most often, it refers to guitar or bass, but the rule also works on other fretboard instruments that don't actually have frets, like a violin or cello.
The one finger per fret rule implies that each finger is assigned a fret to play and only plays the notes occurring on that fret. Practicing this technique makes for great warm-up exercises. In fact, you should go through them regularly in your practice sessions. And they can make very creative way of improving your playing. Check the video at the end of this lesson to see some examples in action.
The technique is pretty much what the title says, each finger is assigned a fret to play. Take a look at the first example in this post. It's for bass guitar, the fretting fingering is given under the tablature. The first finger only plays the notes at the 5th fret, the second finger only plays the notes at the 6th fret, and so on. This example travels from the thinnest string (G) to the thickest (E). When you play through the strings in one direction play back across them until you get to the string you started with.
An exercise like this is a great warm up exercise. Play it regularly to build up hand strength and dexterity. And, while you're at it make sure your other hand is accurately playing the strings whether you are using fingers or plectrum. That's a crucial element that is so often ignored by many players. Get both your hands working in sync. You might find that these can be physically and mentally draining fairly quickly. That's fine, spread a few different versions over a few different practice sessions.
The next example is for guitar. You can see that the only real difference is the number of strings and it's played at the 7th fret.
You do not always have to start with your first finger. This bass version starts with the 4th finger (the pinky finger) on the 15th fret and works back to the 1st.
Again, we can do the same on guitar. Start with the 4th finger and work back to the 1st. These are great versions because they focus attention on the outer part of your hand. It might not get as much action as the other side so this is great for building up strength, control and speed right across your fretting hand.
Play these exercises all over your fretboard. You'll find that up near the nut you need wide stretches, and way up high things can get a little claustrophobic and tight. One last exercise to wrap things up. You can apply eighth notes to these exercises, or even triplets or 16ths!
Now you've got all that down watch this video lesson that shows these techniques in action.