Results 1 to 10 of 13
Hello,
I am new to IPTABLES and was hoping someone might be able to help me. I have a http server running on port 80. I use SSH from work ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-26-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
IPTABLES question
Hello,
I am new to IPTABLES and was hoping someone might be able to help me. I have a http server running on port 80. I use SSH from work to connect to the same pc that runs the web server, but due to firewall restrictions I can only use port 80. I want to create a rule so all traffic on port 80 from a specific IP address or range (my workplace) gets forwarded to port 22, but all other port 80 traffic to be routed normally.
Many thanks.
Chemist
- 11-27-2007 #2
So you'd like portforwarding..
here:
-> Hackorama
Since I have been using 2.4 kernel, I use iptables for firewall and NAT. So these are the Iptable rules required for port forwarding xxx.xxx.xxx.xxx:8888 to 192.168.0.2:80 .
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d xxx.xxx.xxx.xxx
--dport 8888 -j DNAT --to 192.168.0.2:80
/sbin/iptables -A FORWARD -p tcp -i eth0 -d 192.168.0.2 --dport 80 -j ACCEPT
- 11-27-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Hi mate,
Thanks for that, however it appears to not work. I use this script iptablesrocks.org - Deploying the firewall and after I enter this;
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d 82.45.23.202 --dport 80 -j DNAT --to 192.168.1.68:22
/sbin/iptables -A FORWARD -p tcp -i eth0 -d 192.168.1.68 --dport 22 -j ACCEPT
this is the result of iptables -L
general pastebin - Someone - post number 799915
I am trying to get any port 80 traffic from 82.45.23.202 to go to port 22 of 192.168.1.68
any help will be welcome
Thanx
- 11-28-2007 #4
- 11-28-2007 #5Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere 62-31-164-55.cable.ubr11.azte.blueyonder.co.uk tcp dpt:www to:192.168.1.68:22
DNAT tcp -- anywhere 193.34.231.236 tcp dpt:www to:192.168.1.68:22
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
I changed the ip addresses.
Thanks
- 11-28-2007 #6
- 11-28-2007 #7Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Excuse my idiocy, but what do you mean by "re-entering the command but right this time"?
Thanx
- 11-29-2007 #8
Here is what you are looking for:
If the box you are trying to get to is behind the firewall box
[INTERNET]<-->[firewall]<-->[SSH Box]
If the box you are trying to ssh to is on the firewall boxCode:iptables -t nat -A PREROUTING -p tcp -s <Work IP> --dport 80 -j DNAT --to-destination <serverIP>:22
[INTERNET]<-->[firewall/ssh box]
The first rule tell iptable to change the ip address it is going to.Code:iptables -t nat -A PREROUTING -p tcp -s <WorkIP> --dport 80 -j REDIRECT --to-ports 22
The second one tell iptables that it is to stay on the present box and doesn't need to be routed on.
- 11-29-2007 #9Just Joined!
- Join Date
- Nov 2007
- Posts
- 6
Thanks a lot! That worked straight off
I might be pushing my luck here but how would I achieve the same result from a range of IP's?
Regards, Chemist
- 11-29-2007 #10
I guess its not the most Effective way but..
Id write a file that has a list of IPs in there.
Call it iplist.conf
then Id make a new script
that has:
then ill give itCode:iptables -t nat -A PREROUTING -p tcp -s $1 --dport 80 -j REDIRECT --to-ports 22
and call it addfirewall.shCode:chmod +x
then I have to link those files together doing this:
save that file as ExecuteMe.perlCode:open (IP, "iplist.conf"); while ($parseIP = IP) { `sh addfirewall.sh $parseIP`; } close(IP);
dothenCode:chmod +x ExecuteMe.perl
and It should be doneCode:perl ExecuteMe.perl

I hope that helped.
I know for sure LazyDog has a better way but still


Reply With Quote

