Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two CentOS virtual machines on VirtualBox . one of them let's say CentOS-1 holds my Web application code. Second is CentOS2. I have two network connections between these two servers : Bridged & Host-only .

CentOS-1 : for Bridged connection the ip is : 192.168.0.137
for Host-only connection the ip is : 192.168.1.137

CentOS-2 : for Bridged connection the ip is : 192.168.0.101
for Host-only connection the ip is : 192.168.1.101

in my php web page when I try to ssh like this :

 exec('ssh -p 22 root@192.168.0.101 2>&1 ',$output);

it's working, but when I'm trying to ssh to the host-only network ip :

 exec('ssh -p 22 root@192.168.1.101 2>&1 ',$output);

I got this as an output :

ssh: connect to host 192.168.1.101 port 22: No route to host

I tried to re-generate public key for 192.168.0.137 and copy it to 192.168.0.101 but it didn't help. I also tried to give privileges to apache user :

on CentOS-2 :

sudo -u apache ssh root@192.168.1.137 "pwd"
sudo -u apache ssh root@192.168.0.137 "pwd"

on CentOS-1 :

sudo -u apache ssh root@192.168.1.101 "pwd"     
sudo -u apache ssh root@192.168.0.101 "pwd"

neither of the two ways worked. Is there any thing that I has missed? The output of ifconfig -a :

$ ifconfig -a                                                                                                     
eth0      Link encap:Ethernet  HWaddr 08:00:27:0B:56:0E                                                                               
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0                                                            
          inet6 addr: fe80::a00:27ff:fe0b:560e/64 Scope:Link                                                                          
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                                                                          
          RX packets:5652 errors:0 dropped:0 overruns:0 frame:0                                                                       
          TX packets:4886 errors:0 dropped:0 overruns:0 carrier:0                                                                     
          collisions:0 txqueuelen:1000                                                                                                
          RX bytes:833395 (813.8 KiB)  TX bytes:769122 (751.0 KiB)                                                                    

eth1      Link encap:Ethernet  HWaddr 08:00:27:FA:C6:32                                                                               
          BROADCAST MULTICAST  MTU:1500  Metric:1                                                                                     
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0                                                                          
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0                                                                        
          collisions:0 txqueuelen:1000                                                                                                
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)                                                                                      

lo        Link encap:Local Loopback                                                                                                   
          inet addr:127.0.0.1  Mask:255.0.0.0                                                                                         
          inet6 addr: ::1/128 Scope:Host                                                                                              
          UP LOOPBACK RUNNING  MTU:16436  Metric:1                                                                                    
          RX packets:6315 errors:0 dropped:0 overruns:0 frame:0                                                                       
          TX packets:6315 errors:0 dropped:0 overruns:0 carrier:0                                                                     
          collisions:0 txqueuelen:0                                                                                                   
          RX bytes:878894 (858.2 KiB)  TX bytes:878894 (858.2 KiB)       

and output of route :

$ sudo ifconfig eth1 inet 192.168.1.101 broadcast 192.168.1.255 netmask 255.255.255.0 up                          
[sudo] password for safaa:                                                                                                            

    [safaa@AMeS101 ~]$ route                                                                                                           
Kernel IP routing table                                                                                                               
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface                                                         
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1                                                          
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0                                                          
link-local      *               255.255.0.0     U     1002   0        0 eth0                                                          
default         mbox.kds.local  0.0.0.0         UG    0      0        0 eth0       
share|improve this question
    
"No route to host" means that the network is not correctly configured for the SSH client to connection to the SSH server. So permissions, SSH keys and configuration, and Apache configuration have nothing to do with the problem. You should probably rework your question to simplify it to the network configuration and diagnostic steps. Also, please include the output of ifconfig -a and any other commands only *after running commands that change network configutation (such as the command setting the IP address for eth1 on CentOS-2). And include the network config for both VMs. –  depquid Apr 13 '13 at 19:26

1 Answer 1

up vote 0 down vote accepted

here is the answer:

on CentOS1:

sudo ifconfig eth1 192.168.1.191 netmask 255.255.255.0 up
sudo touch /etc/sysconfig/network-scripts/ifcfg-eth1 
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1  

DEVICE="eth1"
IPADDR=192.168.1.191
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

then:

sudo ifup eth1

on CentOS1 who ssh to this server:

sudo -u apache ssh root@192.168.1.191"pwd"

then apache can ssh to 192.168.1.191 and you can do whatever you want :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.