Configuration réseau de PVE

Il faut désormais configurer le réseau interne du serveur PVE afin que les VM et autres CT que nous allons créer puisse communiquer avec le reste du monde. Pour cela, nous allons utiliser le logiciel FireHol (http://firehol.org/).

FireHol

sudo apt install firehol

Une fois FireHol installé, créer le fichier : /etc/firehol/services/hosts.conf

#FHVER: 1:213

local_network="10.0.0.0/24"
public_ip="10.0.2.15"

vm1_ip="10.0.0.1"
ct1_ip="10.0.0.2"

Ainsi que le fichier : /etc/firehol/services/proxmox.conf

#FHVER: 1:213
server_proxmox_ports="tcp/8006"
client_proxmox_ports="default"

Ensuite, il faut modifier le fichier : /etc/firehol/firehol.conf

# FireHOL configuration file
#
# See firehol.conf(5) manual page and FireHOL Manual for details.
#
# This configuration file will allow all requests originating from the
# local machine to be send through all network interfaces.
#
# No requests are allowed to come from the network. The host will be
# completely stealthed! It will not respond to anything, and it will
# not be pingable, although it will be able to originate anything
# (even pings to other hosts).
#

version 6

# Accept all client traffic on any interface
#interface any world
#    client all accept

# ssh
dnat4 to "${vm1_ip}":22 inface enp0s3 proto tcp dport 10001
dnat4 to "${ct1_ip}":22 inface enp0s3 proto tcp dport 20001

interface4 vmbr0 vmlan src "${local_network}"
    policy accept

#interface4 enp0s3 internet src not "${UNROUTABLE_IPS}" dst "${public_ip}"
interface4 enp0s3 internet src any dst "${public_ip}"
    protection strong
    server "ping ssh http https proxmox" accept
    server ident reject with tcp-reset # Make sure idents do not timeout.
    client all accept

router4 vmlan2internet inface vmbr0 outface enp0s3
    masquerade
    server all accept

router4 internet2vmlan inface enp0s3 outface vmbr0
    server ssh accept dst "${local_network}"

Enfin, il faut modifier une ligne du fichier : /etc/default/firehol

#START_FIREHOL=NO
START_FIREHOL=YES

Tester la configuration avec la commande :

sudo firehol nofast try

Si tout va bien, il ne reste qu'à redémarrer le service :

sudo service firehol restart

Nginx

Pour distribuer des pages web, rien de tel qu'un bon vieux proxy inversé Nginx.

sudo apt install nginx

Il faut désormais éditer le fichier : /etc/nginx/conf.d/proxy.conf

proxy_redirect            off;
proxy_set_header          Host            $host;
proxy_set_header          X-Real-IP       $remote_addr;
proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size      16384m;
client_body_timeout       600s;
client_body_buffer_size   128k;
client_header_buffer_size 64k;
proxy_connect_timeout     90;
proxy_send_timeout        90;
proxy_read_timeout        90;
proxy_buffer_size         16k;
proxy_buffers             32   16k;
proxy_busy_buffers_size   64k;
proxy_max_temp_file_size  16384m;

Renommer la configuration par défaut :

cd /etc/nginx/sites-available/
sudo mv default default.backup

Puis éditer le fichier : /etc/nginx/sites-available/default

# Config serveur vm1.admx.osef
server {
    listen 80 default_server;
    #listen 443 ssl default_server;

    # IPv6 listening
    #listen [::]:80;
    #listen [::]:443 ssl http2;

    server_name vm1.admx.osef vm1;

    #if ($scheme = http) { return 301 https://$server_name$request_uri; }
    #ssl_certificate     /etc/ssl/certs/ssl-cert-snakeoil.pem;
    #ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
    #ssl_protocols TLSv1.2 TLSv1.3;

    access_log /var/log/nginx/vm1.admx.osef-access.log;
    error_log  /var/log/nginx/vm1.admx.osef-error.log;

    location / {
        proxy_pass http://10.0.0.1/;
    }

    location ^~ /.well-known/acme-challenge/ { default_type "text/plain"; root /var/www/certbot/; }
}

Et le fichier : /etc/nginx/sites-available/ct1.admx.osef

# Config serveur ct1.admx.osef
# Config serveur ct1.admx.osef
server {
    listen 80;
    listen 443 ssl;

    # IPv6 listening
    #listen [::]:80;
    #listen [::]:443 ssl http2;

    server_name ct1.admx.osef ct1;

    if ($scheme = http) { return 301 https://$server_name$request_uri; }
    ssl_certificate     /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
    ssl_protocols TLSv1.2 TLSv1.3;

    access_log /var/log/nginx/ct1.admx.osef-access.log;
    error_log  /var/log/nginx/ct1.admx.osef-error.log;

    location / {
        proxy_pass https://10.0.0.2/;
    }

    location ^~ /.well-known/acme-challenge/ { default_type "text/plain"; root /var/www/certbot/; }
}

Le fichier « default » est déjà activé, il faut encore activer le fichier ct1.admx.osef, générer les certificats « snake-oil » puis redémarrer Nginx :

cd /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/ct1.admx.osef
sudo make-ssl-cert generate-default-snakeoil
sudo service nginx restart
# Pour vérifier
sudo service nginx status
# En cas de pépin, pour trouver une explication
sudo journalctl -u nginx

Désormais, vous pouvez créer une VM et un CT pour tester.