Add new file
Showing
1 changed file
with
87 additions
and
0 deletions
etc/cxm/iptables.sh
0 → 100644
| 1 | #!/bin/sh | ||
| 2 | ######################################################### | ||
| 3 | # Création : Sebastien Le Moal <sebastien@calexium.com> | ||
| 4 | # Fonction : Autorisé calexium à se connecter au port 22 et 8006 du serveur proxmox | ||
| 5 | # Rediriger le reste du trafic vers la VM OPNSense | ||
| 6 | # Date : Janvier 2018 | ||
| 7 | ######################################################### | ||
| 8 | # --------- | ||
| 9 | # VARIABLES | ||
| 10 | # --------- | ||
| 11 | |||
| 12 | # Bridge Wan Public | ||
| 13 | ProxIntPubWAN="eth0" ## Proxmox bridge IP Public | ||
| 14 | ProxIpPubWAN="163.172.94.226" ## Proxmox IP Public | ||
| 15 | |||
| 16 | # Bridge Wan OPNSense | ||
| 17 | ProxIntOpnsWAN="vmbr1" ## Proxmox bridge WAN OPNsense | ||
| 18 | NetVmWan="10.10.9.0/24" ## Reseau entre proxmox et OPNsense | ||
| 19 | ProxIpVmWan="10.10.9.1" ## Proxmox IP du Reseau entre proxmox et OPNsense | ||
| 20 | OpnsIPVmWan="10.10.9.2" ## OPNsense wan ip adresse | ||
| 21 | |||
| 22 | # Bridge LAN OPNSense | ||
| 23 | #IntVMLan="vmbr2" ## Proxmox bridge IP Public | ||
| 24 | #NetVmLan="10.10.10.0/24" ## Réseau VMNET | ||
| 25 | |||
| 26 | # --------------------- | ||
| 27 | # Pré config | ||
| 28 | # --------------------- | ||
| 29 | ### Supprime les routes existantes | ||
| 30 | iptables -F | ||
| 31 | iptables -t nat -F | ||
| 32 | iptables -t mangle -F | ||
| 33 | iptables -X | ||
| 34 | |||
| 35 | ### désactiver IPv6 | ||
| 36 | ip6tables -P INPUT DROP | ||
| 37 | ip6tables -P OUTPUT DROP | ||
| 38 | ip6tables -P FORWARD DROP | ||
| 39 | |||
| 40 | ### Bloquer tout | ||
| 41 | iptables -P INPUT DROP | ||
| 42 | iptables -P FORWARD DROP | ||
| 43 | |||
| 44 | ### On crée des chaines personnalisées pour éviter la répétition des options. | ||
| 45 | iptables -N TCP | ||
| 46 | iptables -N UDP | ||
| 47 | iptables -A INPUT -p udp -m conntrack --ctstate NEW -j UDP # UDP = ACCEPT / SEND TO THIS CHAIN | ||
| 48 | iptables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP # TCP = ACCEPT / SEND TO THIS CHAIN | ||
| 49 | |||
| 50 | # ------------ | ||
| 51 | # Regle de base | ||
| 52 | # ------------ | ||
| 53 | iptables -A INPUT -i lo -j ACCEPT # permet les communications from/to de l’interface locale | ||
| 54 | iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # préserve les connections déjà actives | ||
| 55 | iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # préserve les connections déjà actives | ||
| 56 | iptables -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT #autorise la réponse au ping. | ||
| 57 | |||
| 58 | # -------------------- | ||
| 59 | # Regle pour Proxmox bridge IP Public ( ProxIntPubWAN) | ||
| 60 | # -------------------- | ||
| 61 | ### Regle entrante | ||
| 62 | iptables -A TCP -i $ProxIntPubWAN -d $ProxIpPubWAN -p tcp --dport 22 -s 109.190.201.236/32 -j ACCEPT # Accepte acces SSH server venant de calexium Avon | ||
| 63 | iptables -A TCP -i $ProxIntPubWAN -d $ProxIpPubWAN -p tcp --dport 8006 -s 109.190.201.236/32 -j ACCEPT # Accepte acces Proxmox WebUI venant de calexium Avon | ||
| 64 | |||
| 65 | ### Regle de Routage | ||
| 66 | iptables -A FORWARD -i $ProxIntPubWAN -d $OpnsIPVmWan -o $ProxIntOpnsWAN -j ACCEPT # Autoriser le transfert tcp vers l'interface WAN OPNsense | ||
| 67 | iptables -A FORWARD -i $ProxIntOpnsWAN -s $NetVmWan -j ACCEPT # Autoriser le transfert de requête à partir du réseau local | ||
| 68 | |||
| 69 | ### Natter le trafic sortant versInternet (SNAT) | ||
| 70 | iptables -A POSTROUTING -t nat -s $ProxIpVmWan -j SNAT --to-source $ProxIpPubWAN | ||
| 71 | iptables -A POSTROUTING -t nat -s $OpnsIPVmWan -j SNAT --to-source $ProxIpPubWAN | ||
| 72 | |||
| 73 | ### Rediriger le trafic venant d'Internet (NAT) | ||
| 74 | iptables -A PREROUTING -t nat -i $ProxIntPubWAN -d $ProxIpPubWAN -p tcp --match multiport ! --dports 22,8006 -j DNAT --to $OpnsIPVmWan # tout tcp vers WAN OPNsense WAN sauf le 22 et 8006 | ||
| 75 | |||
| 76 | |||
| 77 | # ---------------------- | ||
| 78 | # Regles pour bridge WAN OPNsense (PrxVmWanVBR) | ||
| 79 | # ---------------------- | ||
| 80 | ### Regle entrante | ||
| 81 | iptables -A TCP -i $ProxIntOpnsWAN -d $ProxIpVmWan -p tcp --dport 22 -s 109.190.201.236/32 -j ACCEPT # Accepte acces SSH server venant de calexium Avon | ||
| 82 | iptables -A TCP -i $ProxIntOpnsWAN -d $ProxIpVmWan -p tcp --dport 8006 -s 109.190.201.236/32 -j ACCEPT # Accepte acces Proxmox WebUI venant de calexium Avon | ||
| 83 | |||
| 84 | # ----------------------- | ||
| 85 | # Regle pour Proxmox bridge LAN VM (PrxVmPrivVBR) | ||
| 86 | # ----------------------- | ||
| 87 | # NO RULES => Tout est bloqué !!! | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment