Allow only one ip to access ssh

Hi guys,

Using following iptables, I can ssh to this machine from any source, the question is if I want only 192.168.1.2 be able to access this server through ssh, what should I do to the following line:

iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 22 -j okay
# First drop everything (lets you open what you want)
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

iptables -N okay
iptables -A okay -p TCP --syn -j ACCEPT
iptables -A okay -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A okay -p TCP -j DROP

#iptables -A INPUT -p ALL -i eth0 -s 10.1.0.0/16 -j ACCEPT
iptables -A INPUT -p ALL -i lo -s 127.0.0.1 -j ACCEPT
iptables -A INPUT -p ALL -i lo -s 10.1.3.30 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Packets for established connections
#iptables -A INPUT -p ALL -d 10.2.0.13 -m state --state ESTABLISHED,RELATED -j ACCEPT

# TCP rules
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 22 -j okay
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 80 -j okay

#ICMP rules
iptables -A INPUT -p ICMP -i eth0 -s 0/0 --icmp-type 8 -j ACCEPT
iptables -A INPUT -p ICMP -i eth0 -s 0/0 --icmp-type 11 -j ACCEPT

# FORWARD chain rules
#iptables -A FORWARD -i eth0 -j ACCEPT
#iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

# OUTPUT chain rules
iptables -A OUTPUT -p ALL -s 127.0.0.1 -j ACCEPT
iptables -A OUTPUT -p ALL -s 10.1.3.30 -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#Iptables to allow yum OUTPUT on port 80
#iptables -A OUTPUT -p tcp -m tcp -m state --state NEW --dport 80 -j ACCEPT

Open in new window

rawandnetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Monis MontherSystem ArchitectCommented:
It should be

iptables -A INPUT -p TCP -i eth0 -s 192.168.0.1 --destination-port 22 -j okay


Assuming that the source is 192.168.0.1

Also you have another solution, you can use tcpwrappers to allow only the specific IP
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vipul999Commented:

for that you would create
a rule to accept your source ip connecting to destination 22

and

a rule to drop or reject all traffic to port 22

that way only your source ip would be allowed to access 22

0
rawandnetAuthor Commented:
how about if i wanted to allow only http (80) traffic, nothing else!
0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

vipul999Commented:

rule 1: create a rule to accept traffic on port 80
rule 2: create a rule to block everything else

rule should be something like
iptables -A INPUT -p TCP --destination-port 80 -j ACCEPT
iptables -A INPUT -j REJECT

systax could be wrong i havent cross checked.

basically first you have to create the accept rule for the port 80 & then the reject for all.

if you interchange the sequence it will only block everything
0
mchkorgCommented:
Just an advice, take a look to www.shorewall.net as an easier interface to iptables.
You just can write basic rules like: "ACCEPT net:$one.ip loc tcp 22" and some general policy like "DROP net loc"
In a few lines, you'll get something easy to understand and maintain.
You have several examples included: one-interface server, 2/3-interfaces gateways and so on...

regards
0
rawandnetAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.