Apuntes Opnsense
En la categoria Apuntes Voy a poner apubtes y notas de los proyectos que tengo en marcha.
No son articulos conpletos. Pero te pueden ayudar a resolver dudas y problemas y tener referencias.
opnsense y pfsense son distribuciones BSD con caracteristicas avanzadas de cortafuegos y gestion de redes.
Vamos a instalar esta distribucion en una VPS para probar que posibilidades tiene.
Con ella veremos como configurar y gestionar una VPN para teletrabajo y acceso remoto.
Es lo que en terminos informaticos se conoce como una VPN modo Road Warrior.
La diferencia de la VPN que solemos conocer. es que estas vpn a parte de asegurar las comunicaciones (añadiendo una capa cryptofrafica adicional)
Nos permiten comunicar unos equipos con otros aunque esten en redes distintas.
Ej: desde el movil podria acceder de forma segura a los archivos y al escritorio del ordenador de la oficina.
Necesitaras.
- Una vps o maquina virtual con al menos 1Gb de RAM
- Dicha VPS necesitara poder arrancar desde un CD o una imagen .iso de opnsense.
- Es bueno que tu VPS tenga acceso a consola auxiliar ya que si pierdes el control de la maquina tendrias que rehacerla desde cero.
Conocimientos Minimos.
- Pequeña gestion de Maquinas Virtuales / Servidores Privados Virtuales (VPS)
- Conocer la gescion/configuracion del arranque de la maquina. (saber cuando arranca desde disco duro y cuando desde un CDROM o imagen .ISO )
La primera vez que enciendes la VPS con la secuencia de arranque desde el CD
(si la maquina esta vacia. (sin nada en el disco duro) puedes dejar la secuencia de arranque 1)HardDisk => 2)CDrom
Instalacion:
jejo@mipc:~$ ssh installer@1.2.3.4 Password for installer@OPNsense.localdomain:opnsense
Donde 1.2.3.4 es la ip de tu maquina. y el password seria opensense.
┌────────────┤ OPNsense 19.1 ├─────────────┐ │ │ │ Welcome to the OPNsense 19.1 installer! │ │ │ │ Before we begin, you will be asked a │ │ few questions so that this installation │ │ environment can be set up to suit your │ │ needs. │ │ │ │ You will then be presented a menu of │ │ items from which you may select to │ │ install a new system, with or without │ │ importing a previous configuration. │ │ │ │ < Ok, let's go. > │ └──────────────────────────────────────────┘ Set up the installation environment and continue
F10=Refresh Display ┌─────────┤ Configure Console ├─────────┐ │ │ │ Your selected environment uses the │ │ following console settings, shown in │ │ parentheses. Select any that you wish │ │ to change. │ │ │ │ < Accept these Settings > │ │ < Change Keymap (default) > │ │ < Change Video Font (default) > │ └───────────────────────────────────────┘
┌───────────┤ Select Task ├────────────┐ │ │ │ Choose one of the following tasks to │ │ perform. │ │ │ │ < Guided installation > │ │ < Manual installation > │ │ < Import configuration > │ │ < Reset password > │ │ < Reboot > │ │ < Exit > │ └──────────────────────────────────────┘ Invoke Installer with minimal questions
┌───────────────┤ Select a Disk ├──────────── │ This will automatically install OPNsense │ with all current settings without asking │ many questions. │ WARNING: All contents of the selected │ hard disk will be erased! This action is │ irreversible. │ Please select a disk to continue: │ < ada0: 10240MB (20971520 512 byte sectors) │ < Return to Select Task > └────────────────────────────────────────────
┌────────┤ Select install mode ├───────── │ │ Select the installation mode: GPT/UEFI │ is the recommended option. MBR is │ provided for compatibilty with older │ hardware. │ │ < GPT/UEFI mode > │ < MBR mode > │ < Return to Select Disk > └────────────────────────────────────────
@@@@@@@@@@ ┌────────────┤ Set Root Password ├────────────┐@@@@@ │ │ │ Please set your super-user (root) │@@@ │ password, or leave empty to keep the │@@@@@ │ current one. │\\\\\ │ │))))) │ Root Password [*********** ] │///// │ Re-type Root Password [*********** ] │@@@@@ │ │@@@ │ < Accept and Set Password > │ └─────────────────────────────────────────────┘@@@@@ @@@@@@@@@@
@@@@@@@@@@ @@@@@@@@@@@ ┌───────────────┤ Reboot ├───────────────┐@ │ │@@@@@ │ This machine is about to be shut down. │@@@@@@@ │ After the machine has reached its │ \\\\\ │ shutdown state, you may remove the CD │))))))) │ from the CD-ROM drive tray and press │ ///// │ Enter to reboot from the HDD. │@@@@@@@ │ │@@@@@ │ < Reboot > < Return to Select Task > │@ └────────────────────────────────────────┘@@@@@@@ @@@@@@@@@@
No olvides desactivar el Arranque desde el CD.
Una vez Reiniciado
Pequeñas optimizaciones
- ### Añadir SWAP
- System => Settings => Miscelaneus > marcar:
Swap file Add a 2 GB swap file to the system - Reiniciar ( Power => reboot => Yes)
- System => Settings => Miscelaneus > marcar:
Monitoreo (estadisticas)
Reportin => NetFlow Habilitar , Marcar Listen Interfaces (WAN y VPN) Marcar Local (si no no salen las graficas en Insight) Apply
Reporting => Insight
- ### Instalar mc Listado paquetes Freebsd: http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/
pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/libslang2-2.3.2_1.txz pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/png-1.6.37.txz pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/libssh-0.9.2.txz pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/libssh2-1.8.2,3.txz pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/mc-nox11-4.8.23.txz
- ### Instalar Htop Listado paquetes Freebsd: http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/
pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/lsof-4.93.2_5,8.txz pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/htop-2.2.0_1.txz
Habilitar ssh (solo desde VPN)
- System => Settings => Administration
Secure Shell
Marcar: Enable Secure Shell Listen Interfaces Seleccionar: VPN __________
- System => Settings => Administration
Secure Shell
Comprobar la seguridad (Auditoria Interna)
- System => Firmware Boton Audit Now
- ### Comprobar la integridad del sistema
- System => Firmware Boton Audit Now =>desplegar (triangulito) Health
- ## Firewall https://docs.opnsense.org/firewall.html
- ### Desabilitar ipv6 No hay manera de que la ip fe80::a236:9fff:fe30:bde4 No pare de escanearme. Asi que de momento he tenido que desabilitar IPv6 https://www.thomas-krenn.com/en/wiki/OPNsense_disable_IPv6
- ### Firewall editar listas de ips (Aliases)
- Firewall => Diagnostics => Pftables Recuerda el orden de las reglas del cortafuegos es: Definidas por el sistema > Floating Rules > Interface Groups > Interface https://docs.opnsense.org/manual/aliases.html https://docs.opnsense.org/manual/firewall.html
- ### Editar bogonsv6 para bloquear una ipv6 https://bash.cyberciti.biz/firewall/pf-ipv6-ipv4-firewall-for-freebsd-openbsd-netbsd/
root@OPNsense:~ # find / -name "bogon*" /usr/local/etc/bogons /usr/local/etc/bogonsv6 /usr/local/etc/bogonsv6.sample /usr/local/etc/bogons.sample /tmp/bogons /tmp/bogons/bogons.txz.sig /tmp/bogons/bogons.txz
Nota ** No funciona**
pf ver reglas cortafuegos (packet filter )
https://man.openbsd.org/pfctl
https://www.openbsd.org/faq/pf/ https://www.cyberciti.biz/faq/howto-pf-firewall-list-firewall-rules/firewall state table:
pfctl -ss
filter stats and counters:
pfctl -si
current firewall rules
pfctl -sr
Mostrar todo
pfctl -sa
otros comandos
pfctl -sr
/pfctl -s rules
/pfctl -a '*' -sr
pfctl -s info
https://docs.opnsense.org/firewall.html
- ### Comprobar estadisticas interaces
- Firewall => Diagnostics => Interfaces
- ### Reverse proxy / Servidor web /Balanceador de carga.
https://docs.opnsense.org/manual/reverse_proxy.html
Restaura a una configuracion anterior
Restauracion de emergencia.
Cuando el sistema no arranca. Arrancar en modo Single User (pulsando 2 o S en la pantalla de inicio nada mas reiniciar)
Si pide patch para shell /bin/sh
cd conf cd backup ls -lha mount -o wr / cp config-15.....xml ../config.xml reboot
Nota: es bueno tener una copia operativa del archivo config.xml
ej `cp config.xml confix.xml.ok
Referencias
https://docs.opnsense.org/manual/
https://docs.opnsense.org/manual/virtuals.html
https://docs.opnsense.org/manual/how-tos/sslvpn_client.html
https://www.tecmint.com/install-and-configure-opnsense-firewall/
https://www.mmonit.com/monit/documentation/monit.html#ACTION
A estudiar
https://www.mmonit.com/monit/documentation/monit.html#ACTION https://www.secfu.net/2017/04/16/opnsense-as-an-ipv6-firewall-testing-ipv6-security-devices-part-1/ https://openschoolsolutions.org/tag/pfsense/
Paginas con articulos OPNSense
https://homenetworkguy.com/tags/opnsense/
Instalar paquetes (ej mc)
http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/ pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/mc-4.8.23.txz