I struggle with exactly the same thing. OTOH, the real superstar developers I've seen, can instantly achieve cast-iron concentration and focus. So it matters.
I figure that it ultimately boils down to practising impulse control, and trying to avoid distractions. Surfing the web is like a string of thirty-second activity-reward cycles: open a Web page, read it, *boom* dopamine hit.
I have two strategies I use: firstly, I try and maintain my awareness of 'flow' at work, and the little things that break it. Secondly, I go out of my way to find things to do which require achieving and holding focus (but don't overdo it).
Firstly, I find that when I'm working (cutting code), things like slow compiles break my flow, because it's easy to hit Alt-Tab and start surfing shit (until I catch myself, and get back on task). So I find little ways to maintain flow; staying off email, staying off Facebook, staying off Reddit, etc etc. Ringing my terminal when compiles finish, so I can get back on track more easily.
Secondly, I go out of my way to spend my off-hours doing things that require focus, and don't involve a computer. I'm working on a maths degree, as well as teaching myself a musical instrument, and when I establish 'flow' on either activity, I know I'm benefiting. Just the mere act of practising 'establishing flow', has yielded improvements.
I know I've had a good day, when I get home, and I'm too tired to do anything else. Focus is like a muscle; initially it is weak, and needs training up, but with exercise, it gets stronger and stronger.