I wrote several blog posts and a little guide about to get your first client as a software consultant: https://www.breakintoconsulting.com/
Short version: become a "visible expert" in your field (blog posts, ebook, meetup talks), and then connect with people who might need your service.