Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 07/09/2008, à 15:33

Nathanos

Partage de connexion WIFI vers 2e pc

Bonjour.

Alors, vala mon soucis : à ma fac je reçois sur mon portable une connexion Wifi crypté en LEAP que j'aimerais bien envoyé sur un autre ordi via ma carte ethernet.

J'ai donc configuré les ordi comme suit :

Portable : eth1 (Ethernet)
IP : 192.168.10.1
Masque : 255.255.255.0

PC fixe : eth0 (ethernet)
IP : 192.168.10.110
Masque : 255.255.255.0
Passerelle : 192.168.10.1

Les deux réseaux se voient, je peux sans aucun soucis lire la musique présente sur le disque dur du fixe sur le portable, via samba, sauf que voilà, niveau internet, nada : mon ami l'ordi fixe n'a pas le net.

J'ai essayé via Firestarter : résultat, nada. Marche pas.
J'ai essayé via le tuto d'Ubuntu-Fr : nada. Marche pas.

Je commence un peu à désespérer là, semblerait que IPTable refuse de partager la connexion.

J'ai également fait la partie "Option, configurer le par feu", avec comme indications dans Firestarter : interface de connexion eth1 et interface locale eth0.



Quelqu'un a une idée de comment résoudre le soucis ?

Hors ligne

#2 Le 07/09/2008, à 15:50

#Ergo-Proxy

Re : Partage de connexion WIFI vers 2e pc

hello

une idée.?

l'ip masquerade et nat.

# activation du forwarding dans le noyau
# mise en place du partage de connexion sur le réseau local

echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o $interface -j MASQUERADE

#3 Le 07/09/2008, à 15:54

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Mmm...


C'est à dire ?

Dernière modification par Nathanos (Le 07/09/2008, à 15:55)

Hors ligne

#4 Le 07/09/2008, à 15:59

Nathanos

Re : Partage de connexion WIFI vers 2e pc

On est d'accord, mais dans la mesure où eth1 est défini en haut du script (interface=eth1), la commande devrait être bonne.

'Fin, j'ai mis eth1, à la place de $interface, j'vais reboot un peu tous les pc voir si ça marche mieux.

Hors ligne

#5 Le 07/09/2008, à 16:10

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Nan, je crois pas, iptable doit se lancer au démarrage normalement, suite à la commande "sudo update-rc.d iptables start 99 2 . stop 00 2 0 1 6 ." du tuto.


Sinon, pour ce que tu demandes :

ifconfig : eth0      Link encap:Ethernet  HWaddr 00:c0:9f:85:5b:ef 
          inet adr:192.168.10.1  Bcast:192.168.10.255  Masque:255.255.255.0
          adr inet6: fe80::2c0:9fff:fe85:5bef/64 Scope:Lien
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Packets reçus:73 erreurs:0 :0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:1000
          Octets reçus:8977 (8.7 KB) Octets transmis:6751 (6.5 KB)
          Interruption:6

eth1      Link encap:Ethernet  HWaddr 00:0e:35:4a:65:ea 
          inet adr:172.24.2.113  Bcast:172.24.255.255  Masque:255.255.0.0
          adr inet6: fe80::20e:35ff:fe4a:65ea/64 Scope:Lien
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Packets reçus:1418 erreurs:0 :22 overruns:0 frame:0
          TX packets:809 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:1000
          Octets reçus:739305 (721.9 KB) Octets transmis:105945 (103.4 KB)
          Interruption:10 Mémoire:e0208000-e0208fff

iwconfig : eth0      no wireless extensions.

eth1      IEEE 802.11g  ESSID:"INVITES-WIFI" 
          Mode:Managed  Frequency:2.462 GHz  Access Point: 00:0E:83:D6:14:B0   
          Bit Rate:54 Mb/s   Tx-Power=20 dBm   Sensitivity=8/0 
          Retry limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=77/100  Signal level=-52 dBm  Noise level=-82 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:22   Missed beacon:0

sudo lshw -C network :
  *-network:0             
       description: Ethernet interface
       product: BCM4401 100Base-T
       vendor: Broadcom Corporation
       physical id: 2
       bus info: pci@0000:02:02.0
       logical name: eth0
       version: 01
       serial: 00:c0:9f:85:5b:ef
       size: 100MB/s
       capacity: 100MB/s
       width: 32 bits
       clock: 33MHz
       capabilities: pm bus_master cap_list ethernet physical mii 10bt 10bt-fd 100bt 100bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=b44 driverversion=2.0 duplex=full ip=192.168.10.1 latency=64 link=yes module=ssb multicast=yes port=twisted pair speed=100MB/s
  *-network:1
       description: Wireless interface
       product: PRO/Wireless 2200BG Network Connection
       vendor: Intel Corporation
       physical id: 4
       bus info: pci@0000:02:04.0
       logical name: eth1
       version: 05
       serial: 00:0e:35:4a:65:ea
       width: 32 bits
       clock: 33MHz
       capabilities: pm bus_master cap_list ethernet physical wireless
       configuration: broadcast=yes driver=ipw2200 driverversion=1.2.2kmprq firmware=ABG:9.0.2.6 (Mar 22 2005) ip=172.24.2.113 latency=64 link=yes maxlatency=24 mingnt=3 module=ipw2200 multicast=yes wireless=IEEE 802.11g

nathan@tsubomi:~$ route -n
Table de routage IP du noyau
Destination     Passerelle      Genmask         Indic Metric Ref    Use Iface
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.24.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
0.0.0.0         172.24.21.88    0.0.0.0         UG    0      0        0 eth1

nathan@tsubomi:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback


iface eth0 inet static
address 192.168.10.1
netmask 255.255.255.0

auto eth0

nathan@tsubomi:~$ cat /etc/resolv.conf
### BEGIN INFO
#
# Modified_by:  NetworkManager
# Process:      /usr/bin/NetworkManager
# Process_id:   5232
#
### END INFO

search univ-corse.fr


nameserver 127.0.0.1
nameserver 193.48.28.200

nathan@tsubomi:~$ cat /etc/hosts
127.0.0.1    localhost
127.0.1.1    tsubomi
192.168.10.1    serveurICS

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

nathan@tsubomi:~$ sudo iptables -L -vv
Chain INPUT (policy DROP 3 packets, 663 bytes)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  any    any     localhost            anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN
   36  5079 ACCEPT     udp  --  any    any     localhost            anywhere           
    0     0 ACCEPT     tcp  --  any    any     lotus.univ-corse.fr  anywhere            tcp flags:!FIN,SYN,RST,ACK/SYN
   16  3668 ACCEPT     udp  --  any    any     lotus.univ-corse.fr  anywhere           
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere           
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            limit: avg 10/sec burst 5
    0     0 DROP       all  --  any    any     BASE-ADDRESS.MCAST.NET/8  anywhere           
   31  4175 DROP       all  --  any    any     anywhere             BASE-ADDRESS.MCAST.NET/8
    0     0 DROP       all  --  any    any     255.255.255.255      anywhere           
    0     0 DROP       all  --  any    any     anywhere             0.0.0.0             
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID
    0     0 LSI        all  -f  any    any     anywhere             anywhere            limit: avg 10/min burst 5
1222  691K INBOUND    all  --  eth1   any     anywhere             anywhere           
    0     0 INBOUND    all  --  eth0   any     anywhere             serveurICS         
    0     0 INBOUND    all  --  eth0   any     anywhere             172.24.2.113       
   46  6333 INBOUND    all  --  eth0   any     anywhere             192.168.10.255     
    0     0 LOG_FILTER  all  --  any    any     anywhere             anywhere           
    0     0 LOG        all  --  any    any     anywhere             anywhere            LOG level info prefix `Unknown Input'

Chain FORWARD (policy DROP 1 packets, 60 bytes)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere            limit: avg 10/sec burst 5
    0     0 TCPMSS     tcp  --  any    any     anywhere             anywhere            tcp flags:SYN,RST/SYN TCPMSS clamp to PMTU
   66  4000 OUTBOUND   all  --  eth0   any     anywhere             anywhere           
    0     0 ACCEPT     tcp  --  any    any     anywhere             192.168.10.0/24     state RELATED,ESTABLISHED
    0     0 ACCEPT     udp  --  any    any     anywhere             192.168.10.0/24     state RELATED,ESTABLISHED
    0     0 LOG_FILTER  all  --  any    any     anywhere             anywhere           
    0     0 LOG        all  --  any    any     anywhere             anywhere            LOG level info prefix `Unknown Forward'

Chain OUTPUT (policy DROP 3 packets, 537 bytes)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  any    any     172.24.2.113         localhost           tcp dpt:domain
    0     0 ACCEPT     udp  --  any    any     172.24.2.113         localhost           udp dpt:domain
    0     0 ACCEPT     tcp  --  any    any     172.24.2.113         lotus.univ-corse.fr tcp dpt:domain
   16  1062 ACCEPT     udp  --  any    any     172.24.2.113         lotus.univ-corse.fr udp dpt:domain
   36  5079 ACCEPT     all  --  any    lo      anywhere             anywhere           
    0     0 DROP       all  --  any    any     BASE-ADDRESS.MCAST.NET/8  anywhere           
   27  2406 DROP       all  --  any    any     anywhere             BASE-ADDRESS.MCAST.NET/8
    0     0 DROP       all  --  any    any     255.255.255.255      anywhere           
    0     0 DROP       all  --  any    any     anywhere             0.0.0.0             
    0     0 DROP       all  --  any    any     anywhere             anywhere            state INVALID
  845  133K OUTBOUND   all  --  any    eth1    anywhere             anywhere           
   22  3389 OUTBOUND   all  --  any    eth0    anywhere             anywhere           
    0     0 LOG_FILTER  all  --  any    any     anywhere             anywhere           
    0     0 LOG        all  --  any    any     anywhere             anywhere            LOG level info prefix `Unknown Output'

Chain INBOUND (4 references)
pkts bytes target     prot opt in     out     source               destination         
  724  610K ACCEPT     tcp  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    7  1371 ACCEPT     all  --  any    any     172.24.1.40          anywhere           
   24  2944 ACCEPT     all  --  any    any     192.168.10.110       anywhere           
   22  3389 ACCEPT     all  --  any    any     serveurICS           anywhere           
  491 79009 LSI        all  --  any    any     anywhere             anywhere           

Chain LOG_FILTER (5 references)
pkts bytes target     prot opt in     out     source               destination         

Chain LSI (2 references)
pkts bytes target     prot opt in     out     source               destination         
  491 79009 LOG_FILTER  all  --  any    any     anywhere             anywhere           
    0     0 LOG        tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN limit: avg 1/sec burst 5 LOG level info prefix `Inbound '
    0     0 DROP       tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN
    0     0 LOG        tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/RST limit: avg 1/sec burst 5 LOG level info prefix `Inbound '
    0     0 DROP       tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/RST
    0     0 LOG        icmp --  any    any     anywhere             anywhere            icmp echo-request limit: avg 1/sec burst 5 LOG level info prefix `Inbound '
    0     0 DROP       icmp --  any    any     anywhere             anywhere            icmp echo-request
  469 76000 LOG        all  --  any    any     anywhere             anywhere            limit: avg 5/sec burst 5 LOG level info prefix `Inbound '
  491 79009 DROP       all  --  any    any     anywhere             anywhere           

Chain LSO (0 references)
pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG_FILTER  all  --  any    any     anywhere             anywhere           
    0     0 LOG        all  --  any    any     anywhere             anywhere            limit: avg 5/sec burst 5 LOG level info prefix `Outbound '
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-port-unreachable

Chain OUTBOUND (3 references)
pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere           
  743  125K ACCEPT     tcp  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
  190 15681 ACCEPT     all  --  any    any     anywhere             anywhere

Précision : j'ai pas retapé la commande
echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o $interface -j MASQUERADE
partant du principe qu'elle est activé au lancement du pc (et dans la mesure où il y a bien un "1" sans que je fasse rien dans /proc/sys/net/ipv4/ip_forward, j'pense que j'ai raison).

Dernière modification par Nathanos (Le 07/09/2008, à 16:14)

Hors ligne

#6 Le 07/09/2008, à 16:53

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Mmmm, il a pas l'air d'aimer ton script :d

nathan@tsubomi:~$ sudo sh script.sh 
script.sh: 13: internal: not found
script.sh: 15: dynamic: not found
script.sh: 15: eth1: not found
script.sh: 17: and: not found
script.sh: 18: internal: not found
script.sh: 19: to: not found
script.sh: 20: internal: not found
from: can't read /var/mail/internal

sed : l'option requiert un argument -- e
Utilisation: sed [OPTION]... {script-seulement-si-pas-d'autre-script}
[fichier-d'entrée]...

  -n, --quiet, --silent
                 supprimer l'écriture automatique de l'espace des motifs
  -e script, --expression=script
                 ajouter le script aux commandes à être exécutées
  -f fichier-script, --file=fichier-script
                 ajouter le contenu de fichier-script aux commandes
                 à être exécutées
  -i[SUFFIXE], --in-place[=SUFFIXE]
                 éditer les fichiers à leur place (fait une
                 sauvegarde si l'extension est fournie)
  -l N, --line-length=N
                spécifier la longueur de coupure de ligne désirée pour la
                commande `l'
  --posix
                 désactiver toutes les extensions GNU.
  -r, --regexp-extended
                 utiliser la syntaxe des expressions régulières
                 étendues dans le script.
  -s, --separate
                considérer les fichiers comme séparés plutôt que comme un
                simple flux long et continu.
  -u, --unbuffered
                 charger des quantités minimales de données depuis les
                 fichiers d'entrée et libérer les tampons de sortie plus
                 souvent
      --help     afficher cette aide et sortir
      --version  afficher les informations de version du logiciel et sortir

Si aucune option -e, --expression, -f ou --file n'est donnée, le
premier argument qui n'est pas une option sera pris comme étant le script
sed à interpréter. Tous les arguments restants sont les noms des fichiers
d'entrée; si aucun fichier d'entrée n'est spécifiée, l'entrée standard
est lue.

Rapporter toutes anomalies à: bonzini@gnu.org.
N'oubliez pas d'inclure le mot ``sed'' quelque-part dans la zone ``Subject:''
script.sh: 163: s/\([^\.]\)\..*/\1/: not found
script.sh: 165: -e: not found
FATAL: Module ebtable_nat.ko not found.

Dernière modification par Nathanos (Le 07/09/2008, à 16:54)

Hors ligne

#7 Le 07/09/2008, à 17:02

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Tiens, bizarre, ça marche mieux... J'ai du me planter dans le c/c tout à l'heure.
Donc...

nathan@tsubomi:~$ sudo sh script.sh 

Activating firewall script generated Sun Sep  7 16:23:00 2008  by mike
Rule 0 (NAT)
Rule 0 (eth1)
Rule 1 (lo)
Rule 3 (global)
Rule 4 (global)
Rule 5 (global)
Rule 6 (global)
Rule 7 (global)
Rule 8 (global)

J'vais tenter de lancer firefox sur l'autre pc...

Hors ligne

#8 Le 07/09/2008, à 17:14

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Bon, après reboot de l'autre pc, le firewall a décidé de bloquer tout chez moi, donc plus droit aux ping, plus de samba, plus internet, rien nada.

Moralité : ton script marche, mais il me prend internet >_< .

Sinon, le renvoi de IPtable est similaire à celui que tu indiques, avec le script activé.


D'ailleurs, là que j'y pense, dans IPTable on voit souvent du "in" eth1 et du "out" any, mais ça serait pas mieux si on indiquait explicitement eth0 dans "out" ?
Idem pour ce qui est de Destination, ça marcherait pas si on disait franco "192.168.10.110" ? (je présume que le "0" est l'équivalent IP de "*")

Bon après, je dis ça, mais niveau réseau j'y connais pas grand chose moi ^_^ .

Dernière modification par Nathanos (Le 07/09/2008, à 17:27)

Hors ligne

#9 Le 07/09/2008, à 17:58

#Ergo-Proxy

Re : Partage de connexion WIFI vers 2e pc

Nathanos a écrit :

Bon, après reboot de l'autre pc, le firewall a décidé de bloquer tout chez moi, donc plus droit aux ping, plus de samba, plus internet, rien nada.

Moralité : ton script marche, mais il me prend internet >_< .

Sinon, le renvoi de IPtable est similaire à celui que tu indiques, avec le script activé.


D'ailleurs, là que j'y pense, dans IPTable on voit souvent du "in" eth1 et du "out" any, mais ça serait pas mieux si on indiquait explicitement eth0 dans "out" ?
Idem pour ce qui est de Destination, ça marcherait pas si on disait franco "192.168.10.110" ? (je présume que le "0" est l'équivalent IP de "*")

Bon après, je dis ça, mais niveau réseau j'y connais pas grand chose moi ^_^ .

un autre big_smile

#!/bin/sh 
#
#  This is automatically generated file. DO NOT MODIFY !
#
#  Firewall Builder  fwb_ipt v2.1.14-1 
#
#  Generated Sun Sep  7 17:51:43 2008 CEST by mike
#
# files: * Eth1 en partage.fw
#
#
#  This firewall has two interfaces. Eth1 faces outside and has a dynamic address; eth0 faces inside.
#  Policy includes basic rules to permit unrestricted outbound access and anti-spoofing rules. Access to the firewall is permitted only from internal network and only using SSH. The firewall uses one of the machines on internal network for DNS. Internal network is configured with address 192.168.10.0/255.255.255.0
#
#
#


PATH="/sbin:/usr/sbin:/bin:/usr/bin:${PATH}"
export PATH

LSMOD="/sbin/lsmod"
MODPROBE="/sbin/modprobe"
IPTABLES="/sbin/iptables"
IPTABLES_RESTORE="/sbin/iptables-restore"
IP="/sbin/ip"
LOGGER="/usr/bin/logger"


#
# Prolog script
#

#
# End of prolog script
#

log() {
  echo "$1"
  test -x "$LOGGER" && $LOGGER -p info "$1"
}

check_file() {
  test -r "$2" || {
    echo "Can not find file $2 referenced by AddressTable object $1"
    exit 1
  }
}

va_num=1
add_addr() {
  addr=$1
  nm=$2
  dev=$3

  type=""
  aadd=""

  L=`$IP -4 link ls $dev | head -n1`
  if test -n "$L"; then
    OIFS=$IFS
    IFS=" /:,<"
    set $L
    type=$4
    IFS=$OIFS
    if test "$type" = "NO-CARRIER"; then
      type=$5
    fi

    L=`$IP -4 addr ls $dev to $addr | grep inet | grep -v :`
    if test -n "$L"; then
      OIFS=$IFS
      IFS=" /"
      set $L
      aadd=$2
      IFS=$OIFS
    fi
  fi
  if test -z "$aadd"; then
    if test "$type" = "POINTOPOINT"; then
      $IP -4 addr add $addr dev $dev scope global label $dev:FWB${va_num}
      va_num=`expr $va_num + 1`
    fi
    if test "$type" = "BROADCAST"; then
      $IP -4 addr add $addr/$nm dev $dev brd + scope global label $dev:FWB${va_num}
      va_num=`expr $va_num + 1`
    fi
  fi
}

getInterfaceVarName() {
  echo $1 | sed 's/\./_/'
}

getaddr() {
  dev=$1
  name=$2
  L=`$IP -4 addr show dev $dev | grep inet | grep -v :`
  test -z "$L" && { 
    eval "$name=''"
    return
  }
  OIFS=$IFS
  IFS=" /"
  set $L
  eval "$name=$2"
  IFS=$OIFS
}


getinterfaces() {
  NAME=$1
  $IP link show | grep ": $NAME" | while read L; do
    OIFS=$IFS
    IFS=" :"
    set $L
    IFS=$OIFS
    echo $2
  done
}


# increment ip address
incaddr()
{
  n1=$4
  n2=$3
  n3=$2
  n4=$1

  vn1=`eval  "echo \\$$n1"`

  R=`expr $vn1 \< 255`
  if test $R = "1"; then
    eval "$n1=`expr $vn1 + 1`"
  else
    eval "$n1=0"
    incaddr XX $n4 $n3 $n2
  fi
}

if $IP link ls >/dev/null 2>&1; then
  echo;
else
  echo "iproute not found"
  exit 1
fi



MODULES_DIR="/lib/modules/`uname -r`/kernel/net/"
MODULES=`find $MODULES_DIR -name '*conntrack*'|sed  -e 's/^.*\///' -e 's/\([^\.]\)\..*/\1/'`
MODULES="$MODULES `find $MODULES_DIR -name '*nat*'|sed  -e 's/^.*\///' -e 's/\([^\.]\)\..*/\1/'`"
for module in $MODULES; do 
  if $LSMOD | grep ${module} >/dev/null; then continue; fi
  $MODPROBE ${module} ||  exit 1 
done


# Using 0 address table files


INTERFACES="eth1 eth0 lo "
for i in $INTERFACES ; do
  $IP link show "$i" > /dev/null 2>&1 || {
    log "Interface $i does not exist"
    exit 1
  }
done


# Configure interfaces
$IP -4 neigh flush dev eth0 >/dev/null 2>&1
$IP -4 addr flush dev eth0 secondary label "eth0:FWB*" >/dev/null 2>&1


add_addr 192.168.10.1 24 eth0
$IP link set eth0 up
add_addr 127.0.0.1 8 lo
$IP link set lo up

getaddr eth1  i_eth1

# Add virtual addresses for NAT rules


log 'Activating firewall script generated Sun Sep  7 17:51:43 2008  by mike'

$IPTABLES -P OUTPUT  DROP
$IPTABLES -P INPUT   DROP
$IPTABLES -P FORWARD DROP
ip6tables -L -n > /dev/null 2>&1 && {
  ip6tables -P OUTPUT  DROP
  ip6tables -P INPUT   DROP
  ip6tables -P FORWARD DROP
  ip6tables -A INPUT  -i lo  -j ACCEPT 
  ip6tables -A OUTPUT  -o lo  -j ACCEPT 
}



cat /proc/net/ip_tables_names | while read table; do
  $IPTABLES -t $table -L -n | while read c chain rest; do
      if test "X$c" = "XChain" ; then
        $IPTABLES -t $table -F $chain
      fi
  done
  $IPTABLES -t $table -X
done


$IPTABLES -A INPUT   -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

# 
# Rule 0 (NAT)
# 
echo "Rule 0 (NAT)"
# 
# 
test -n "$i_eth1" && $IPTABLES -t nat -A OUTPUT   -s $i_eth1  -j DNAT --to-destination 192.168.10.1 
test -n "$i_eth1" && $IPTABLES -t nat -A POSTROUTING -o eth1  -s $i_eth1  -d 192.168.10.1 -j MASQUERADE  
# 
# Rule 0 (eth1)
# 
echo "Rule 0 (eth1)"
# 
# anti spoofing rule
# 
$IPTABLES -N In_RULE_0
test -n "$i_eth1" && $IPTABLES -A INPUT  -i eth1  -s $i_eth1  -m state --state NEW  -j In_RULE_0 
$IPTABLES -A INPUT  -i eth1  -s 192.168.10.1  -m state --state NEW  -j In_RULE_0 
$IPTABLES -A INPUT  -i eth1  -s 192.168.10.0/24  -m state --state NEW  -j In_RULE_0 
test -n "$i_eth1" && $IPTABLES -A FORWARD  -i eth1  -s $i_eth1  -m state --state NEW  -j In_RULE_0 
$IPTABLES -A FORWARD  -i eth1  -s 192.168.10.1  -m state --state NEW  -j In_RULE_0 
$IPTABLES -A FORWARD  -i eth1  -s 192.168.10.0/24  -m state --state NEW  -j In_RULE_0 
$IPTABLES -A In_RULE_0  -j LOG  --log-level info --log-prefix "RULE 0 -- DENY "
$IPTABLES -A In_RULE_0  -j DROP 
# 
# Rule 1 (lo)
# 
echo "Rule 1 (lo)"
# 
# 
# 
$IPTABLES -A INPUT  -i lo  -m state --state NEW  -j ACCEPT 
$IPTABLES -A OUTPUT  -o lo  -m state --state NEW  -j ACCEPT 
# 
# Rule 2 (global)
# 
echo "Rule 2 (global)"
# 
# SSH Access to firewall is permitted
# only from internal network
# 
$IPTABLES -A INPUT -p tcp -m tcp  -s 192.168.10.0/24  --dport 22  -m state --state NEW  -j ACCEPT 
# 
# Rule 3 (global)
# 
echo "Rule 3 (global)"
# 
# Firewall uses one of the machines
# on internal network for DNS
# 
$IPTABLES -N RULE_3
$IPTABLES -A OUTPUT -p tcp -m tcp  -d 192.168.10.0/24  --dport 53  -m state --state NEW  -j RULE_3 
$IPTABLES -A OUTPUT -p udp -m udp  -d 192.168.10.0/24  --dport 53  -m state --state NEW  -j RULE_3 
$IPTABLES -A RULE_3  -j LOG  --log-level info --log-prefix "RULE 3 -- ACCEPT "
$IPTABLES -A RULE_3  -j ACCEPT 
# 
# Rule 4 (global)
# 
echo "Rule 4 (global)"
# 
# All other attempts to connect to
# the firewall are denied and logged
# 
$IPTABLES -N RULE_4
test -n "$i_eth1" && $IPTABLES -A OUTPUT  -d $i_eth1  -m state --state NEW  -j RULE_4 
$IPTABLES -A OUTPUT  -d 192.168.10.1  -m state --state NEW  -j RULE_4 
$IPTABLES -A INPUT  -m state --state NEW  -j RULE_4 
$IPTABLES -A RULE_4  -j LOG  --log-level info --log-prefix "RULE 4 -- DENY "
$IPTABLES -A RULE_4  -j DROP 
# 
# Rule 5 (global)
# 
echo "Rule 5 (global)"
# 
# 
# 
$IPTABLES -A INPUT  -s 192.168.10.0/24  -m state --state NEW  -j ACCEPT 
$IPTABLES -A OUTPUT  -s 192.168.10.0/24  -m state --state NEW  -j ACCEPT 
$IPTABLES -A FORWARD  -s 192.168.10.0/24  -m state --state NEW  -j ACCEPT 
# 
# Rule 6 (global)
# 
echo "Rule 6 (global)"
# 
# 
# 
$IPTABLES -N RULE_6
$IPTABLES -A OUTPUT  -m state --state NEW  -j RULE_6 
$IPTABLES -A INPUT  -m state --state NEW  -j RULE_6 
$IPTABLES -A FORWARD  -m state --state NEW  -j RULE_6 
$IPTABLES -A RULE_6  -j LOG  --log-level info --log-prefix "RULE 6 -- DENY "
$IPTABLES -A RULE_6  -j DROP 
# 
# Rule 7 (global)
# 
echo "Rule 7 (global)"
# 
# 
# 
$IPTABLES -N RULE_7
test -n "$i_eth1" && $IPTABLES -A INPUT -p tcp -m tcp  -m multiport  -s $i_eth1  --dports 80,443,143,110,445  -m state --state NEW  -j RULE_7 
test -n "$i_eth1" && $IPTABLES -A INPUT -p udp -m udp  -s $i_eth1  --dport 137  -m state --state NEW  -j RULE_7 
test -n "$i_eth1" && $IPTABLES -A OUTPUT -p tcp -m tcp  -m multiport  -s $i_eth1  --dports 80,443,143,110,515,445  -m state --state NEW  -j RULE_7 
test -n "$i_eth1" && $IPTABLES -A OUTPUT -p udp -m udp  -s $i_eth1  --dport 137  -m state --state NEW  -j RULE_7 
$IPTABLES -A RULE_7  -j LOG  --log-level info --log-prefix "RULE 7 -- ACCEPT "
$IPTABLES -A RULE_7  -j ACCEPT 
#
#
echo 1 > /proc/sys/net/ipv4/ip_forward


#
# Epilog script

Dernière modification par #Ergo-Proxy (Le 07/09/2008, à 18:02)

#10 Le 07/09/2008, à 18:09

Nathanos

Re : Partage de connexion WIFI vers 2e pc

J'ai récupéré le ping et samba, mais j'ai toujours plus l'net avec ton script.

Et le partage marche pas.

Hors ligne

#11 Le 07/09/2008, à 18:24

Nathanos

Re : Partage de connexion WIFI vers 2e pc

Je comprend officiellement pas : toujours pas de forward actif, partage de connexion inexistant.

J'vais essayer ce tuto voir si ça marche mieux.

En tout cas merci de ton aide, maintenant je sais lire un fichier de conf' d'Iptable :d .

Hors ligne