Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm trying to forward SSH connections in my LAN from one computer to another using iptables, however, I'm stuck. Yet, I think I'm just about there, if someone could give me a small hand here.
At the moment my internet comes into my flat and is then routed with a linksys router. This has an external IP, and a private one (10.0.0.1). At the moment, my server is set up as a DMZ, and any SSH requests to my flat are sent straight to my server.
Instead, I would like SSH requests to be routed (using iptables) by my server and sent to another computer.
My server has two cards: eth0 10.0.0.2 and eth1 192.168.0.1 . The other computer (call it COMP3) has IP eth0: 192.168.0.1.
At the moment my server and COMP3 can chat to each other (ie they can ping one another, and I can SSH in from one to the other.
I would like that, whenever I SSH to my flat the Linksys router sends the request to my server, and then my server says "oh, this is an SSH request, I ad better send it to COMP3".
So far, Ihave a working firewall on my server (which allows SSH requests) and no firewall on COMP3. The rules which I have written to allow this forwarding are:
as far as I can see, this should work, however, it doesn't and when I SSH to my flat, it doesn't connect to anything (not even my server, like it used to).
Can someone help me? I feel that I'm so close to the end!
Regards
Hamish
edit: I can't set my linksys router up to do this, as I have no spare ports on it.
if u want to share internet for your computer behind linux also, u may want to visit www.iptables-script.dk to generate iptables script for yourself. it is simple and secure enough.
i hope it will help u.
In an effort to simplify everything, I have written rules so that the port which I want to forward is port 1234 (thus I don't mess up chances of sshing into my server).
This means that I want to forward requests to 10.0.0.2:1234 to 192.168.0.2:22 .
You should not need SNAT, Masquerade, or POSTROUTING rules. If you want to forward port 1234 to 22, change --dport 22 to --dport 1234 in the PREROUTING rule. You did setup the linksys to forward anything for port 1234 to 10.0.0.2, correct?
If you still can't get connected, here is a very basic ruleset that will forward 1234 to 192.168.0.2:22. It should work, if it doesn't the problem is something else.
However, I'm confused about one thing:
the only way it works at the moment is if I set iptables --policy FORWARD ACCEPT" .
When I have the polilcy set to ACCEPT forwards, it works perfectly, however, whenI turn that off and rely on this line:
Code:
iptables -A FORWARD -p tcp -d $INTERNAL_MACHINE_IP --dport $INTERNAL_MACHINE_PORT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
it doesn't work.
Doing this does work:
Code:
iptables -A FORWARD -p tcp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
Do you have any suggestions why that doesn't work? As far as I can see, that is saying that it should accept forwards whcih are either NEW, Established or related.
thanks for everything so far, you have helped me no end!
hamish
The second rule works because it will allow any tcp packet to be forwarded to any ip, using any port, on any interface. The first rule allows all tcp packets to be forwarded to 192.168.0.2, but will not allow them to be forwarded back to the internet, so a connection cannot be established. I would use a few rules like this.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.