CentOS 에서는 racoon 을 사용한 IPsec 연결을 제공합니다. 일반적인 고정아이피 끼리의 host-to-host, net-to-net 연결방식은 다음 링크를 참고하시기 바랍니다.
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-networkscripts-interfaces-ipsec.html
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-vpn.html
http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_security_guide/s1-ipsec-host2host.html
여기에 설명되어 있지 않은 IPsec 연결방식 중 road-warrior 는 유동 아이피와 IPsec 연결을 만들 때 사용됩니다. 유동 아이피를 가진 서버에게 실제 고정 아이피를 할당할 때 사용하는데요, CentOS 는 기본적으로 road-warrior 를 지원하지 않기 때문에 추가 설정이 필요합니다.
이 포스팅에서는 일반적인 IPsec 설정보다는 road-warrior 설정에 필요한 방법만을 설명합니다. IPsec에 대한 이해가 있고 CentOS 에서 일반적인 host-to-host, 또는 net-to-net 설정이 가능한 독자층을 대상으로 하고 있으니 자세한 설정 내용은 위 링크를 참고하기기 바랍니다.
일단 클라이언트쪽의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 설정은 일반적인 설정과 크게 다르지 않습니다. DST 항목은 IPsec 을 연결할 서버가 되어야 합니다. SRC는 유동아이피이므로 지정하지 않습니다. SRCNET, DSTNET 을 지정하면 SRCNET -> DSTNET 의 연결에 대해 IPsec 을 통하도록 policy를 생성합니다.
서버쪽의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 에서는 반대로 DST=anonymous 로 지정합니다. SRC는 지정하지 않아도 됩니다. 어차피 policy 는 클라이언트 -> 서버 방향으로 SA 생성 단계에서 자동으로 만들어지는 것이 목표입니다.
클라이언트, 서버 양쪽 모두 IKE_METHOD=X509 를 사용합니다. PSK 방식을 많이 사용하시겠지만, PSK는 CentOS ifup-ipsec 스크립트 구조상 identifier가 address로 고정되기 때문에 road-warrior 방식에서는 적합하지 않습니다. 다음 커맨드를 서버에서 사용하여 X509 인증을 설정합니다.
클라이언트에서도 똑같은 방법으로 <클라이언트키이름> 을 사용하여 키페어를 생성 후, <클라이언트키이름>.public 파일을 서버쪽으로 복사합니다.
이제 서버의 /etc/racoon/certs/ 에는 <서버키이름>.private <서버키이름>.public <클라이언트키이름>.public 파일이 있을겁니다.
클라이언트의 /etc/racoon/certs/ 에는 <클라이언트키이름>.private <클라이언트키이름>.public <서버키이름>.public 파일이 있어야 합니다.
그러면 서버의 ifcfg-ipsec0 에서 cert 파일 설정을 다음과 같이 해 줄 수 있습니다. .public, .private 는 붙이지 않습니다.
그러면 ifcfg-ipsec0 준비는 끝났습니다. ifup ipsec0 으로 ipsec0 인터페이스를 올리면 /etc/racoon/racoon.conf 파일과 해당 DST 에 대한 conf 파일이 자동으로 생성됩니다. 라우팅, 폴리시 추가에서 에러가 주르륵 나지만 동작에는 큰 문제가 없습니다.
이제 마지막으로 서버의 /etc/racoon/anonymous.conf 파일을 수정해 generate_policy on; 옵션을 다음과 같이 추가해줍니다.
위 설정이 없으면 다음과 같은 에러가 발생합니다.
다시 ifdown ipsec0; ifup ipsec0 을 통해 인터페이스를 재시작하고 클라이언트에서 서버로 IPsec 접속이 되나 확인합니다.
설정 후에는 다음과 같은 에러가 발생하나, 정상적인 동작입니다.
만일 서버의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 파일을 수정했다면, /etc/racoon/anonymous.conf 이 재생성되므로 generate_policy on; 를 다시 추가해줘야 합니다. 서버에 있는 /etc/sysconfig/network-scripts/ifup-ipsec 파일을 수정하여 자동적으로 추가하게 만드는 방법도 있지만, 배포판 업데이트시 충돌을 야기하기 때문에 추천하지는 않습니다.
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-networkscripts-interfaces-ipsec.html
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-vpn.html
http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_security_guide/s1-ipsec-host2host.html
여기에 설명되어 있지 않은 IPsec 연결방식 중 road-warrior 는 유동 아이피와 IPsec 연결을 만들 때 사용됩니다. 유동 아이피를 가진 서버에게 실제 고정 아이피를 할당할 때 사용하는데요, CentOS 는 기본적으로 road-warrior 를 지원하지 않기 때문에 추가 설정이 필요합니다.
이 포스팅에서는 일반적인 IPsec 설정보다는 road-warrior 설정에 필요한 방법만을 설명합니다. IPsec에 대한 이해가 있고 CentOS 에서 일반적인 host-to-host, 또는 net-to-net 설정이 가능한 독자층을 대상으로 하고 있으니 자세한 설정 내용은 위 링크를 참고하기기 바랍니다.
일단 클라이언트쪽의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 설정은 일반적인 설정과 크게 다르지 않습니다. DST 항목은 IPsec 을 연결할 서버가 되어야 합니다. SRC는 유동아이피이므로 지정하지 않습니다. SRCNET, DSTNET 을 지정하면 SRCNET -> DSTNET 의 연결에 대해 IPsec 을 통하도록 policy를 생성합니다.
서버쪽의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 에서는 반대로 DST=anonymous 로 지정합니다. SRC는 지정하지 않아도 됩니다. 어차피 policy 는 클라이언트 -> 서버 방향으로 SA 생성 단계에서 자동으로 만들어지는 것이 목표입니다.
클라이언트, 서버 양쪽 모두 IKE_METHOD=X509 를 사용합니다. PSK 방식을 많이 사용하시겠지만, PSK는 CentOS ifup-ipsec 스크립트 구조상 identifier가 address로 고정되기 때문에 road-warrior 방식에서는 적합하지 않습니다. 다음 커맨드를 서버에서 사용하여 X509 인증을 설정합니다.
sudo openssl req -x509 -new -keyout /etc/racoon/certs/<서버키이름>.private -out /etc/racoon/certs/<서버키이름>.public -nodes -days 3650
chmod 600 /etc/racoon/certs/<서버키이름>.private
그리고 /etc/racoon/certs/<서버키이름>.public 파일을 클라이언트의 /etc/racoon/certs/ 로 복사해줍니다.chmod 600 /etc/racoon/certs/<서버키이름>.private
클라이언트에서도 똑같은 방법으로 <클라이언트키이름> 을 사용하여 키페어를 생성 후, <클라이언트키이름>.public 파일을 서버쪽으로 복사합니다.
이제 서버의 /etc/racoon/certs/ 에는 <서버키이름>.private <서버키이름>.public <클라이언트키이름>.public 파일이 있을겁니다.
클라이언트의 /etc/racoon/certs/ 에는 <클라이언트키이름>.private <클라이언트키이름>.public <서버키이름>.public 파일이 있어야 합니다.
그러면 서버의 ifcfg-ipsec0 에서 cert 파일 설정을 다음과 같이 해 줄 수 있습니다. .public, .private 는 붙이지 않습니다.
IKE_CERTFILE=<서버키이름>
IKE_PEER_CERTFILE=<클라이언트키이름>
클라이언트에서는 반대로 입력하면 됩니다.IKE_PEER_CERTFILE=<클라이언트키이름>
그러면 ifcfg-ipsec0 준비는 끝났습니다. ifup ipsec0 으로 ipsec0 인터페이스를 올리면 /etc/racoon/racoon.conf 파일과 해당 DST 에 대한 conf 파일이 자동으로 생성됩니다. 라우팅, 폴리시 추가에서 에러가 주르륵 나지만 동작에는 큰 문제가 없습니다.
이제 마지막으로 서버의 /etc/racoon/anonymous.conf 파일을 수정해 generate_policy on; 옵션을 다음과 같이 추가해줍니다.
remote anonymous
{
generate_policy on;
exchange_mode aggressive, main;
my_identifier asn1dn;
peers_identifier asn1dn;
...생략...
{
generate_policy on;
exchange_mode aggressive, main;
my_identifier asn1dn;
peers_identifier asn1dn;
...생략...
위 설정이 없으면 다음과 같은 에러가 발생합니다.
2009-11-29 09:13:07: INFO: respond new phase 2 negotiation: xxx.xxx.xxx.xxx[500]<=>yyy.yyy.yyy.yyy[500]
2009-11-29 09:13:07: ERROR: no policy found: aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:13:07: ERROR: failed to get proposal for responder.
2009-11-29 09:13:07: ERROR: failed to pre-process packet.
2009-11-29 09:13:07: ERROR: no policy found: aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:13:07: ERROR: failed to get proposal for responder.
2009-11-29 09:13:07: ERROR: failed to pre-process packet.
다시 ifdown ipsec0; ifup ipsec0 을 통해 인터페이스를 재시작하고 클라이언트에서 서버로 IPsec 접속이 되나 확인합니다.
설정 후에는 다음과 같은 에러가 발생하나, 정상적인 동작입니다.
2009-11-29 09:14:58: INFO: respond new phase 2 negotiation: xxx.xxx.xxx.xxx[500]<=>yyy.yyy.yyy.yyy[500]
2009-11-29 09:14:58: INFO: no policy found, try to generate the policy : aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel 211.215.9.154[500]->165.132.148.222[500] spi=216702467(0xcea9e03)
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel yyy.yyy.yyy.yyy[500]<=>xxx.xxx.xxx.xxx[500] spi=~~(0x~~~)
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=fwd"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "bbb.bbb.bbb.bbb/m[0] aaa.aaa.aaa.0/n[0] proto=any dir=out"
2009-11-29 09:14:58: INFO: no policy found, try to generate the policy : aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel 211.215.9.154[500]->165.132.148.222[500] spi=216702467(0xcea9e03)
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel yyy.yyy.yyy.yyy[500]<=>xxx.xxx.xxx.xxx[500] spi=~~(0x~~~)
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=fwd"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "bbb.bbb.bbb.bbb/m[0] aaa.aaa.aaa.0/n[0] proto=any dir=out"
만일 서버의 /etc/sysconfig/network-scripts/ifcfg-ipsec0 파일을 수정했다면, /etc/racoon/anonymous.conf 이 재생성되므로 generate_policy on; 를 다시 추가해줘야 합니다. 서버에 있는 /etc/sysconfig/network-scripts/ifup-ipsec 파일을 수정하여 자동적으로 추가하게 만드는 방법도 있지만, 배포판 업데이트시 충돌을 야기하기 때문에 추천하지는 않습니다.
CentOS provides IPsec with racoon IKE and scripts. It's well documented in following official and other links, if you are using host-to-host or net-to-net connection between two hosts which have fixed ip-address on both side.
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-networkscripts-interfaces-ipsec.html
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-vpn.html
http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_security_guide/s1-ipsec-host2host.html
But, there are another way to use IPsec, which is called as "road-warrior" is used to make secure IPsec connection from client with dynamic ip-address to server. We need to configure a bit more to use this way, because CentOS do NOT support road-warrior officially.
In this post, the specific how-to about road-warrior will be explained, aiming who understand basics of IPsec and can setup generic host-to-host or net-to-net connection in CentOS. If you are not familiar with these topics, please refer above links.
First, the configuration in "/etc/sysconfig/network-scripts/ifcfg-ipsec0" is not significantly differ with generic IPsec setting. "DST" must be set with ip-address of server, and "SRC" should be omitted because the address is dynamic. Packets from "SRCNET" to "DSTNET" will be relayed via IPsec with the policy created by script.
On the contrary, server should use "DST=anonymous" in "/etc/sysconfig/network-scripts/ifcfg-ipsec0", this is magic keyword for road-warrior. "SRC" should be excluded, policies will be generated with the generation of SA.
For authentication, "IKE_METHOD=X509" would be set in this case. PSK is popular, but CentOS use address as default identifier when PSK is used which is not suitable with road-warrior. Use following commands to produce X509 key-pair.
Vice versa, make key-pair in the client with <client_key_name> and copy <client_key_name>.public file to server side.
In summary, server's /etc/racoon/certs/ should have following files: <server_key_name>.private <server_key_name>.public <client_key_name>.public
And client's /etc/racoon/certs/ does <client_key_name>.private <client_key_name>.public <server_key_name>.public
Then the certification setting in ifcfg-ipsec0 can be set like this:
Now ifcfg-ipsec0 is ready for ifup. Use "ifup ipsec0" command to activate ipsec0 interface, and "/etc/racoon/racoon.conf", "DST.conf " file will be generated. You will see several errors while getting routes and generating policies, but it is not problem on operation.
Finally, modify server's "/etc/racoon/anonymous.conf" to add "generate_policy on;" option.
Following errors will be occur if you don't add above configuration:
Toggle the ipsec0 interface down and up with "ifdown ipsec0; ifup ipsec0" command. The IPsec will work functionally when client connect to server!
Some other error can be found in log, but it's just usual error message.
If you change "/etc/sysconfig/network-scripts/ifcfg-ipsec0" file on the server, you have to insert "generate_policy on;" again because "/etc/racoon/anonymous.conf" is regenerated while interface up.
You can modify the server's "/etc/sysconfig/network-scripts/ifup-ipsec" to avoid the repetition on change of configuration, but this workaround make another possibility of conflicting while update or upgrading system. So I do not recommend this workaround.
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-networkscripts-interfaces-ipsec.html
http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-vpn.html
http://www.linuxtopia.org/online_books/centos_linux_guides/centos_linux_security_guide/s1-ipsec-host2host.html
But, there are another way to use IPsec, which is called as "road-warrior" is used to make secure IPsec connection from client with dynamic ip-address to server. We need to configure a bit more to use this way, because CentOS do NOT support road-warrior officially.
In this post, the specific how-to about road-warrior will be explained, aiming who understand basics of IPsec and can setup generic host-to-host or net-to-net connection in CentOS. If you are not familiar with these topics, please refer above links.
First, the configuration in "/etc/sysconfig/network-scripts/ifcfg-ipsec0" is not significantly differ with generic IPsec setting. "DST" must be set with ip-address of server, and "SRC" should be omitted because the address is dynamic. Packets from "SRCNET" to "DSTNET" will be relayed via IPsec with the policy created by script.
On the contrary, server should use "DST=anonymous" in "/etc/sysconfig/network-scripts/ifcfg-ipsec0", this is magic keyword for road-warrior. "SRC" should be excluded, policies will be generated with the generation of SA.
For authentication, "IKE_METHOD=X509" would be set in this case. PSK is popular, but CentOS use address as default identifier when PSK is used which is not suitable with road-warrior. Use following commands to produce X509 key-pair.
sudo
openssl req -x509 -new -keyout /etc/racoon/certs/<server_key_name>.private
-out /etc/racoon/certs/<server_key_name>.public -nodes -days 3650
chmod 600 /etc/racoon/certs/<server_key_name>.private
Next, copy /etc/racoon/certs/<server_key_name>.public file to client at the location of /etc/racoon/certs/.chmod 600 /etc/racoon/certs/<server_key_name>.private
Vice versa, make key-pair in the client with <client_key_name> and copy <client_key_name>.public file to server side.
In summary, server's /etc/racoon/certs/ should have following files: <server_key_name>.private <server_key_name>.public <client_key_name>.public
And client's /etc/racoon/certs/ does <client_key_name>.private <client_key_name>.public <server_key_name>.public
Then the certification setting in ifcfg-ipsec0 can be set like this:
IKE_CERTFILE=<server_key_name>
IKE_PEER_CERTFILE=<client_key_name>
.public, .private are excluded in this files. The client use reversed order of there key.IKE_PEER_CERTFILE=<client_key_name>
Now ifcfg-ipsec0 is ready for ifup. Use "ifup ipsec0" command to activate ipsec0 interface, and "/etc/racoon/racoon.conf", "DST.conf " file will be generated. You will see several errors while getting routes and generating policies, but it is not problem on operation.
Finally, modify server's "/etc/racoon/anonymous.conf" to add "generate_policy on;" option.
remote anonymous
{
generate_policy on;
exchange_mode aggressive, main;
my_identifier asn1dn;
peers_identifier asn1dn;
...omitted...
{
generate_policy on;
exchange_mode aggressive, main;
my_identifier asn1dn;
peers_identifier asn1dn;
...omitted...
Following errors will be occur if you don't add above configuration:
2009-11-29 09:13:07: INFO: respond new phase 2 negotiation: xxx.xxx.xxx.xxx[500]<=>yyy.yyy.yyy.yyy[500]
2009-11-29 09:13:07: ERROR: no policy found: aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:13:07: ERROR: failed to get proposal for responder.
2009-11-29 09:13:07: ERROR: failed to pre-process packet.
2009-11-29 09:13:07: ERROR: no policy found: aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:13:07: ERROR: failed to get proposal for responder.
2009-11-29 09:13:07: ERROR: failed to pre-process packet.
Toggle the ipsec0 interface down and up with "ifdown ipsec0; ifup ipsec0" command. The IPsec will work functionally when client connect to server!
Some other error can be found in log, but it's just usual error message.
2009-11-29 09:14:58: INFO: respond new phase 2 negotiation: xxx.xxx.xxx.xxx[500]<=>yyy.yyy.yyy.yyy[500]
2009-11-29 09:14:58: INFO: no policy found, try to generate the policy : aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel 211.215.9.154[500]->165.132.148.222[500] spi=216702467(0xcea9e03)
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel yyy.yyy.yyy.yyy[500]<=>xxx.xxx.xxx.xxx[500] spi=~~(0x~~~)
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=fwd"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "bbb.bbb.bbb.bbb/m[0] aaa.aaa.aaa.0/n[0] proto=any dir=out"
2009-11-29 09:14:58: INFO: no policy found, try to generate the policy : aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel 211.215.9.154[500]->165.132.148.222[500] spi=216702467(0xcea9e03)
2009-11-29 09:14:58: INFO: IPsec-SA established: ESP/Tunnel yyy.yyy.yyy.yyy[500]<=>xxx.xxx.xxx.xxx[500] spi=~~(0x~~~)
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=in"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "aaa.aaa.aaa.0/n[0] bbb.bbb.bbb.bbb/m[0] proto=any dir=fwd"
2009-11-29 09:14:58: ERROR: such policy does not already exist: "bbb.bbb.bbb.bbb/m[0] aaa.aaa.aaa.0/n[0] proto=any dir=out"
If you change "/etc/sysconfig/network-scripts/ifcfg-ipsec0" file on the server, you have to insert "generate_policy on;" again because "/etc/racoon/anonymous.conf" is regenerated while interface up.
You can modify the server's "/etc/sysconfig/network-scripts/ifup-ipsec" to avoid the repetition on change of configuration, but this workaround make another possibility of conflicting while update or upgrading system. So I do not recommend this workaround.
Posted by Arcy

