iptables is widely used in Linux to manipulate network packets. There are a lot of blog posts about its usage. I also recommend one here:
This book contains many use cases and command parameter explanation about iptables. It alos has a picture depicting the flow of packet processing.