Configuración De Vpc En Amazonws

Manual simple para configurar una VPC en AmazonWS.
View more...
   EMBED

Share

Preview only show first 6 pages with water mark for full document please download

Transcript

Uso de Amazon VPC Creación de una VPC Instalación y configuración de OpenVPN Instalación del paquete de software Generación de certificados y llave para el Certificate Authority Generación del certificado y llaves del servidor Generación de parámetros Diffie Hellman Configuración y arranque del servidor Configuración del cliente Ruteo en la subred pública Creación de una VPC La forma más simple de crear una VPC es utilizando el Wizard, accesible mediante el Amazon VPC Console Dashboard a través del botón Get started creating a VPC El wizard presenta las cuatro opciones disponibles (figura 2), de la cual para nuestros propósitos elegiremos la segunda “VPC with Public and Private Subnets”. Nota: Las opciones tres y cuatro requieren el uso de gateways de hardware en las instalaciones del cliente para su acceso. Las subredes públicas albergan instancias que pueden tener acceso directo a Internet mediante una Elastic IP. Las subredes privadas en cambio requieren de una instancia en la subred pública que realize Network Address Translation por ellas y no tienen acceso directo a Internet. El siguiente cuadro de diálogo permite editar los parámetros por default de la VPC, por ejemplo, el bloque de direcciones que manejaremos para ruteo interno1, las subredes IP de ese bloque que representarán la subred pública y la privada, el tipo de instancia para la instancia que realizará NAT. La tercera imagen muestra estos (figura 3) Figura 2: Configuraciones de VPC Figura 3: Parámetros de la VPC ya modificados 1 Un bloque con al menos 16 bits para máscara de red Finalmente, en el VPC Console Dashboard podemos observar los elementos recién creados La instancia NAT le es asignada una IP, consultable en la consola de EC2 o en la parte de Navigation, apartado Virtual Private Clouds, opción Elastic IPs (en el caso del ejemplo es 107.23.68.41) A esta dirección se le debería crear un Resource Record en Route 53 para facilitar el acceso (para el ejemplo gw.natware.mx). Con la instancia de NAT arriba podemos realizar una sesión remota para actualizar e instalar OpenVPN, pero antes de eso al Security Group de la instancia NAT deberá configurarsele el acceso por medio de SSH. Finalmente realizamos la sesión y actualizamos el sistema: Natalie:~ rvaldez$ ssh -i .ssh/natwareawsadminkey.pem [email protected] The authenticity of host 'gw.natware.mx (107.23.68.41)' can't be established. RSA key fingerprint is 07:68:a9:9b:72:f9:56:b7:7d:16:49:67:6a:db:cc:07. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gw.natware.mx,107.23.68.41' (RSA) to the list of known hosts. __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___| See /usr/share/doc/system-release/ for latest release notes. There are 28 security update(s) out of 54 total update(s) available Run "sudo yum update" to apply all updates. [ec2-user@ip-172-16-1-193 ~]$ sudo yum update …. Complete! Instalación y configuración de OpenVPN Instalación del paquete de software [ec2-user@ip-172-16-1-193 ~]$ sudo yum install openvpn …. Complete! Copia de los archivos base para configuración [ec2-user@ip-172-16-1-193 etc]$ sudo mkdir /etc/openvpn [ec2-user@ip-172-16-1-193 etc]$ sudo cp -r /usr/share/openvpn/easy-rsa/2.0/* /etc/openvpn [ec2-user@ip-172-16-1-193 etc]$ ls /etc/openvpn/ build-ca build-key-server Makefile README build-dh build-req openssl-0.9.6.cnf revoke-full build-inter build-req-pass openssl-0.9.8.cnf sign-req build-key clean-all openssl-1.0.0.cnf tmp build-key-pass inherit-inter openssl-1.0.0.cnf-old-copy vars build-key-pkcs12 list-crl pkitool whichopensslcnf Se edita el archivo vars y se cambian los siguientes parámetros [ec2-user@ip-172-16-1-193 openvpn]$ sudo vi /etc/openvpn/vars # These are the default values for fields # which will be placed in the certificate. # Don't leave any of these fields blank. export KEY_COUNTRY="MX" export KEY_PROVINCE="YUC" export KEY_CITY="Merida" export KEY_ORG="GrupoPlenum" export KEY_EMAIL="[email protected]" [ec2-user@ip-172-16-1-193 openvpn]$ sudo su [root@ip-172-16-1-193 ~]# cd /etc/openvpn/ [root@ip-172-16-1-193 openvpn]# . vars NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/keys [root@ip-172-16-1-193 openvpn]# ./clean-all Generación de certificados y llave para el Certificate Authority [root@ip-172-16-1-193 openvpn]# ./build-ca Generating a 1024 bit RSA private key ..............++++++ ......++++++ writing new private key to 'ca.key' ----You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----Country Name (2 letter code) [MX]: State or Province Name (full name) [YUC]: Locality Name (eg, city) [Merida]: Organization Name (eg, company) [GrupoPlenum]: Organizational Unit Name (eg, section) [changeme]:Plenumsoft Common Name (eg, your name or your server's hostname) [changeme]:GrupoPlenumCA Name [changeme]:GrupoPlenumCA Email Address [[email protected]]: Generación del certificado y llaves del servidor [root@ip-172-16-1-193 openvpn]# ./build-key-server server Generating a 1024 bit RSA private key .++++++ ................++++++ writing new private key to 'server.key' ----You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----Country Name (2 letter code) [MX]: State or Province Name (full name) [YUC]: Locality Name (eg, city) [Merida]: Organization Name (eg, company) [GrupoPlenum]: Organizational Unit Name (eg, section) [changeme]:Plenumsoft Common Name (eg, your name or your server's hostname) [server]: Name [changeme]:server Email Address [[email protected]]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:GapugeY3 An optional company name []:Plenumsoft Using configuration from /etc/openvpn/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'MX' stateOrProvinceName :PRINTABLE:'YUC' localityName :PRINTABLE:'Merida' organizationName :PRINTABLE:'GrupoPlenum' organizationalUnitName:PRINTABLE:'Plenumsoft' commonName :PRINTABLE:'server' name :PRINTABLE:'server' emailAddress :IA5STRING:'[email protected]' Certificate is to be certified until Aug 29 23:48:14 2022 GMT (3650 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated Generación de parámetros Diffie Hellman [root@ip-172-16-1-193 openvpn]# ./build-dh Generating DH parameters, 1024 bit long safe prime, generator 2 This is going to take a long time ................................................+............................ ....+...+...............................................................+.... .+...................+.............+......................................... ............................................................................. .......................+...+....+............................................ ..............+.............................................................. ............................................................++*++*++* Generar la llave y certificado para un usuario [root@ip-172-16-1-193 openvpn]# ./build-key rvaldez Generating a 1024 bit RSA private key ...++++++ ..............................++++++ writing new private key to 'rvaldez.key' ----You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----Country Name (2 letter code) [MX]: State or Province Name (full name) [YUC]: Locality Name (eg, city) [Merida]: Organization Name (eg, company) [GrupoPlenum]: Organizational Unit Name (eg, section) [changeme]:Plenumsoft Common Name (eg, your name or your server's hostname) [rvaldez]: Name [changeme]:rvaldez Email Address [[email protected]]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:Phe43fuq An optional company name []: Using configuration from /etc/openvpn/openssl-1.0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'MX' stateOrProvinceName :PRINTABLE:'YUC' localityName :PRINTABLE:'Merida' organizationName :PRINTABLE:'GrupoPlenum' organizationalUnitName:PRINTABLE:'Plenumsoft' commonName :PRINTABLE:'rvaldez' name :PRINTABLE:'rvaldez' emailAddress :IA5STRING:'[email protected]' Certificate is to be certified until Aug 30 00:11:16 2022 GMT (3650 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated Configuración y arranque del servidor Crear un archivo /etc/openvpn/server.conf con las siguientes líneas [root@ip-172-16-1-193 tmp]# cat /etc/openvpn/server.conf port 1194 proto tcp dev tun ca keys/ca.crt cert keys/server.crt key keys/server.key # This file should be kept secret dh keys/dh1024.pem server 192.168.234.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 176.16.1.0 255.255.255.0" push "route 176.16.2.0 255.255.255.0" keepalive 10 120 comp-lzo user nobody group nobody persist-key persist-tun status openvpn-status.log verb 6 Después de configurarlo, ejecutar el OpenVPN en el foreground para observar su comportamiento [root@ip-172-16-1-193 tmp]# openvpn /etc/openvpn/server.conf NOTA: Abrir el puerto TCP/1194 para la conexión de los clientes Configuración del cliente Crear un paquete para transferir al cliente con la llave y certificado del usuario y el certificado del Certification Authority [root@ip-172-16-1-193 keys]# cd /etc/openvpn/keys [root@ip-172-16-1-193 keys]# tar cvf /tmp/client.tar rvaldez.key rvaldez.crt ca.crt rvaldez.key rvaldez.crt ca.crt Transferir el paquete al cliente y crear un archivo de configuración con las siguientes líneas natalie-display:Configurations rvaldez$ cat natware.conf client dev tun proto tcp remote gw.natware.mx 1194 resolv-retry infinite nobind persist-key persist-tun ca canatware.crt cert rvaldez.crt key rvaldez.key ns-cert-type server comp-lzo verb 3 Ruteo en la subred pública Añadir una ruta en la tabla de ruteo de la subred pública. En la imagen es la primera ruta