home network gateway and accessing sshd from outside
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
There are less than 2 hours left to vote in the 2011 LinuxQuestions.org Members Choice Awards. Click here to go to the polls. Vote now and make sure your voice is heard! TIME IS RUNNING OUT!
home network gateway and accessing sshd from outside
I have followed the guide located here: linuxselfhelp.com/HOWTO/mini/Home-Network-mini-HOWTO.html
I'm using CentOS4, and it doesn't appear to use ipchains, i'm using iptables instead.
I also had a look at this "home networking/gateway" guide: newbiedoc.sourceforge.net/networking/homegateway.html along with a few others.
You will notice that in section 10 of that guide it has a startup script, but that uses ipchains not iptables, I would like to beable to have a startup script that uses iptables.
Eventually (using 2 network cards) I have it working, and I can use the linux box as a gateway for my network machines.
My problem is that I wish to beable to do the following:
1, Access the server via ssh and ftp from the outside world.
2, Forward port 5900 (for vnc) on the external ip to a machine on the LAN.
I have tried to setup iptables to do it, but whenever I try and ssh I get: ssh: connect to host x.x.x.x port 22: Connection refused
Distribution: At home: Arch, OpenBSD, Solaris. At work: CentOS, Debian, Ubuntu
Posts: 3,558
Rep:
To get SSH working you need to both allow incoming requests with a destination port (dport) of 22 and outgoing requests from your box with source port (sport) of 22. Something like:
iptables -A INPUT -p tcp -d <your IP> --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state RELATED,ESTABLISHED --sport 22 -j ACCEPT
This allows all incoming port 22 requests and related outgoing requests. You might want to filter incoming requests by IP address.
For forwarding VNC, you need to use DNAT, see this page for some details on how to do that.
iptables -A INPUT -p tcp -d $myip --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state RELATED,ESTABLISHED --sport 22 -j ACCEPT
But now I seem to get:
ssh: connect to host $myip port 22: Operation timed out
This is the gateway script I run at startup:
Code:
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F #ignore if you get an error here
/sbin/iptables -X #deletes every non-builtin chain in the table
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -m state --state NEW -i ! eth0 -j ACCEPT
# only if both of the above rules succeed, use
/sbin/iptables -P INPUT DROP
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
# use this line if you have a static IP address from your ISP
# replace your static IP with x.x.x.x
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to $myip
# use this line only if you have dynamic IP address from your ISP
#/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o eth0 -j REJECT
Hi, i've got similar problem: my IP is reachable from internet(web site shows) but name address not!(cannot connect) I have DNS on local network working ok, firewall is configured for allowed traffic for port 80 (i has used this iptables commands on this thread). Needs to be reconfigured DNS system or etc. Thanx and sorry for intermission.
I have discovered that it could be something to do with my Netgear DG834G router, or my ISP which is eclipse.net.uk...
I discovered this by pointing an external IP (on my router) to a windows machine running windrop which listens on port 3333, I could not reach port 3333 from the outside world.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.