在 Windows 域中使用带 IPSEC 隔离的 Alpine

来自 Alpine Linux
注意: ipsec-tools 已从 Alpine v3.13 版本开始移除

基于 微软的文档

要求

  1. IPSEC 使用证书来验证计算机之间的身份。在继续之前,您需要从域管理员处获取证书或 PSK(预共享密钥)。本文档概述了使用证书的方法。PSK 只是配置上的一些更改。
  2. 运行 Alpine 的计算机
  3. 几个网卡 - 如果您计划将此作为网关与域通信

步骤

  1. 安装最新版本的 Alpine。
  2. 配置它:记住保留一个接口用于 masq,另一个接口用于域网络。192.168.1.0/24 将用于 masq,而 10.1.1.0/24 将用于域
  3. #setup-alpine
  4. 安装以下软件包:ipsec-tools-cvs, openssl, iptables
  5. 分部分提取证书。域管理员给您的证书很可能是一个 pfx 文件。
Extract the CA
* #openssl pkcs12 -in PFXFILE -cacerts -nokeys -out DOMAIN-ca.pem 
Extract the Key part of your cert
* #openssl pkcs12 -in PFXFILE -nocerts -nodes -out MY-key.pem
Extract the Pub cert file
* #openssl pkcs12 -in PFXFILE -nokeys -clcerts -out MY-cert.pem
If your admin gives you a p7b file, this most likely contains the CA chain. You have to convert it to pem file format and use it as DOMAIN-ca.pem
* #openssl pkcs7 -inform DER -outform PEM -in CA_CHAIN -print_certs -text -out DOMAIN-ca.pem
  1. 将这些证书放入 /etc/racoon/ 中
  2. 这是用于域隔离中的身份验证标头。下面的策略文件仅用于在一台机器上使用端口 3389。格式是
policy src_net/mask[port] dst_net/mask[port] protocol policy and implementation of policy

下面的命令将为 rdesktop 连接(终端服务器)执行 AH

* #vi /etc/ipsec.conf
 spdflush;
 spdadd 0.0.0.0/0 10.1.1.2/32[3389] tcp -P out ipsec ah/transport//use;
 spdadd 10.1.1.2/32[3389] 0.0.0.0/0 tcp -P in ipsec ah/transport//use;

* #vi /etc/racoon/racoon.conf
 
path certificate "/etc/racoon/";

remote anonymous {
	exchange_mode main;
	certificate_type x509 "MY_cert.pem" "MY_key.pem";
	ca_type x509 "DOMAIN-ca.pem";
        #nat_traversal on; #this may not need to be used even if you are doing a router :). Have to research this.
	proposal {
		authentication_method rsasig;
		encryption_algorithm 3des;
		hash_algorithm sha1;
		dh_group 14 ;	
		}

	}
sainfo anonymous {
	encryption_algorithm 3des;
	authentication_algorithm hmac_sha1;
	compression_algorithm deflate;

}

* rc-service racoon start
* Get the masq working correctly
* #iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE