Tuesday, 16 July 2013

Open ports in Iptables via sudo

This is a small script which allows ordinary users open and close ports using Iptables:

#!/bin/bash

if [ ! $# == 3 ]; then
    echo "Usage: ports open|close tcp|udp port_number"
    echo "List of open ports:"
    iptables -L
  exit
fi

if [ $1 == 'open' ]; then
d="A"
iptables -$d INPUT -p $2 --dport $3 -j ACCEPT
elif [ $1 == 'close' ]; then
d="D"
iptables -$d INPUT -p $2 --dport $3 -j ACCEPT
else
echo "Port may be open or close only"
fi

No comments:

Post a Comment

Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...