Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i use fedora 13, and i have firewall turned off now.

but i want to allow all incoming connections and outgoing connections except to a port P. i want to allow connection to port P only from certain ip address : A.B.C.D/24 and X.Y.Z.Z

how do i set this up? it is a remote server, and i do not have X installed so i cannot use apps like firestarter.

share|improve this question
Coming from a BSD pf background I find the iptables really hard to understand and obscure. But, I just want to recommend to you the fwbuilder software which takes the drudgery out of it. – Matt H Mar 10 '11 at 12:47

After putting the appropriate iptables rules in place, you can run service iptables save to save the in-memory rules to a file that will be loaded each time the iptables service is started.

Don't forget to run chkconfig iptables on after so that the service actually starts each time.

share|improve this answer

My two cents:

If you are talking about a port, this is already above the IP level, it's either tcp/udp. Iptables rules that contain a port number and no explicit tcp or udp argument will fail AFAIK. Investigate more the service that runs on that port to find out if it uses tcp or udp. If you need both tcp and udp, you will need to have duplicate rules for both tcp and udp.

To be honest, your question looks amateurish. Not because you don't know what to do, this is normal. Because of the way it is asked.

share|improve this answer


# First, let's make a list of allowed sources
iptables -N restricted_port
iptables -A restricted_port -s A.B.C.D/24 -j ACCEPT
iptables -A restricted_port -s X.Y.Z.Z    -j ACCEPT
# And REJECT other sources (or DROP, if you prefer)
iptables -A restricted_port -j REJECT

# Now, we intercept TCP/UDP accesses to port $P
iptables -A INPUT -p tcp --dport $P -g restricted_port
iptables -A INPUT -p udp --dport $P -g restricted_port
# Other incoming are okay
iptables -A INPUT -j ACCEPT

Save the rules with service iptables save

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .