<?xml version="1.0" encoding="UTF-8" ?><oembed><version>1.0</version><provider_name>Jui-Nan Lin&#039;s Blog</provider_name><provider_url>https://jnlin.org</provider_url><author_name>jnlin</author_name><author_url>https://jnlin.org/author/jnlin/</author_url><title>IPSec 設定筆記</title><html>參考

&lt;a href=&quot;http://taosecurity.blogspot.com/2005/01/ipsec-tunnels-with-freebsd-although.html&quot;&gt;http://taosecurity.blogspot.com/2005/01/ipsec-tunnels-with-freebsd-although.html&lt;/a&gt;。
&lt;ol&gt;
	&lt;li&gt;修改 Kernel，加上
&lt;blockquote&gt;&lt;code&gt;options FAST_IPSEC
device crypto
&lt;/code&gt;&lt;/blockquote&gt;
並且重開機。&lt;/li&gt;
	&lt;li&gt;安裝 &lt;code&gt;security/ipsec-tools&lt;/code&gt;。&lt;/li&gt;
	&lt;li&gt;設定 &lt;code&gt;/usr/local/etc/racoon/racoon.conf&lt;/code&gt;:
&lt;blockquote&gt;&lt;code&gt;path pre_shared_key &quot;/usr/local/etc/racoon/psk.txt&quot;;
padding
{
maximum_length 20;      # maximum padding length.
randomize off;          # enable randomize length.
strict_check off;       # enable strict check.
exclusive_tail off;     # extract last one octet.
}&lt;/code&gt;

listen
{
isakmp (MY_IP) [500];
}
timer
{
# These value can be changed per remote node.
counter 5;              # maximum trying count to send.
interval 20 sec;        # maximum interval to resend.
persend 1;              # the number of packets per send.

&lt;em&gt; &lt;/em&gt;&lt;em&gt;# maximum time to wait for completing each phase.
phase1 30 sec;
phase2 15 sec;
}
remote &lt;/em&gt;&lt;em&gt;[500]
{
#exchange_mode main,aggressive;
exchange_mode aggressive,main;
doi ipsec_doi;
situation identity_only;&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;my_identifier user_fqdn &quot;sakane@kame.net&quot;;
peers_identifier user_fqdn &quot;sakane@kame.net&quot;;
#certificate_type x509 &quot;mycert&quot; &quot;mypriv&quot;;&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;nonce_size 16;
lifetime time 1 min;    # sec,min,hour&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;proposal {
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group 2;
}
}&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt;&lt;/blockquote&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt;&lt;/li&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; 	&lt;/em&gt; 	
	&lt;li&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;設定 &lt;code&gt;/usr/local/share/psk.txt: &lt;/code&gt;&lt;/em&gt;&lt;/li&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; 	&lt;/em&gt; 	
	&lt;li&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;設定 /etc/ipsec.conf:
flush;
spdflush;spdadd   any -P out ipsec
esp/tunnel/-/require; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;spdadd   any -P in ipsec
esp/tunnel/-/require;&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;spdadd  / any -P out ipsec
esp/tunnel/-/require;&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;spdadd /  any -P in ipsec
esp/tunnel/-/require;&lt;/em&gt;

&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt;&lt;/li&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; 	&lt;/em&gt; 	
	&lt;li&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;/usr/local/etc/rc.d/racoon.sh start; /etc/rc.d/ipsec start;&lt;/em&gt;&lt;/li&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt;&lt;/ol&gt;
&lt;em&gt; &lt;/em&gt;&lt;em&gt; &lt;/em&gt; &lt;em&gt;&lt;/em&gt;&lt;em&gt;P.S.
racoon 的範例設定檔在 &lt;code&gt;/usr/local/share/examples/ipsec-tools&lt;/code&gt; 裡面。&lt;/em&gt;</html><type>rich</type></oembed>