Mr Cameron added: "If I am prime minister, I will make sure it is a comprehensive piece of legislation that makes sure we do not allow terrorist safe spaces to communicate with each other.
"That is the key principle. Do we allow terrorists the safe spaces to talk to each other? I say 'no we don't".
He added: "I am confident the powers we need, whether it is on communications data or the content of communications, I am very comfortable they are absolutely right for a modern liberal democracy."
Labour leader Ed Miliband said it was important for security services to "keep up to date with technology" but said it had to be "done in the right way", with "basic liberties" protected.
"That's why we said there needs to be an independent look at these issues, to make recommendations about what needs to be changed for the future," he added.
Explaining his party's opposition to the draft Communications Data Bill in 2013, Lib Dem leader Nick Clegg said a "law which means there will be a record kept of every website you visit, who you communicate with on social media sites" would not happen when his party was in government.
Speaking on BBC Radio 4's The World at One, David Anderson QC, the government's independent reviewer of terror legislation, said the "real issue" was that people were communicating not over the telephone, but over the internet, using service providers based in the United States.
Liberal Democrat Civil Liberties Minister Simon Hughes said he would not support "blanket powers" that would take away the liberties of "innocent civilians".