Ratan Singh, an Indian rice farmer, used to have trouble sleeping. His village lies dangerously close to Pakistan, and in the past two years he has seen more than a half-dozen villagers and hundreds of cattle die in cross-border shooting.

But since India built a thick mud wall and an 8-foot-high, 3-tier maze of barbed-wire fence near the border in Kashmir, the guns have fallen silent.

"We are safe now, and I sleep peacefully," said Singh, 80. But he has a new problem. With the border fence that Indian soldiers erected near the turbulent, zigzag boundary last year, most of his farmland now falls on the other side, exposed to the Pakistani patrol posts. "I am too scared to go to my farm now," said Singh, as he pointed toward his land.

The fence is part of India's ambitious project to seal its entire 1,800-mile border with Pakistan. Even as India embarks on a peace process with its rival this summer, the massive effort has come to illustrate the deep suspicion, hostility and paranoia that have bedeviled relations between the nuclear neighbors for more than half a century.

Construction of the fences began in the late 1980s in the state of Punjab, when India faced an armed Sikh separatist uprising and weapons were being smuggled from Pakistan. The fences now cover almost half the border, at a cost so far of $300 million. India is pushing ahead with work in Jammu and Kashmir, India's only Muslim-majority state, to stop Islamic guerrillas from entering from Pakistan. India accuses Pakistan of training and arming militants who are fighting to end India's rule in Kashmir. The two nations have fought two of their three wars over the region.

Two months ago, officials began to string barbed wire across stretches of the disputed, mountainous cease-fire line, called the Line of Control, which encloses much of Jammu and Kashmir.

Pakistan considers Jammu and Kashmir disputed territory and objects to the fence.

"The border in Jammu and Kashmir remains un-demarcated. It is a working boundary and a cease-fire line," said Maj. Gen. Shaukat Sultan, Pakistan's military spokesman. "Any measure to alter the status of these and any attempt to erect [a] new impediment is a direct violation of international commitments, and Pakistan opposes it. Border fencing is not allowed."

But Indian officials claim they have a sovereign right to build inside Indian territory and accuse Pakistan of intensifying shooting and shelling where work is underway. To escape the Pakistani gunfire, Indian soldiers are building a 10-foot-high mud wall by night on the border, then work behind the wall during the day. Indian officials claim that Pakistan is firing at the earth-scooping machines and that four drivers have died and 17 others have been injured since work began two years ago.

"We cannot wish Pakistan away, it is going to remain our neighbor," said Dilip Trivedi, head of India's Border Security Force in Jammu and Kashmir. "The fence will be a permanent barrier at the border to prevent militants from entering. Why should we wait for them to come in and attack our people? Why not stop them at the border?"

About 43 miles of the border between Jammu and Kashmir and Pakistan is now closed off. Trivedi said there were 39 attempts at infiltration in 2000, but only two this year in the fenced area. India is also using Israeli ground sensors, radars and French thermal-imaging devices to detect movement along the Line of Control, which is patrolled by the Indian army. The rest of the India-Pakistan border is policed by the 20,000-member Border Security Force.

The terrain of the border, which runs through deep ravines and lofty forests that are under heavy snow four months a year, poses the biggest challenge for both physical and electronic fencing. India's goal is to cover the fencible parts within the next three years.

The other challenge, according to officials, is that this teeming nation of more than 1 billion people does not have a dead border. Hamlets and farmland go right up to the line. Grazers routinely take their cattle up to the borderland, and the movement of animals often sets off the sensors.

In the Indian border state of Rajasthan, marriage processions between villages in India and Pakistan were common until the fence went up.

Today, fencing is the preferred counterinsurgency measure. The Indian government decided not only to close off all borders with Pakistan in the west but also with Bangladesh in the east. On the Bangladesh border, India aims to stop illegal refugees, most of them Muslims, and to address the "smuggling of Indian cattle near the border for consumption," said an official.

Although the fence and the mud wall in his Kashmiri border village have made it safer for Jasveer Kumar, 32, to enter his farmland after several years, he is still unable to cultivate all of his land.

"My farm has a number of land mines, and I cannot go anywhere near it, let alone grow crops on it. That is the price we pay for living on the border," he said as he drove his tractor away from the area marked as mined. The Indian army has yet to clear the thousands of mines it laid along the border last year during the massive troop buildup that brought India and Pakistan to the brink of war.

Security analysts admit that militants would still be able to enter India.

"A fence can only make infiltration of militants difficult, not impossible. After all, even the Berlin Wall was breached," said K.P.S. Gill, a retired counter-terrorism police officer and head of Institute of Conflict Management in New Delhi. "Can erecting a physical barrier counter a Pakistani mentality that believes in a holy war to save Islam in Kashmir?"

Other critics point out that fencing is an expensive alternative to good border intelligence. They say the money could be spent on developing the impoverished border villages so that those who live there can become part of an effective intelligence network for the Indian state.

"No single measure is foolproof," said Vijay Raman of the Border Security Force. "In the final analysis, peace between India and Pakistan is the best fence."

Ratan Singh, an 80-year-old farmer in Gakhriyal Akhnur village, points to his farmland that now lies across the fence India is building along the border.