Hello
I'm beginner in the linux scripting and i would like to get help. I want to create a script that can block one or more Port even see all the TCP port. The ports must be blocked even when starting my machine.
Of course requires a second script which will allow the ports that you want to unlock.
I put online my script can you help me please?
Cordially
Script 1 : Close
#!/bin/bash
read -p 'Quelle port voulez-vous d�sactiver ?' port1
iptables -A INPUT -p tcp --dport $port1 -j REJECT
iptables -A OUTPUT -p tcp --dport $port1 -j REJECT
read -p 'Voulez-vous d�sactiver un autre port ?(oui/non) ' rep
if [ $rep = 'oui' ]
then
read -p 'Num�ro du deuxi�me port ? ' port2
iptables -A INPUT -p tcp --dport $port2 -j REJECT
iptables -A OUTPUT -p tcp --dport $port2 -j REJECT
echo "Les port $port1 et $port2 sont bien d�sactiv�s !"
echo -e "\niptables -A INPUT -p tcp --dport $port1 -j REJECT\niptables -A OUTPUT -p tcp --dport $port1 -j REJECT\niptables -A INPUT -p tcp --dport $port2 -j REJECT\niptables -A OUTPUT -p tcp --dport $port2 -j REJECT\n" >> /etc/rc.local
exit 0
elif [ $rep = 'non' ]
then
echo "Le port $port1 est bien d�sactiv� !"
echo -e "\niptables -A INPUT -p tcp --dport $port1 -j REJECT\niptables -A OUTPUT -p tcp --dport $port1 -j REJECT\n" >> /etc/rc.local
exit 0
fi
exit 0
Script 2 : Open
#!/bin/bash
read -p 'Quelle port voulez-vous activer ?' port
iptables -D INPUT -p tcp --dport $port -j REJECT
iptables -D OUTPUT -p tcp --dport $port -j REJECT
echo "Le port $port est bien ouvert !"
echo -n "
iptables -D INPUT -p tcp --dport $port -j REJECT
iptables -D OUTPUT -p tcp --dport $port -j REJECT" >> /etc/rc.local