I've been having the same problem on and off for years now. I'm starting to claw my way out of it, excruciatingly slowly and am prone to relapse at any time. Currently I'm meant to be writing an essay I really don't care about. If it were a psychology assignment I was meant to be doing right now, I'd be neck-deep in journal articles and smearing my half-thought out crap all over every word document I have as a rough copy for the assignment. Since it's a history essay however, I'm here, telling someone else how to get out of the exact situation I'm in...
In my experience, it's a matter of motivation and self-control. If I don't have motivation to do what I'm meant to be doing, it doesn't get done without a Herculean effort of self-control. Unfortunately, I have very little motivation to do anything, in comparison to most people. Thus, self control. Self-control is hard to learn, but damn useful once you start getting the hang of it. Best way is to just do as others have suggested and force yourself to keep to strict benchmarks, but do so while interrupting you old schedule. It's amazing how much difference a change of location or routine can make, since if you're in new territory, you'll be more receptive to new routines and won't be able to immediately think something along the lines of 'fuck this, what's on *websites here*?'
Without someone hovering over you watching for slipups, you'll probably not be able to make yourself keep to the benchmarks or new routine consistently, but as long as you keep thinking out new approaches, you'll probably be able to figure out specifics plans to make sure you stick to them. Best idea I've yet had is to make myself leave the house more often when I have to get things done (like going to the school's library to work instead of doing it at home) and to never, ever listen/watch things in the background, as they distract me to hell and back. When I'm trying to work on the internet I also avoid opening non-work related tabs and refuse to look at non-work stuff, putting it off untill I've met some arbitrary landmark. Even if those landmarks are stupidly close ("Okay, once I've written 200 words of this 5000 word essay, it's break time!"), they're there at least. Persevere and keep pushing them back, no matter how shit it feels to be refusing yourself comfort.