Link to home
Start Free TrialLog in
Avatar of JPERKS1985
JPERKS1985

asked on

ip tables question

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
Avatar of data_grrr
data_grrr

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.
Avatar of JPERKS1985

ASKER

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?
Now when I restart the ip tables service i get error failed.
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?
ASKER CERTIFIED SOLUTION
Avatar of durindil
durindil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial