He was speaking to reporters as he landed in Indonesia on the first leg of a four-day trade mission he hopes to use to forge new political alliances to counter a threat he has described as a "death cult".
"If there is a threat to Britain or to our people on our streets ... we are able to stop it by taking immediate action against that threat," said Cameron.
"As prime minister, I would always want to try and take that action, and that’s the case whether that problem is emanating from Libya or Syria or anywhere else.”
Britain raised its domestic terrorism alert to the second-highest level in August last year, saying an attack was "highly likely".
Read: IS militants are plotting 'terrible' UK attacks, says Cameron
Cameron was due to meet Indonesian President Joko Widodo later on Monday to discuss how the two countries could cooperate in the battle against Islamist militancy.
The militant threat is high on the political agenda in Britain after a gunman killed 30 British tourists at a Tunisian beach resort last month in an attack claimed by Islamic State.
Read: At least 15 Britons among Tunisia terror victims
Tunisia's government said at the time that the gunman had been trained in a jihadist camp in Libya.
Britain is already taking part in US-led air strikes on Islamic State positions in Iraq and Cameron is keen to get parliamentary backing later this year to extend that aerial campaign to Syria. But he has not, before Monday, raised the prospect of bombing targets inside anarchic Libya.
Cameron spoke after The Sunday Telegraph reported Cameron and his advisers had discussed what they could do to help defeat Islamist militants in Libya if a stable government there emerged.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ