In Pirkei Avos (1,1) it says עשו סייג לתורה  make a fence around the Torah. By doing so you insure that one will not come to transgress the words of the Torah. Erecting a guard on the prohibitions of the Torah stems from the middah of fear of Hashem. The word גדר is gematriah 207 just like the word זר which means a stranger. The more gedarim one makes the more of a stranger becomes with the prohibition. Out of sight is out of mind.
However, Rav Hunter ztl writes in his last mamar on Pesach that by making fences גדרים one is also acting from the middah of אהבה by bestowing the Torah with love and honor. The greater amount of fences he places on the observance of the mitzvos, the greater amount of kovid and preciousness he demonstrates for the Torah. We are mistaken to think that adding guards to the Torah is the avodah of סור מרע  alone. Simultaneously it also includes the action of עשה טוב which is rooted in the midah of אהבה.
Chazal say that Hashem also makes גדרים .  In Avos D’reb Nosson Perek 1
ועשה סייג לדבריך כדרך שעשה הקב”ה סייג לדבריו ואדם הראשון עשה סייג לדבריו. תורה עשתה סייג לדבריה. משה עשה סייג לדבריו ואף איוב ואף נביאים וחכמים כולם עשו סייג לדבריהם. איזהו סייג שעשה הקב”ה לדבריו הרי הוא אומר (דברים כט כא) ואמרו כל הגוים על מה עשה ה’ ככה לארץ הזאת מלמד שגלוי היה לפני מי שאמר והיה העולם שעתידין הדורות כך לומר על מה עשה ה’ ככה לארץ הזאת לפיכך א”ל הקב”ה למשה משה כתוב והנח לדורות הבאים ואמרו על אשר עזבו את ברית ה’ [וגו’] וילכו ויעבדו אלהים אחרים וישתחוו להם אלהים אחרים אשר לא ידעום ולא חלק להם. הא למדת (שעשה הקב”ה סייג לדבריו וכתיב בתריה מה שהיו עתידין לומר עדיין) שהוציא הקב”ה שכר בריותיו בשלום.
“When the future generations will see the diseases and plagues that afflict Eretz Yisrael, that it cannot be sown and it is infertile, they will ask what caused Hashem’s great fury. Then they will say because they served idolatry and thereby engaged Hashem’s wrath, and He cast them to another land”. From this we see that Hashem made a protection for His words of giving Eretz Yisrael as an inheritance to them after taking them out of Mitzrayim and now He is taking it away from them with anger. Hashem even quoted in the Torah the reaction of the future generations to this destruction of Eretz Yisrael and what they will say.
Therefore we can suggest that making גדרים to protect the words of Hashem is following and emulating Hashem who also made גדרים  for His words written in the Torah. Emulating Hashem stems from אהבה for it is only the one whom we love and admire that motivates us to strive to emulate and model ourselves after him. This is the depth of the aspect of עשה טוב  which is involved in making גדרים .
Afterwards I found in the Shlah Hakadosh (Beshalach) this same concept. He writes the following
כי אמר אלהים פן ינחם העם בראותם מלחמה ושבו מצרימה (שמות יג יז) ראה והביטה כמה צריך האדם להתבונן לעשות גדרים וסיגים והרחקות שלא יבא לידי עבירה. הנה הקב”ה בעצמו בכבודו עשה הרחקה פן ינחם העם וג’ שלום שלום לרחוק (ישעיה נז יט) המרחק עצמו מחשש עבירה ואז הוא קרוב להקב”ה.
How does one become close to Hashem by making גדרים ? It is we mentioned above because he fulfillsזה אלי ואנוהו  which Rashi explains is a combination of two words אני והוא emulating Hashem (Shabbos 133b).
Apparently we can bring a further proof that Hashem makes gedarim from the rainbow. (Bereishis 9,14) “I will confirm my bris with you that never again will any flesh be wiped out by the floodwaters and there will never again be a flood to destroy the earth. This is the sign I have placed my rainbow in the cloud and it will be a sign of the covenant. Then when I will cause to come clouds of destruction, the rainbow will appear in the cloud and I will remember the covenant which is between Me and you, and the water will no longer become a flood to destroy earth”.      
It is as if Hashem made for himself a geder that when and if He is about to bring a flood, the alarm will sound and the rainbow will appear. This geder will restrain Hashem from bringing on the flood.
Now we can understand the words of (Vayikrah 18,30) ושמרתם משמרתי in a deeper level. Chazal deduct from this double lashon עשו משמרת למשמרתי. The Torah is called משמרתי  and one is obligated to make safeguards to the Torah (Yevamos 21). However, according to Avos D’reb Nosson we can interpret this to mean that Hashem Himself made a משמרת to His own words and therefore we are obligated to do the same and make סייגים to His words written in the Torah.
By Avraham Avinu we also find the same lashon (Bereishis 26,5) עקב אשר שמע אברהם בקולי וישמר משמרתי that Avraham made gedarim just like Hashem. Rashi comments גזרות להרחקה על אזהרות התורה כגון שניות לעריות ושבות לשבת. However, where do we see explicitly that Avraham made a גדר to his own words? We suggest that such a source is in Bereishis 14,22 when after Avraham was victorious defeating the Four Kings, the king of Sodom offered him the booty of the war. Avraham responded  with a שבועה  to Hashem “I will not take from the spoils even a thread or a shoelace nor will I take from whatever you possess so that you will not say I have made Avraham wealthy, for Hashem Himself promised to make me rich.
The Medrash says that Avraham swore to Hashem in order that his yetzer harah won’t prove to him otherwise and that he was wrong for not taking from the spoils. The lure of money is so strong that this same Avraham who gave up his life to be thrown into a fiery furnace for emunas Hashem nevertheless needed here the  גדר and fear of a shevuah in order to preserve his resolve not to partake from the spoils. וישמר משמרתי. 
In this week’s parsha we find that Balak was afraid of attacking Klal Yisrael for Hashem redeemed them from Mitzrayim in a miraculous fashion. Furthermore, Am Yisrael wiped out Sichon and Og who used to protect us. This fear was a geder to protect Am Yisrael from being harmed by the nations and it is described in אז ישיר with six varying grades of fear such asחיל , בהלה,   .פחד ,אימה, נמוגו ,רעדהTo get around this, he hired Bilam to curse them and in this way they will be able to overcome the גדר  of fear that the nations possess about attacking Yisrael. We find that as Billam travelled to curse Yisrael, he was passing between two parallel walls of stone and his leg became crushed byגדר מזה וגדר מזה  (Bamidbar 22,24). This scenario alludes to a deeper meaning other than relating the physical injury that Billam received while riding his אתון. Bilam’s goal was to successfully curse Yisrael and thereby crush this גדר (fence) of fear that has paralyzed all the nations. Hashem was sending him the message with these two גדרים that attaining such a goal is futile and the only one to be crushed at the end is you.
 בלעם and בלק both possess two letters of עמלק. The nation of Amalek was the first to break the fence of fear that protected Am Yisrael from attack because of the Ten Makkos and Kerias Yam Suf.  Billam’s and Balak’s plan was identical to Amalek’s. When one analyzes the roots of Amalek he will find them in the chait of Aitz Hadaas, as Chazal say that Haman is hinted in the Torah from the passuk המן העץ הזה . At the chait of Aitz Hadaas we find the Nachash boasting how he broke the גדר which caused the cataclysmic fallout of mankind by his eating from its fruit. The Medrash  says (Chukas 9,2) the Nachash was asked why he is always found nearby fences. His reply was אני פרצתי גדרו של עולם. Adam told Chavah not to eat and not to touch the tree of Aitz Hadaas. He added the prohibition of touch in order to make a geder that she won’t come to eat from it. However, he omitted telling her that touching was only an added geder of his own and not the direct command from Hashem. So when the Nachash pushed her against the AitzHadaas he pointed out that just like you didn’t die from touching it, you also won’t die by eating from it. She then gave Adam to eat from it and since then the עולם was never ever the same.
So the Nachash’s sly method of deceiving Chavah into transgressing the word of Hashem was to break the geder. Therefore as a punishment, the Nachash is always found around fences a”k. Amalek whose roots are in the Nachash used the same tactic against Am Yisrael by removing from the nations their fear of attacking Yisrael which was a geder to keep them distant and restrained.
Billlam followed in the plan of these two giant generators of evil, the Nachash and Amalek, to destroy theגדר  of fear. This is why he was punished by the גדר מזה וגדר מזה the two parallel walls which also allude to the two forces of שקר in the world which strove to diminish the tzuras Adam Harishon and Yisrael the אתם קרויים אדם, by breaking the גדר of יראה (fear).
The Torah requires fear as aגדר  of fulfilling Hashem’s commandments. That is why the Torah is full of reprimand and punishment for those who dare transgress His words. It is very interesting that the gematriah of נחש ועמלק  with their eight letters equalsתורה  (including the word). Fear of Hashem is one גדר  to help preserve the Torah as the sefarim write on the passuk יראת ה’ טהורה עומדת לעד that the word יראת  is gematriahתורה. This middah helps to sustain the Torah to beעומדת לעד , without faltering. This is hinted by Shlomo Hamelech in the last passuk of Koheles סוף דבר הכל נשמע את האלקים ירא ואת מצוותיו שמור. That it is the middah of Yiras Shamayim that will preserve the fulfillment of the mitzvos. The secondגדר  is to make fences surrounding the mitzvos so we will not come near to transgress them.
At the end of the parsha we find that Bilam advised Balak that the way to curse Yisrael is by getting the men to fall into immoral acts with Moavite girls. Rashi writes (Bamidbar 22,5) that up until now civilization were גדורים מעריות and Bilam gave advise to act immorally which was a פרצו גדר העולם, the same lashon with which the Nachash boasted himself.  Once again, these two masters of evil attempted to break the gedarim. This temptation for immoral behavior led to the avodah zara of Baal Peor. The service to the avodahzarah of the idol of Peor was to defecate in front of it and place the waste matter on the idol. The more the defecation and self degradation, the greater service one did to this idol. What type of idolatry and meaning does this perverted avodah zarah have when people lose total respect and dignity of oneself and others?
Man who was created in the tzelim Elokim is a creation that possesses kovid like his creator. Man was created in order to discover Hashem’s kovod in creation. In order to discover it one must first possess it. Animals don’t blush and they defecate anywhere they please for they lack the sensation of self dignity. To make an avodah zarah where one debases himself publicly like an animal, and all the stops גדרים)) of the tzelem Elokim are already pulled out, is the lowest descent of man. Dignity and blushing are naturally built in gedarim with which man was created. We find that immediately after the chait of Aitz Hadaas, Adam and Chava used fig leaves to conceal their nakedness. Then the Torah says, that Hashem made for Adam and Chavah clothes. Hashem did not leave it up to man to invent clothing. For if so man can make it one day and break it the next day. Clothing was created by Hashem who is eternal. So too, modesty and the middah of tzenius is eternal for the Jewish Nation, and it doesn’t depend upon the sick perverts in Milan, Paris, and Madison Avenue to set the whimsical style and jive with the up to date insanity.
When one breaksגדרים  the fences and guardians that were instituted to protect the laws, what follows is when one fence falls the other one also falls quickly in its footsteps. It sets into motion a domino effect and one can fall very quickly to the bottom of the pit of decadence and beyond. The result of breaking גדרים in this parsha ends up with the avodah zara of Peor where all gedarim become lost.
This strange service of idolatry is found in the letters ofפעור  which are identical to עורף which means back of the neck. Making a geder causes one to turn his back on the aveirah, to look away, to take the longer route instead of the short one which is less tzeniusdik. The avodah zara of Peor was to remove any inhibition of tzenius and dignity of a person. פעור  is the opposite pull of עורף which is to turn your back from even coming  into the vicinity of an aveirah. פעור  means to uncover like one finds by the Sotah woman ופרע את ראשה to uncover her hair making her not tznius. The avodah zarah of Peor was to degrade man by removing all inhibitions of kovid and dignity and release the animal that lurks within.
From here we can go to our every day tefillah. The gematriah of גדר מזה וגדר מזה equals תפילה. What is the connection between the two? This shows us that davening strengthens our resolve to distant ourselves from all evil. It is an act of bittul nullifying oneself before the Almighty King of the universe and acknowledging that everything is created and sustained by Him.
The geder that Adam made for Chava was by adding the wordsולא תגעו  the prohibition to touch the tree. The gematriah of ולא תגעו is תפלה. The focus of one’s tefillah is to fortify and fine tune one’s priorities and to reinforce one’s devotion to strive for kedusha which means separation. It is the time when we must enforce the boundaries that protect us from the lures and seductions promulgated from the רשות הרבים who support an undisciplined and unrestrictive lifestyle. This is achieved through our recognition that nothing exists outside of Hashem’s will, which is the avodah of tefillah.
Before we start Shemoneh Esrai our Chachamim established to recite pessukim from Kerias YamSuf and mention the miraculous episode. The connection between the splitting of the sea and tefillah is as we just explained. A Yid must build walls surrounding himself to distant his lifestyle and ambitions from outside influences. When crossing the sea the water formed two walls on both of their sides, right and left, מימינם ומשמאלם similar to גדר מזה וגדר מזה. The Mechilta comments on these two walls

מי גרם להם לישראל להנצל מימינם ומשמאלם מימינם בזכות התורה שעתידין לקבל שנאמר דברים ל”ג מימינו אש דת למו ומשמאלם זו תפלה. ד”א מימינם ומשמאלם מימינם זו מזוזה שעתידין ישראל לעשות ומשמאלם זו תפילין which is placed on the left hand.
The reliving of Kerias YamSuf is with what we approach the Shemoneh Esrai. When we leave the house we must recognize the mezuzah whose inside words make a גדר for us not to be influenced from the sheker outside. Likewise we put tefillin on our bodies which is the housing for our neshamos, their words written on parchment make a גדר upon us not to crave bodily pleasures and cravings. Tefillah is the gematriah of גדר מזה וגדר מזה for it is our reality check and it makes us refocus on who is in the driver’s seat.
Gateway drugs lead to hard drugs. Dovid Hamelech says in Tehillim כי חזק בריחי שעריך ברך בניך בקרבך (Tehillim 147,13). When one strengthens the bolts of his gates, your children will be blessed. Dovid Hamelech is not worried about the bolts of your house but rather the bolts of your gates that stand before your doorstep. It is the gateway which is the geder that needs strengthening and tighter protection. For it is the גדר, that keeps the שקר away from your house. Notice that the word שעריך is gematria שקר.
If one ever unfortunately experienced a sewer back up in his house with excrement lying everywhere, he can get a picture of what happens when we don’t clean out the plumbing from time to time. The avodahzara of Peor was to invite and embrace the sewer to overflow and bring its bacteria and disease within our abode. Lehavdi ltefilla is our Roto Rooter to keep the sewerage concealed and hidden from our eyes and presence three times a day.
In the tefilla of Chazaras Hashatz the chazzan says ושבחך אלקינו מפינו לא ימוש לעולם ועד. How can we be so sure that our praising of Hashem will never be removed from our mouths? The key lies in the acronym of שבחך which is כי חזק בריחי שעריך ברך בנים בקרבך. When we the parents make extra necessary gedarim in our שעריך, after consulting with Daas Torah, then with the help of Hashem the praise of Hashem will not terminate by us and or by our future generations. Our gedarim will protect us and keep us far away from spiritual catastrophe.

 – Rav Brazil
Gut Shabbos