2

I have this command for allow traffic to one port only from one ip:

iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP

But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:

iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP

How can i do this?

1

I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:

#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
#       Most basic iptables firewall.
#       Currently for this question:
#       https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#

# The location of the iptables program
#
IPTABLES=/sbin/iptables

#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"

echo 1110080_firewall $FWVER begin.

#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F

# Reset all IPTABLES counters
$IPTABLES -Z

# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT

#$IPTABLES -A INPUT -j DROP

echo 1110080_firewall $FWVER done.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.