• Etablir une connexion PPPoE, transformer OmniOSce en routeur (NAT, DNAT, DHCP)

     For English version, please go down...

     

    Tout d'abord, je tiens à remercier chaleureusement 'jperkin' pour son tutoriel sur ce sujet (https://gist.github.com/jperkin/7717d3e84e93885ab14da3bce3039f4b), qui m'a mis sur voix ainsi que 'hadfl" sur le canal IRC d'omnios pour m'en avoir donné le lien !
    Enfin, un merci à l'équipe d'OmniOSce pour les rappels de règles de pare-feu pour IPF (https://omnios.org/info/ipfilter)

    Le but ici est de transformer un serveur OmniOSce en routeur/pare-feu placé directement en frontal sur internet.
    Ce n'est pas une pratique très commune je crois, mais pourquoi pas essayer.
    Nous aurons pour cela besoin de configurer une connexion PPPoE, de configurer le pare-feu IPFilter et de mettre en place un serveur DHCP pour d'éventuels ordinateurs clients dans le LAN.

    Nous configurerons également un DNAT (port forwarding) pour pouvoir joindre un serveur web dans le LAN depuis internet (pour l'exemple car je dois dire que j'en ai bien bavé sur ce point)

    Le routeur possède donc a minima 2 interfaces réseau, une pour le WAN, une autre pour notre réseau local LAN.

    L'installation doit être faîte en 2 étapes si vous êtes en physique :
    - 1ère étape: faire l'installation d'OmniOSce en permettant au serveur d'avoir accès à internet pour faire les éventuelles mises-à-jour, configurer ntp et installer ppp et ppp/tunnel.
    - 2nde étape: Placer le serveur à son endroit définitf/ou simplement faire les branchements définitifs (s'il est dans une baie) et le brancher au câble internet relié à votre modem, boîtier ONT/fibre.... Une fois branché et allumé, on peut effectuer la configuration PPPoE (et parfois batailler un moment !).

    Vous devez être root tout au long du processus de configuration.

    ETAPE 1 :

    - Faire l'installation d'omniosce (choisissez BASH lorsque vous créez votre utilisateur administrateur - ou autre si vous êtes plus à l'aise, je vais rester simple ici)
    - Allumez le serveur, identifiez-vous en root et faîtes les éventuelles mises-à-jour de l'image système lors du premier démarrage :

    pkg refresh --full ; pkg update && reboot

    - Si vous utilisez un fuseau horaire différent du standard, vous devez impérativement configurer ntp pour récupérer la bonne heure :
    (ici un exemple pour le fuseau horaire Français) :

    pkg install ntpsec && /usr/bin/ntpdate 0.fr.pool.ntp.org && date && svcadm enable svc:/network/ntp:default

    - Installer ppp et ppp/tunnel

    pkg install pkg:/system/network/ppp pkg:/system/network/ppp/tunnel

    - Avant d'éteindre votre serveur, vous devez être certain du nom de l'interface qui sera reliée à internet.
    Regardez votre configuration IP actuelle :

    ipadm

    Regardez les interfaces réseau réelles pour voir les autres interfaces non utilisées

    dladm show-phys

    - Eteignez votre serveur.

     

    ETAPE 2 :

    - Vous avez à présent placé votre routeur à son emplacement définitif et l'avez branché au câble internet relié à votre modem/boîtier ONT/fibre...). (Et si vous n'avez pas de baie, vous êtes malins, vous avez également prévu l'écran et le clavier pour poursuivre la configuration ! :-D).

    - Allumez votre serveur, identifiez-vous en root.

    - Récupérez le nom de l'interface réseau que vous avez directement branchée à internet (pas la LAN !)

    dladm show-phys

    (prenons par exemple "rge0")

    - Nous devons "plumber" cette interface avec l'interface virtuelle "sppptun".
    Dans mon cas, et c'est là que ce tuto diffère un peu de celui de jperkin, créer le fichier /etc/ppp/pppoe.if en mettant le nom de l'interface dedans n'a pas fonctionné).

    sppptun plumb pppoed rge0
    sppptun plumb pppoe rge0

    - Vous pouvez vérifier à tout moment si vos interfaces sont bien "plumbées" :

    sppptun query

    - Configuration des identifiants CHAP :
    (remplacer par vos identifiants ISP réels puis copier/coller le bloc)

    cat <<EOL > /etc/ppp/chap-secrets
    # Secrets for authentication using CHAP
    # client    server      secret      IP addresses
    "YOUR-ISP-USER" * "ASSOCIATED-PASSWORD" *
    EOL

    - Créer le script pour démarrer la connexion PPPoE :
    (Remplacer par votre nom d'utilisateur ISP - pas le mot de passe, qui lui, sera automatiquement lu dans chap-secrets - copier/coller le bloc ci-dessous pour créer le fichier de configuration)

    cat <<EOL > /etc/ppp/peers/myisp
    # Configuration PPPoE
    sppptun
    plugin "/usr/lib/inet/ppp/pppoe.so"
    connect "/usr/lib/inet/pppoec -v rg0" user "YOUR-ISP-USER" defaultroute noipdefault usepeerdns persist noauth
    #debug
    #logfile "/var/log/pppd.log" EOL

    J'ai laissé les lignes debug et logfile commentées, mais si ça ne fonctionne pas ensuite, il faudra les décommenter pour pouvoir aller voir ce qui se passe dans les logs.

    - Créer le fichier /etc/ppp/options pour pouvoir ensuite démarrer la connexion avec un utilisateur moins privilégié (autre root) :
    (inutile de remplir quoique ce soit d'autre dedans que ce qui s'y trouve déjà... le fichier options doit simplement exister.. on fait donc une simple copie en le renommant)

    cp /etc/ppp/options.tmpl /etc/ppp/options

    Vous pouvez à présent quitter root et redevenir un utilisateur administrateur standard pour démarrer la connexion

    - Lancer la connexion :

    pppd call myisp

    - Vérifier la connexion :

    ifconfig spppO

    or

    ipadm

    Vous devriez voir l'interface sppp0 apparaître et configurée avec votre adresse IP publique récupérée automatiquement.

    Regardez également dans le fichier de log /var/log/pppd.log si jamais vous aviez décommenté #debug et #logfile pour voir comment tout cela se passe.

    - Tester votre connexion à internet :

    ping 1.1.1.1

     


    A partir de maintenant, je considère que vous êtes connectés à internet depuis le serveur
    On va donc vite mettre en place le pare-feu, le NAT, le DNAT et le serveur DHCP pour les clients du LAN.

     

     

    - Configurer l'interface réseau du LAN (si vous ne l'avez pas déjà fait)
    rge0 est l'interface du WAN (pour rappel)
    rge1 est l'interface du LAN
    La passerelle de mon réseau local LAN relié à l'interface "rge1" aura pour IP : 10.10.10.1/24

    ipadm delete-ip rge1
    ipadm create-ip rge1
    ipadm create-addr -T static -a local=10.10.10.1/24 rge1/v4

     

    - Configurer le NAT avec IPFilter
    Mon adresse IP publique, liée à l'interface "sppp0" a pour IP : 45.56.67.78 (exemple bidon).
    Voici la configuration du fichier /etc/ipf/ipnat.conf

    # NAT for LAN
    map sppp0 10.10.10.0/24 -> 0.0.0.0/32

    # DNAT for a web server :
    rdr sppp0 45.56.67.78 port 443 -> 10.10.10.210 port 443

    - Configurer le pare-feu IPFilter :
    Voici la configuration du fichier /etc/ipf/ipf.conf :
    Ici le but est :
    --- d'autoriser le trafic depuis LAN vers internet en stateful
    --- d'autoriser les connexions entrantes en stateful vers le serveur web,
    --- de bloquer tout le reste
    --- ATTENTION, il y a une règle qui peut bloquer l'attribution automatique de l'adresse IP publique par votre FAI.
    Vous devrez peut-être l'adapter.

    # Block packets from non-routable or reserved address spaces
    block in quick on sppp0 from 192.168.0.0/16 to any # RFC 1918 private IP
    block in quick on sppp0 from 172.16.0.0/12 to any # RFC 1918 private IP
    block in quick on sppp0 from 10.0.0.0/8 to any # RFC 1918 private IP
    block in quick on sppp0 from 127.0.0.0/8 to any # loopback
    block in quick on sppp0 from 0.0.0.0/8 to any # loopback
    block in quick on sppp0 from 169.254.0.0/16 to any # DHCP auto-config
    block in quick on sppp0 from 192.0.2.0/24 to any # reserved for docs
    block in quick on sppp0 from 204.152.64.0/23 to any # Sun cluster interconnect
    block in quick on sppp0 from 224.0.0.0/3 to any # Class D & E multicast

    # Block fragments and too short TCP packets
    block in quick on sppp0 all with frags
    block in quick on sppp0 proto tcp all with short

    # Block source routed packets
    block in quick on sppp0 all with opt lsrr
    block in quick on sppp0 all with opt ssrr

    # Block OS fingerprint attempts and log first occurrence
    block in log first quick on sppp0 proto tcp from any to any flags FUP

    # Block anything with special options
    block in quick on sppp0 all with ipopts

    # Block public pings and ident
    block in quick on sppp0 proto icmp all icmp-type 8
    block in quick on sppp0 proto tcp from any to any port = 113

    # Allow on loopback
    pass in quick on lo0 all
    pass out quick on lo0 all

    # Allow DHCP traffic on the LAN (rge1)
    pass in quick on rge1 proto udp from any port = 68 to any port = 67
    pass out quick on rge1 proto udp from any port = 67 to any port = 68

    # Allow all stateful traffic from LAN to INTERNET
    pass in quick on rge1 all keep state
    pass out quick on sppp0 all keep state

    # Allow DNAT traffic to SFTP server
    pass in quick on sppp0 proto tcp from any to 10.10.10.210 port = 443 keep state

    # Block any connection from the WAN to this server
    block in quick on sppp0 all

    - Démarrer IPF, charger les règles de pare-feu ainsi que les règles de NAT/DNAT

    svcadm enable svc:/network/ipfilter:default
    ipf -Fa -f /etc/ipf/ipf.conf
    ipnat -CF -f /etc/ipf/ipnat.conf

    - Activer l'IPv4-forwarding
    (je ne m'occupe que d'IPv4 comme vous pouvez le constater.. mais libre à vous d'ajouter l'IPv6)

    svcadm enable ipv4-forwarding

    - Configurer le service DHCP :

    pkg install pkg:/network/service/isc-dhcp

    - Indiquez la configuration : /etc/dhcpd.conf :

    subnet 10.10.10.0 netmask 255.255.255.0 {    
    option domain-name-servers 1.1.1.1;
    option routers 10.10.10.1;
    authoritative;
    range 10.10.10.2 10.10.10.200;
    }

    - Démarrer le serveur dhcp :

    /usr/sbin/dhcpd


    A présent vos clients recevront une configuration IP via DHCP et accèderont automatiquement à internet.

     

     

    -----------------------------------------------------------------------------------------------------------------------------------------------------

     

    First of all, I would like to warmly thank 'jperkin' for his tutorial on this subject howto which set me on the right path, as well as 'hadfl' on the OmniOS IRC channel for providing the link!
    Finally, thanks to the OmniOSce team for the firewall rule reminders for IPF OmniOSce-IPF

    The goal here is to turn an OmniOSce server into a router/firewall placed directly in front of the internet. This is not a very common practice, I believe, but why not give it a try.
    For this, we will need to configure a PPPoE connection, configure the IPFilter firewall, and set up a DHCP server for potential client computers in the LAN.
    We will also configure a DNAT (port forwarding) to be able to access a web server in the LAN from the internet.

    The router thus has at least 2 network interfaces, one for the WAN and another for our local LAN network.

    The installation must be done in 2 steps if you are on physical hardware:
    - First step: Install OmniOSce, allowing the server to access the internet for potential updates, configure NTP, and install ppp and ppp/tunnel.
    - Second step: Place the server in its final location or simply make the final connections (if it is in a rack) and connect it to the internet cable linked to your modem/ONT/fiber box etc.
    Once connected and powered on, you can configure PPPoE.

    You must be root throughout the entire configuration process.

    STEP 1:
    - Install OmniOSce (choose BASH when creating your admin user - or another shell if you are more comfortable, I'll keep it simple here)
    - Power on the server, log in as root, and perform any necessary system image updates on the first boot:
    pkg refresh --full ; pkg update && reboot
    - If you are using a time zone different from the standard, you must configure NTP to retrieve the correct time: (here is an example for the French time zone):
    pkg install ntpsec && /usr/bin/ntpdate 0.fr.pool.ntp.org && date && svcadm enable svc:/network/ntp:default
    - Install ppp and ppp/tunnel :
    pkg install pkg:/system/network/ppp pkg:/system/network/ppp/tunnel
    - Before shutting down your server, you must be certain of the name of the interface that will be connected to the internet.
    - Check your current IP configuration:
    ipadm
    - Look at the actual network interfaces to see other unused interfaces:
    dladm show-phys
    - Shut down your server.

    STEP 2:
    - You have now placed your router in its final location and connected it to the internet cable linked to your modem/ONT/fiber box...). (And if you don't have a rack, you are clever, you have also arranged for the screen and keyboard to continue the configuration! :-D).
    - Power on your server, log in as root.
    - Retrieve the name of the network interface that you have directly connected to the internet (not the LAN!)
    dladm show-phys
    (let's take "rge0" as an example)
    - We need to "plumb" this interface with the virtual "sppptun" interface.
    In my case, and this is where this tutorial differs slightly from jperkin's, creating the file /etc/ppp/pppoe.if with the interface name inside did not work).
    sppptun plumb pppoed rge0
    sppptun plumb pppoe rge0
    - You can check at any time if your interfaces are properly "plumbed":
    sppptun query
    - Configuration of CHAP credentials:
    (replace with your actual ISP credentials then copy/paste the block)

    cat <<EOL > /etc/ppp/chap-secrets
    # Secrets for authentication using CHAP
    # client server secret IP addresses
    "YOUR-ISP-USER" * "ASSOCIATED-PASSWORD" *
    EOL

    - Create the script to start the PPPoE connection:
    (Replace with your ISP username - not the password, which will be automatically read from chap-secrets
    - copy/paste the block below to create the configuration file)

    cat <<EOL > /etc/ppp/peers/myisp
    # PPPoE Configuration
    sppptun
    plugin "/usr/lib/inet/ppp/pppoe.so"
    connect "/usr/lib/inet/pppoec -v rg0"
    user "YOUR-ISP-USER"
    defaultroute
    noipdefault
    usepeerdns
    persist
    noauth
    #debug
    #logfile "/var/log/pppd.log"
    EOL

    I left the debug and logfile lines commented out, but if it doesn't work later, you will need to uncomment them to see what is happening in the logs.

    Create the file /etc/ppp/options to be able to start the connection with a less privileged user (other than root):
    (no need to fill in anything else inside other than what is already there... the options file just needs to exist... so we simply make a copy and rename it)
    cp /etc/ppp/options.tmpl /etc/ppp/options

    You can now exit root and become a standard admin user to start the connection.
    - Start the connection:
    pppd call myisp
    - Check the connection:
    ifconfig spppO

    You should see the sppp0 interface appear and configured with your automatically retrieved public IP address.

    Also, check the /var/log/pppd.log file if you had uncommented #debug and #logfile to see how everything is going.
    - Test your internet connection:
    ping 1.1.1.1

    From now on, I assume you are connected to the internet from the server.
    So we will quickly set up the firewall, NAT, DNAT, and DHCP server for the LAN clients.
    - Configure the LAN network interface (if you haven't already done so).
    rge0 is the WAN interface (as a reminder).
    rge1 is the LAN gateway and will have IP 10.10.10.1/24
    ipadm delete-ip rge1
    ipadm create-ip rge1
    ipadm create-addr -T static -a local=10.10.10.1/24 rge1/v4
    - Configure NAT with IPFilter.
    My public IP address on the "sppp0" interface is : 45.56.67.78.
    Here is the configuration of the /etc/ipf/ipnat.conf file:

    # NAT for LAN
    map sppp0 10.10.10.0/24 -> 0.0.0.0/32
    
    # DNAT for a web server:
    rdr sppp0 45.56.67.78 port 443 -> 10.10.10.210 port 443

    - Configure the IPFilter firewall:
    Here is the configuration of the /etc/ipf/ipf.conf file:
    The goal here is:
    --- to allow traffic from LAN to the internet statefully,
    --- to allow incoming connections statefully to the web server,
    --- to block everything else.
    --- CAUTION, there is a rule that may block the automatic assignment of the public IP address by your ISP. You may need to adapt it.

    # Block packets from non-routable or reserved address spaces
    block in quick on sppp0 from 192.168.0.0/16 to any      # RFC 1918 private IP
    block in quick on sppp0 from 172.16.0.0/12 to any       # RFC 1918 private IP
    block in quick on sppp0 from 10.0.0.0/8 to any          # RFC 1918 private IP
    block in quick on sppp0 from 127.0.0.0/8 to any         # loopback
    block in quick on sppp0 from 0.0.0.0/8 to any           # loopback
    block in quick on sppp0 from 169.254.0.0/16 to any      # DHCP auto-config
    block in quick on sppp0 from 192.0.2.0/24 to any        # reserved for docs
    block in quick on sppp0 from 204.152.64.0/23 to any     # Sun cluster interconnect
    block in quick on sppp0 from 224.0.0.0/3 to any         # Class D & E multicast
    
    # Block fragments and too short TCP packets
    block in quick on sppp0 all with frags
    block in quick on sppp0 proto tcp all with short
    
    # Block source routed packets
    block in quick on sppp0 all with opt lsrr
    block in quick on sppp0 all with opt ssrr
    
    # Block OS fingerprint attempts and log first occurrence
    block in log first quick on sppp0 proto tcp from any to any flags FUP
    
    # Block anything with special options
    block in quick on sppp0 all with ipopts
    
    # Block public pings and ident
    block in quick on sppp0 proto icmp all icmp-type 8
    block in quick on sppp0 proto tcp from any to any port = 113
    
    # Allow on loopback
    pass in quick on lo0 all
    pass out quick on lo0 all
    
    # Allow DHCP traffic on the LAN (rge1)
    pass in quick on rge1 proto udp from any port = 68 to any port = 67
    pass out quick on rge1 proto udp from any port = 67 to any port = 68
    
    # Allow all stateful traffic from LAN to INTERNET
    pass in quick on rge1 all keep state
    pass out quick on sppp0 all keep state
    
    # Allow DNAT traffic to SFTP server
    pass in quick on sppp0 proto tcp from any to 10.10.10.210 port = 443 keep state 
    
    # Block any connection from the WAN to this server
    block in quick on sppp0 all

    - Start IPF, load the firewall rules as well as the NAT/DNAT rules
    svcadm enable svc:/network/ipfilter:default
    ipf -Fa -f /etc/ipf/ipf.conf
    ipnat -CF -f /etc/ipf/ipnat.conf
    - Enable IPv4 forwarding
    (I am only dealing with IPv4 here as you can see... but feel free to add IPv6)
    svcadm enable ipv4-forwarding
    - Configure the DHCP service:
    pkg install pkg:/network/service/isc-dhcp
    - Specify the configuration: /etc/dhcpd.conf:

    subnet 10.10.10.0 netmask 255.255.255.0 {
    option domain-name-servers 1.1.1.1;
    option routers 10.10.10.1;
    authoritative;
    range 10.10.10.2 10.10.10.200;
    }

    - Start the DHCP server:
    /usr/sbin/dhcpd

    Now your clients will receive an IP configuration via DHCP and will automatically access the internet.

     


    Tags Tags : , , , , , ,
  • Commentaires

    Aucun commentaire pour le moment

    Suivre le flux RSS des commentaires


    Ajouter un commentaire

    Nom / Pseudo :

    E-mail (facultatif) :

    Site Web (facultatif) :

    Commentaire :