Solved

ip tables question

Posted on 2006-11-20
5
250 Views
Last Modified: 2010-04-20
how would I allow access to port 8080 for only one  external IP. So 64.342.12.12 has access to port 8080 and all other IPs do not? I'm looking for the terminal command. thanks
0
Comment
Question by:JPERKS1985
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:data_grrr
ID: 17982660
iptables -A FORWARD -s 64.342.12.12/CIDRnumber -i eth0 -d destination.ip. -o eth1 -p TCP \
         --sport 1:65535 --dport 8080 -j ACCEPT

CIDRnumber must be the subnet mask of 64.342.12.12 like /24 for 255.255.255.0 or /8 for 255.0.0.0

'eth0' is the interface that packets coming from 64.342.12.12, or whatever name it is in your configuration.

destination ip must be the address of destination server which listens port 8080

eth1 is the interface listening 8080

--sport is the accepted port range. you can change it like 8080:8081 if you wanna listen these ports.

--dport is the destination port, packets are routed to this port. if your server listens 8080 it must be like this.
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 17982925
iptables -A FORWARD -s 64.342.12.12/24 -i eth0 -d 64.342.12.13 -o eth1 -p TCP \
         --sport 1:65535 --dport 8080 -j ACCEPT


didn't work, replacing the .13 address with 127.0.0.1 didn't work either. Any ideas?
0
 
LVL 1

Author Comment

by:JPERKS1985
ID: 17982944
Now when I restart the ip tables service i get error failed.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17985448
It's not clear if the firewall is on same machine as squid(?) or before the squid-box.
For squid box
iptables -I INPUT -p tcp -s 64.342.12.12/32 --dport 8080 -j ACCEPT #/32 means only this one IP
For firewall before squid-box
iptables -I FORWARD -p tcp -s 64.342.12.12/32 -d ip.of.squid.box/32 --dport 8080 -j ACCEPT #/32 means only this one IP

Note, that param -I says to insert the rule in front of processing chain, -A means appen at the end. I used -I because You may already have some rules that denies access to 8080. To verify: iptables -L INPUT -nx # or: iptables -L FORWARD -nx

> Now when I restart the ip tables service i get error failed.
Of course, the configuration was not saved permanently. Usually You have to issue:
/etc/init.d/iptables save
What linux distro?
0
 
LVL 6

Accepted Solution

by:
durindil earned 500 total points
ID: 17996788
I don't see why you wold need forward rules - but you have to put your IPTABLES rules in order.  Therefore, you would issue the most resctrictive command first.  You want to:

1) Allow only 64.342.12.12 access to 8080
2) Deny all others access to 8080

So you would issue:

/sbin/iptables -I INPUT 1 -p udp --dport 8080 -j DROP
/sbin/iptables -I INPUT 1 -p tcp --dport 8080 -j DROP
/sbin/iptables -I INPUT 1 -s 64.342.12.12 -p udp --dport 8080 -j ACCEPT
/sbin/iptables -I INPUT 1 -s 64.342.12.12 -p tcp --dport 8080 -j ACCEPT

The save the config:

/sbin/ipables-save > /etc/sysconfig/iptables

Since you issued the commands in this order, each subsequent one will be pushed down in order.  Therefore it will process the rules for 64.342.12.12 first.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question