LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   iptables help! DROP ssh port, but allow to connect to ssh if from 2222 port (https://www.linuxquestions.org/questions/linux-networking-3/iptables-help-drop-ssh-port-but-allow-to-connect-to-ssh-if-from-2222-port-483041/)

kandzha 09-13-2006 06:47 AM

iptables help! DROP ssh port, but allow to connect to ssh if from 2222 port
 
Greetings,

I am sorry if I repeat any thread in forum, but i need some help quick.

Runing slackware 10.2 kernel 2.6 as a router
external interface - eth0
internal interface - eth1
subnet - 192.168.0.x

I am still relative newbie to linux and trying to configure IPTABLES.

My goal is to make that:
1) All external connections to port 22(ssh) would be dropped, while connections from internal network it would be open. My rule for this is:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -j DROP

2) (which is actualy my current problem!!!) I want to make that if trying to connect to my router using port 2222 (not 22) it would somehow forward request to port 22 and allow a connection. (Some sort of tricky hiding :) )

Thanks
Kandzha

unSpawn 09-13-2006 07:10 AM

Some sort of tricky hiding
If you're concerned about remote SSH attempts better check out ways to thwart that: http://www.linuxquestions.org/questi...d.php?t=340366

kandzha 09-13-2006 07:17 AM

[QUOTE=unSpawn]Some sort of tricky hiding
If you're concerned about remote SSH attempts better check out ways to thwart that
No thats not my problem, i just want to be able to connect to router from my home :)

amitsharma_26 09-13-2006 07:30 AM

Quote:

Originally Posted by kandzha
1) All external connections to port 22(ssh) would be dropped, while connections from internal network it would be open. My rule for this is:
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 22 -j DROP

Yes this is fine.
Quote:

Originally Posted by kandzha
2) (which is actualy my current problem!!!) I want to make that if trying to connect to my router using port 2222 (not 22) it would somehow forward request to port 22 and allow a connection. (Some sort of tricky hiding :) )

But better way of doing this would be to change the port at which sshd is running at by mentioning
Code:

Port 2222
in /etc/ssh/sshd.conf & blocking all requests @ 22 nos of port @ INPUT chain.

sin 09-13-2006 09:10 AM

iptables -A INPUT -p tcp --dport 22 -s ! 192.168.0.0/24 -j DROP
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to 192.168.0.1:22


All times are GMT -5. The time now is 10:54 PM.