Ssh – telneting to ssh port works, but SSH not

networkingroutingssh

I have a two network interfaces machine, one is connected to the router and gets an automatic address via DHCP. The other has a static IP in a different subnet. I can ping both IP addresses, telnet to port 22 and see the "SSH prompt".. just fine. (trying them with switching the cable in my notebook)

Question: but when it comes to connecting to this machine via SSH I can only connect through the NIC that is connected via the router, not directly. It just timeouts when I try to connect directly. Why?

The firewall rules are the default, tried rebooting both sides, I only modified the "UseDNS to no" in the sshd_config on the machine.

Best Answer

I'm almost sure you have a route problem. Probably you either have none or two default routes.

Let's assume you have two networks, 192.168.0.0/24 and 192.168.1.0/24, your router's IP 192.168.0.1 and your machine's addresses 192.168.0.2 and 192.168.1.2. A manual configuration would be something like:

sudo ifconfig eth0 192.168.0.2 netmask 255.255.255.0 up
sudo ifconfig eth1 192.168.1.2 netmask 255.255.255.0 up
sudo route add default gw 192.168.0.1
sudo route add -net 192.168.1.0 netmask 255.255.255.0

Although each scenario would require a slightly different command. [1]

Please make sure there's no other default route. Also, make sure you have ipv4_forward set to 1. [2]

Related Question