I need to install SharePoint (Farm based installation) on VM and I have installed SQL Server 2008 R2 on my local machine.
How can I connect both the machines so that I can use sql instance settings on farm-based SharePoint installation??
I'd probably ensure you're VM's network card is setup in 'Bridged' mode (depending on what flavour of virtualisation you're using) then create a SQL alias on your SharePoint server VM (c:\windows\System32\cliconfg.exe) select enable TCP create an alias of you're choosing (SQLALIAS) point it at the IP address of your local machine and install SharePoint with that alias.
The catch is that since SharePoint is going to be very dependant on what ever account your using as the farm account and the actual install account which are typically domain accounts, so unless you're SQL server is setup for Windows authentication is somehow connected to your test domain then you're going to have a hard time making it all work, you're better off almost just installing SQL on the SharePoint VM.
But that said I'd use a SQL alias for any installation of SharePoint even a multi-server one.