+ Responder ao Tópico



  1. #1

    Padrão Script Firewall com MAC e IP

    Eu tenho um arquivo chamado mac.txt e dentro dele contem as linhas IP e MAC separados por ponto e virgula, ex:
    192.168.0.10;F0:AF:FF:FE:FA:00

    Meu script do firewall contem o seguinte:

    #!/bin/bash
    for i in `cat /root/mac1.txt`;
    do
    MACSOURCE=`echo $i | cut -d ';' -f1`
    IPSOURCE=`echo $i | cut -d ';' -f2`
    iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
    iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
    iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
    iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
    done

    E acontece o erro :

    iptables v1.4.3.1: Bad mac address "192.168.0.10"
    Try `iptables -h' or 'iptables --help' for more information.
    iptables v1.4.3.1: host/network `F0:AF:FF:FE:FA:00' not found
    Try `iptables -h' or 'iptables --help' for more information.
    iptables v1.4.3.1: Bad mac address "192.168.0.10"
    Try `iptables -h' or 'iptables --help' for more information.
    iptables v1.4.3.1: host/network `F0:ADF:FF:FE:FA:00' not found
    Try `iptables -h' or 'iptables --help' for more information.

    Ja tentei usar também WHILE mas o erro acontece. Ele está pegando as ASPAS no IP e o APOSTROFE (`) no MAC.

  2. #2

    Smile

    Há duas maneiras de você resolver este problema:

    maneira 1:

    mudar a sintaxe do cut para

    MACSOURCE=`echo $i | cut -d \; -f1`

    maneira 2:

    substituir os ; no seu arquivo txt e mudar de cut para
    MACSOURCE=`echo $i | awk '{ print $2}'`

    Isto deve resolver.

  3. #3

    Padrão

    Eu preciso que a saida do comando seja iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT. (iptables -t filter-A FORWARD-d 0/0 -s 192.168.0.10 -m mac --mac-source 00:xx:yy:zz:99:88 -j ACCEPT).
    Eu preciso do $IPSOURCE que está na primeira coluna e do $MACSOURCE da segunda coluna, Modifiquei o CUT para -d \; e deu o mesmo erro

    Fiz o teste:

    for i in `cat /root/mac.txt`;
    do
    MACSOURCE=`echo $i | cut -d ';' -f1`
    IPSOURCE=`echo $i | cut -d ';' -f2`
    echo $MACSOURCE
    echo $IPSOURCE
    done

    e o script esta ok

  4. #4

    Padrão

    Ficou assim e está funcionando :

    >for i in `cat /root/mac.txt`;
    >do
    >IPSOURCE=`echo $i | cut -d \; -f1`
    >MACSOURCE=`echo $i | cut -d \; -f2`
    >iptables -t filter -A FORWARD -d 0/0 -s $IPSOURCE -m mac --mac-source $MACSOURCE -j ACCEPT
    >iptables -t filter -A FORWARD -d $IPSOURCE -s 0/0 -j ACCEPT
    >iptables -t filter -A INPUT -s $IPSOURCE -d 0/0 -m mac --mac-source $MACSOURCE -j ACCEPT
    >iptables -t nat -A POSTROUTING -s $IPSOURCE -o eth0 -j MASQUERADE
    >done

    Obrigado pela ajuda