Sorry to hear that you are feeling so frustrated with the behavior. My DD (29months) went through an aggression phase. I didn't do the walking away thing, although sometimes I would step back a bit if I needed to protect myself. But as soon as I recovered my thinking, I would redirect rather than try to suppress, something toddlers naturally resist. So if your child goes to pull your hair, continue with the "Mommy likes gentle. That hurts, Mommy." And then say, "Hey, it seems like you really like to tug on things. Let's find something for you to tug on. Hmmm, how about this...."
So much of this is about understanding and respecting developmental stages. This is what toddlers do - they experiment with their own strength and sense of power. They thrive on spontaneous movement, and lack the self-control or forethought to think their actions through. I know my DD, she is sweet and loving, and yet, we went over a year with her going in and out of phases of aggression. It started at 13 months with her slapping my face, then she started throwing things at me, then she would kick me during diaper changes, then she'd hit the dog, etc....My point is this is what toddlers do. We can't just sit back and let them be hurtful, because they need us to teach them socially acceptable behavior, but we can communicate to them that we understand they have a need, and while we need to keep everyone safe from harm, we can still help them find ways to meet their need (i.e., when DD would hit our dog, I'd say, "Oh, that hurts him. Mommy needs to keep him safe. Let's find something else you can hit. Here, hit Sparky (stuffed dog)...- it won't hurt Sparky." Sometimes she'd try to go back for the dog, and I'd repeat what I said and eventually she'd gladly hit the stuffed dog, then she'd go around the room looking for other things she was able to hit. It was all about learning.)
I don't believe this is about attention, as long as the child is truly getting enough of the good kind. And if they're not, that should be the focus of the intervention. But if lots of time is being spent connecting in positive ways, than this is about experimentation and learning about cause and effect IMO.They are fascinated by their ability to elicit reactions from others. Respect that need in the child while still helping the child respect your need to be safe from harm
BTW, this started when DD was 13 months, and over the past year and half, we are now at the point that all I have to say to her is ,"Mommy likes gentle", and she almost always redirects herself toward gentle. After months and months of practice, her brain is finally able to control her impulse toward aggression. Young toddlers do not have this impulse control, especially when the focus of the intervention has been about suppression. The urge is just too strong to control - and that urge has a purpose. But sometimes, even at 29 months, when other things are going on in her brain, she's not able to control herself as well. On those occasions, she needs my help more. I repeat that I like gentle, and help her find an object to use roughly. There's no tension here. Actually, when we find safe objects for her to use aggressively together, we actually connect through the joint problem-solving we're doing. Who would ever think that aggression could equal connection? But it can.
The key with behavior, regardless of the age of the child, is not to expect immediate behavioral results. This behavior has served a purpose for the child for nine months, and he isn't going to be able to let it go easily. Expect him to hear your redirection, and still try to persist with what he's doing. That's not bad or attention seeking, and it doesn't mean the intervention isn't "working"; that's the goal-directed, "I need to finish what I started" thinking of the toddler. They're determined and that's a good thing.
Just stay calm and persistant and he'll follow your lead. If he resists, make the redirection playful and he'll be that much more likely to join in.