I managed to make it work after googling stuff for around 2 hours. Here's a quick guide if you are in a similar situation.
You need to do things on both your mac and your CentOS machine to make sure that the forwarding works.
1) On your mac you need to install XQuartz. This is the daemon which would listen for the forwarded requests from your CentOS and render a UI on your mac.
2) On your CentOS you need to edit /etc/ssh/sshd_config and add the following entries to it
- AddressFamily inet #this entry ensures that SSH is not messed up over IPV6. My forwarding was not working till I made this entry.
- X11Forwarding yes #this entry will ensure that the forwarding happens from CentOS.
3) Next install a package called xauth on your CentOS machine. you can use yum to install it.
- yum install xauth
4) restart the ssh daemon
sudo service sshd restart
5) Install an app like xeyes to test if the X11 forwarding is working or not.
- yum install xeyes
- ssh -X user@host