I've received several variations of this question since starting my "Question of the Week" series. Having never studied the terrorism issue, I've been ignoring those queries.
But I got several new emails on the topic after what happened in Boston, so I'm answering simply to make one point. There's no way to create a perfectly safe, risk-free society.
That being said - and with the caveat that I have no expertise in this field, here are some random thoughts on the topic.
Libertarians want less interventionism around the world, and perhaps that will reduce hostility against the United States, but some of these nutjobs hate us because of our freedoms. So even a perfect foreign policy (whatever that even is) provides no guarantee we won't get attacked. That being said, I think Ron Paul has screwed up big time in some of his criticisms of U.S. actions. Being against nation building does not mean you have to be against killing terrorists.
If you want to cause trouble, find a bunch of young men with no purpose in their lives and lots of time on their hands. Combine that with religious extremists who tell those men that they will get a bunch of virgins* in paradise if they die while killing Westerners, and you have a nontrivial supply of future terrorists. I suspect part of the answer will have to come from within the Islamic community, though I confess that I'm puzzled by the inaction on that front even though one imagines that 99 percent of Muslims don't support terrorism.
Terrorists and would-be terrorists get information from the Internet that fuels their hate and provides knowledge on how to conduct attacks. I'm rather sympathetic to drone attacks on the scum in the Middle East who are directly seeking to instigate/plan terrorism, but I don't see any feasible or desirable way to control and/or regulate the Internet (just like I don't see a feasible or desirable way to regulate video games, even if it was shown that violent games somehow inspired Newtown-type killers).
Close monitoring of pro-terrorist websites and chat rooms is a very legitimate and proper function of law enforcement and the intelligence community. Being a Muslim shouldn't be a cause for investigation and harassment by the government. Being a Muslim who uses the Internet to visit such sites is a cause for investigation and harassment (and the same is true for members of any other group with a history of violence).
Monitoring of Mosques also is a proper function of government, just as I also have no objection of law enforcement monitoring militia groups, environmental groups, etc, etc. Obviously, the monitoring of any group should be selectively focused on those strains that are believed to espouse violence. I don't know where you draw the line between freedom of religion and incitement of violence, but I have zero sympathy for radical Imams preaching hate inside the United States and would like to see them shut down/imprisoned/deported if they cross that line.
Yes, I'm disgusted by the leftists in the press who obviously hope for a "right wing" link any time there's an attack. These are the same journalists, by the way, who weren't even slightly bothered by Barack Obama's association with Bill Ayers, a real-life terrorist who bombed the NYC police department, the U.S. Capitol, and the Pentagon.
I favor immigration, but I want people who believe in tolerance and hard work. There should be some sort of test, however imperfect, designed to weed out those who do not believe in assimilation. I'm still flabbergasted that the U.S. government is so bloody incompetent that it gave a greed card to the so-called Blink Sheik. Such people should never be let in the country and there should be mechanisms for quick deportation (perhaps halfway across the Atlantic) if they do slip through the net.