Iptables. How to open a port to one ore more specific IP

Written by
Date: 2013-01-27 22:31:10 00:00

Sometimes you need to open a port on your server, you want it to be recheable only from specific IP address, you can use Iptables for this:

iptables -I INPUT -p tcp -s --dport 22 -j ACCEPT

In that case, you are opening ssh port only to IP, if you need to open DNS for your internal network.

iptables -I INPUT -p udp -s --dport 53 -j ACCEPT

Once you have them added and opened for those IPs, you need to close the door for the rest of IPs

iptables -I INPUT -p tcp -s --dport 22 -j DROP
iptables -I INPUT -p udp -s --dport 53 -j DROP